문제

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?

도움이 되었습니까?

해결책

Put a go after the external comment

/* This is comment 1 */
go

ALTER VIEW [dbo].[view_name]
...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top