Friday, March 23, 2012

Finding a column in a database

Hi all,

How do I find all tables containing a column (say a column including
the string 'value')?
Thanks

BrunoSELECT sysCol.Name, sysType.name
FROM syscolumns sysCol
INNER JOIN sysobjects sysObj ON sysCol.id = sysObj.id
INNER JOIN systypes sysType on sysCol.xtype = sysType.xtype
WHERE sysObj.name ='<TABLE NAME>'

best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
------------

*** Sent via Developersdex http://www.developersdex.com ***|||If you mean a column with 'value' in the column name (not in the data),
then there are a couple of ways:

select object_name(id), name
from syscolumns
where name like '%value%'

Or if you want a portable solution, you can use the INFORMATION_SCHEMA
views:

select TABLE_NAME, COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS
where COLUMN_NAME like '%value%'

Books Online has more information about syscolumns and the views.

Simon

No comments:

Post a Comment