Subscribe to our YouTube Channel for more Videos

SQL Server 101 – Check if a column exists in a table

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'))
    /* Column exists and you can perform yoour business logic */
Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.