Data Haunting

Easy Solutions Destination

By

Sql server check if column exists in table

In Sql server if we want to be sure that specific column exists in given database table or not than you can check either manually or using query for large number of columns of table. In this tutorial we will different different query see how to check if column exist in database table.

Suppose we create Database table named “EmployeeSalary” with three column “Id, Name, Salary” as below.

Query for checking column exists in Database Table using if exists

Using “If Exists” query we can check if column exists or not as given below general query.

If we apply above query with our created table “EmployeeSalary” than if we replace “tableName” name with “EmployeeSalary” and “columnName” with “Name” than we have output like “Column Exists in given table” as given below.

Query for checking column exists in Database Table using if COL_LENGTH

COL_LENGTH can also be used to check whether column exists or not using following query.

In above query you can replace “table_name” and “column_name” with your table name and column name is given below.

What is your opinion ?

Here we have seen two different methods whether column exist in sql server. If you have any query and question, you can comment or you can mail me.

Leave a Reply