Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

How to check if the column exists in sql table

IF EXISTS(SELECT 1 FROM sys.columns WHERE Name = N'columnName' AND Object_ID = Object_ID(N'schemaName.tableName'))
BEGIN
	ALTER TABLE MyTable ADD COLUMN MyOtherColumn(DATATYPE)
END
 
PREVIOUS NEXT
Tagged: #How #check #column #exists #sql #table
ADD COMMENT
Topic
Name
3+8 =