SQL Server Script to identify a column in a database

In this post I would like to use the below script to identify if a specific column exists in a database. For instance I would like to know which tables have the column productdescription in AdventureWorksDW2008R2 database.

SELECT st.name AS TableName,SCHEMA_NAME(schema_id) AS SchemaName,sc.name AS ColumnName
FROM sys.tables AS st INNER JOIN sys.columns sc ON st.OBJECT_ID = sc.OBJECT_ID
WHERE sc.name LIKE '%productdescription%' ORDER BY SchemaName, TableName

Below is the tablename with the schemaname and the columnname we searched for.


In the above script just replace the productdescription after the Like operator with the column you are searching for and run the script accross the databases to identify the table and schema names.

Hope this helps.

This entry was posted in SQL Server DBA Stuff and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s