Search for a column in your SQL Server database

If you have a requirement where you need to determine the tables and views where the column exists, here's the query for you:

USE AdventureWorks;
GO
SELECT OBJECT_NAME(obj.object_id) as [Name], type_desc as [Type]
FROM sys.objects obj inner join sys.columns col
ON col.object_id = obj.object_id
WHERE col.NAME = 'ProductID'
ORDER BY [Type]
GO

No comments:

Post a Comment