TSQL - How to use GO inside of a BEGIN .. END block?

后端 未结 8 940
一生所求
一生所求 2020-12-02 18:06

I am generating a script for automatically migrating changes from multiple development databases to staging/production. Basically, it takes a bunch of change-scripts, and m

8条回答
  •  无人及你
    2020-12-02 18:39

    You can enclose the statements in BEGIN and END instead of the GO inbetween

    IF COL_LENGTH('Employees','EMP_IS_ADMIN') IS NULL --Column does not exist
    BEGIN
        BEGIN
            ALTER TABLE dbo.Employees ADD EMP_IS_ADMIN BIT
        END
    
        BEGIN
            UPDATE EMPLOYEES SET EMP_IS_ADMIN = 0
        END
    END
    

    (Tested on Northwind database)

    Edit: (Probably tested on SQL2012)

提交回复
热议问题