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
?
The keyboard shortcut to comment text is CTRL + K, CTRL + C.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With