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

后端 未结 8 872
一生所求
一生所求 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:45

    I had the same problem and finally managed to solve it using SET NOEXEC.

    IF not whatever
    BEGIN
        SET NOEXEC ON; 
    END
    
    ALTER TABLE dbo.EMPLOYEE ADD COLUMN EMP_IS_ADMIN BIT NOT NULL
    GO
    UPDATE dbo.EMPLOYEE SET EMP_IS_ADMIN = whatever
    
    SET NOEXEC OFF; 
    
    0 讨论(0)
  • 2020-12-02 18:46

    You can incorporate a GOTO and LABEL statements to skip over code, thus leaving the GO keywords intact.

    0 讨论(0)
提交回复
热议问题