Search This Blog

Search column name in entire database on SQL Server

This query returns the complete details of a searched column in the entire database


SELECT table_name = sysobjects.name,
column_name = syscolumns.name,
datatype = systypes.name,
length = syscolumns.length
FROM sysobjects 
JOIN syscolumns ON sysobjects.id = syscolumns.id
JOIN systypes ON syscolumns.xtype = systypes.xtype
WHERE sysobjects.xtype='U' and syscolumns.name like '%ColumnName%'
ORDER BY sysobjects.name, syscolumns.colid


Might be simple.. But useful at times..!!