How to check if a column exists in a table in SQL Server ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

If you want to find out if a column exists in a SQL Server table , you can use the sys.columns table and specify the name of the column and table as parameter.

How to check if a column exists in a table in SQL Server ?

For example , you want to find out if the GroupName column exists in the table “HumanResources.Department” table , your query will look this

Use AdventureWorks2014
GO
SELECT *
FROM sys.columns 
WHERE Name      = N'GroupName'
AND Object_ID = Object_ID(N'HumanResources.Department') 

The result would be details of the column.

How to check if a column exists in a table in SQL Server ?
%d bloggers like this: