Quantcast
Channel: CodeFari
Viewing all articles
Browse latest Browse all 265

How to check if column exists in SQL Server table

$
0
0


Following Query may help you to check existing column in SQL server.

If Not Exists (SELECT Column_Name
               FROM sys.columns
               WhereTable_Name = Tbl_Name
               ANDColumn_Name = 'Col_Name')
BEGIN
-- Column doesn't exist
END

Note: It will return NULL if the user doesn't have permissions to view the metadata because sys.columns checks user access too.

Viewing all articles
Browse latest Browse all 265

Trending Articles