If you need to check if a column exists in a table or not in SQL Server , below is a sample code snippet that demonstrates how to do it.
How to check if a column exists in a table in SQL Server ?
The below query checks if the column EmploymentStatusID exists in the table Employee under the schema “dbo” and returns true if it exists.
IF EXISTS(SELECT 1 FROM sys.columns WHERE Name = N'EmploymentStatusID' AND Object_ID = Object_ID(N'dbo.Employee')) BEGIN /* Column exists and you can perform yoour business logic */ END
Enter your email address to subscribe to this blog and receive notifications of new posts by email.