Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 comments 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?

like image 787
Pandincus Avatar asked May 13 '11 13:05

Pandincus


People also ask

How do I add comments in SQL Server Management Studio?

The keyboard shortcut to comment text is CTRL + K, CTRL + C.

Does SQL save automatically?

By using the Auto Recovery feature in SQL Server Management Studio it will automatically save any open SQL scripts after a period of time. This feature is useful if SSMS crashed or the application was not shut down cleanly or the machine was shut down unexpectedly.


1 Answers

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

like image 97
SQLMenace Avatar answered Sep 22 '22 14:09

SQLMenace