Invalid column name on sql server update after column create

后端 未结 4 1449
暗喜
暗喜 2020-12-06 09:34

Does anyone see what\'s wrong with this code for SQL Server?

IF NOT EXISTS(SELECT *
              FROM   sys.columns
              WHERE  Name = \'OPT_LOCK\'         


        
4条回答
  •  感情败类
    2020-12-06 10:00

    Use the Go command and Default 0 to solve this.

    --Add all columns, if they don't exist
    ALTER TABLE REP_DSGN_SEC_GRP_LNK
        ADD OPT_LOCK NUMERIC(10, 0) NOT NULL DEFAULT 0
    ALTER TABLE REP_DSGN_SEC_GRP_LNK
        ALTER COLUMN OPT_LOCK NUMERIC(10, 0) NOT NULL
    GO
    --Consume new columns
    UPDATE REP_DSGN_SEC_GRP_LNK SET OPT_LOCK = 1 WHERE SOMETHING = 'ELSE'
    GO
    

提交回复
热议问题