RSS Feed

SQL Server - Check If Column Exists In A Table

SQL Server - Check If Column Exists In A Table


Suppose we have a below table "A" with two columns ID and Name.

Select * from A



Example 1 - check if a column exists

We are checking whether column "ID" exists in table "A".



sys.columns returns a row for each column of an object that has columns, such as views or tables. For more on sys.columns please see MSDN.

Example 2 - check if a column exists

We are checking whether column "ID" exists in table "A".



INFORMATION_SCHEMA.COLUMNS is a view. It lets you access information about all the columns of all tables / views in a database.