Database Simplified Headline Animator

Database Simplified

Monday, 7 November 2011

Find Tables With Column Name in SQL Server Databases

This post describes how one can find list of all the tables where a column with a particular name exists in a databases. Many people come across this issue and searches for query. So here is the query with example.

I am using following query to find out all the table having name “Status” in master database.



Use master
Go

Select B.name as TableName, A.name As ColumnName,C.name as DataType
from Sys.columns A
Join Sys.objects B On A.object_id=B.object_id
Join Sys.types C On A.system_type_id=C.system_type_id
Where A.name='Status'--ColumnName
Go

Output :

image

So the above query lists all the tables having column with name “status” and their datatype.

No comments:

Post a comment