Check if a column exists before adding it

Check is a column already exists before you add it.

IF NOT EXISTS(SELECT * FROM SYS.COLUMNS WHERE Name = N'columnName' AND Object_ID = Object_ID(N'tableName'))
BEGIN

ALTER TABLE [tableName]
ADD [columnName] DataType

END
Subscribe

0 comments