I am trying to alter a table to add three new columns but I would like to check if the columns names before adding and if it already exists, just skip else add the column,
ALTER TABLE TESTTABLE
ADD [ABC] [int] ,
[XYZ] [ [int] ,
[PQR] [int]
GO
I have the below script
IF NOT EXISTS(
SELECT *
FROM sys.columns
WHERE Name = N'ABC'
AND Object_ID = Object_ID(N'TESTTABLE'))
BEGIN
ALTER TABLE TESTTABLE
ADD [ABC] int
END
but this has to be done for each column is there a better way to achieve this?