Does anyone see what\'s wrong with this code for SQL Server?
IF NOT EXISTS(SELECT *
FROM sys.columns
WHERE Name = \'OPT_LOCK\'
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