Saturday, November 14, 2009

Find table from Column Name in an MSSQL Database

From the following query you can find all the tables contains the ‘FirstName’ column.

SELECT
table_name=sysobjects.name,
column_name=syscolumns.name
FROM sysobjects
JOIN syscolumns ON sysobjects.id = syscolumns.id
WHERE sysobjects.xtype=’U’ AND syscolumns.name like ‘FirstName’
ORDER BY sysobjects.name,syscolumns.colid

Regards,
Vijay Modi

No comments:

Post a Comment