I need to add a specific column if it does not exist. I have something like the following, but it always returns false:
IF EXISTS(SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTableName'
AND COLUMN_NAME = 'myColumnName')
How can I check if a column exists in a table of the SQL Server database?
COL_LENGTH('AdventureWorks2012.HumanResources.Department ','ModifiedDate')
works fine. – Martin Smith Sep 12 '13 at 16:38EXEC sp_executesql
with formedUPDATE
statement. – cassandrad Apr 16 '15 at 15:02FROM [YourDatabase].INFORMATION_SCHEMA.COLUMNS
– Alex Kwitny Jun 25 '15 at 22:35