开发者

How does Management Studio know to save my T-SQL comments?

I'm confused about the way that SQL Server Management Studio saves the comments of views, stored procedures, etc.

Let's say I'm altering a view and I put some comments in before the ALTER statement:

USE [SomeDatabase]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- Let's add some comments about this view!
ALTER VIEW [dbo].[MyView]
AS
SELECT Stuff
FROM   TableOfStuff
-- To get the other stuff, we have to do an inner join
INNER JOIN OtherStuff
ON     TableOfStuff.OtherKey = OtherStuff.StuffKey

GO

When I run the above code in Management Studio, my view will be altered AND the comments will be saved. If I later do a Script View As --> ALTER TO --> New Query Window, the c开发者_运维百科omments will reappear.

So how does Management Studio know that those comments 'belong with' the view? Does it have something to do with SET QUOTED_IDENTIFIER ON?


What ever is between the GO before ALTER VIEW and the GO after ALTER View will be saved

Go is a batch terminator, so everything between those 2 GO statements is a batch, and that is what is sent


It's not management studio but sql server it self

Whatever you create in your server (index, SP, whatever), sql server will save the text you used to create the object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜