---
title: "How to check if a column exists in a SQL Server table"  
description: "How to check if a column exists in a SQL Server table"  
author: "Revati S Misra"  
published: 2023-09-27  
updated: 2023-09-28  
canonical: https://www.mindstick.com/forum/159948/how-to-check-if-a-column-exists-in-a-sql-server-table  
category: "mssql server"  
tags: ["database", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How to check if a column exists in a SQL Server table

How to [check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) a [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) [exists](https://www.mindstick.com/forum/158947/how-do-you-use-the-exists-operator-to-check-for-the-existence-of-records-in-a-subquery) in a [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [Server table](https://www.mindstick.com/forum/396/how-to-selecte-random-records-from-sql-server-table)

## Replies

### Reply by Aryan Kumar

In [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server), you can [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) if a column exists in a [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) by querying the system catalog views, specifically the **INFORMATION_SCHEMA.COLUMNS** view. Here's a SQL query to check if a column exists in a SQL Server table:

```plaintext
IF EXISTS (
    SELECT 1
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'YourTableName' -- Replace with the actual table name
    AND COLUMN_NAME = 'YourColumnName' -- Replace with the column name you want to check
)
BEGIN
    -- Column exists in the table
    PRINT 'Column exists in the table';
END
ELSE
BEGIN
    -- Column does not exist in the table
    PRINT 'Column does not exist in the table';
END
```

Replace **'YourTableName'** with the name of the table you want to check, and **'YourColumnName'** with the name of the column you want to verify.

Here's how this query works:

1. It uses the **INFORMATION_SCHEMA.COLUMNS** view, which contains information about columns in all tables within the current database.
2. The **IF EXISTS** statement checks if any rows match the specified conditions.
3. In the **SELECT** statement, it filters rows where the **TABLE_NAME** matches the table you're interested in and the **COLUMN_NAME** matches the column you want to check.
4. If the query returns any rows, it means the column exists in the table, and it prints a message indicating that. If there are no matching rows, it prints a message indicating that the column does not exist.

This approach allows you to programmatically determine whether a column exists in a SQL Server table before attempting to perform any operations involving that column, helping you avoid errors and handle cases where the schema of the table might change over time.


---

Original Source: https://www.mindstick.com/forum/159948/how-to-check-if-a-column-exists-in-a-sql-server-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
