Monday, August 4, 2008

Search column name in SQL DB

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..!!

No comments: