Question

In T-SQL, I occasionally have to alter table and view definitions in a SQL Server 2008 R2 database. When I do, there's often many required changes so I automate the creation a T-SQL script to help. In this script, I insert comments that are relevant to the creation of the script. There are also comments within the object definitions themselves, which are relevant to the object they are in.

I have found that comments both inside and outside the object definitions are stored in the object definition, and this is not desired. Consider the following T-SQL snippet:

/* This is comment 1 */

ALTER VIEW [dbo].[view_name]
AS
SELECT
    field_name1,
    field_name2, /* This is comment 2 */
    field_name3
...

I have found that both comment 1 and comment 2 are stored within view_name's object definition. Comment 2 is fine--I want it there. But I don't want comment 1 to be stored with the object's definition. How I can prevent comment 1 from being stored?

Was it helpful?

Solution

Put a go after the external comment

/* This is comment 1 */
go

ALTER VIEW [dbo].[view_name]
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top