Most handy MS SQL query – ever

Find any field name in a MS SQL db – matching your search string (e.g. ‘perator’, as in ‘Operator’ or ‘operator’):

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 ‘%perator%’

ORDER BY sysobjects.name,syscolumns.colid

Change the ‘syscolumns.name’ to ‘sysobjects.name’ to search on table names.

 

Handy when learning a new system!