SQL Query to Search a Column Name in all Tables

This query will give you a column name in all the tables,Sps,etc. Just give your column name in the place of employee and see the magic.

SELECT C.NAME[Column Name],O.NAME [Found in Object],
CASE O.XTYPE
 WHEN 'U' THEN 'Table'
 WHEN 'P' THEN 'Stored Procedure'
 WHEN 'FN' THEN 'Scalar Function'
 WHEN 'V' THEN 'View'
 WHEN 'S' THEN 'System Table'
 WHEN 'IT' THEN 'Internal table'
ELSE
'Sysobjects.XTYPE ='''+O.XTYPE +'''' END 'Object Type'       
FROM SYSCOLUMNS C
INNER JOIN SYSOBJECTS O ON C.ID=O.ID
AND C.NAME LIKE '%employee%'v

Ebook Download
View all
Learn
View all