Get all table names for a specific column name
SELECT sysobj.name as Table_Name
FROM sysobjects sysobj
INNER JOIN syscolumns syscol
ON sysobj.id= syscol.id
WHERE syscol.name = 'COLUMN_NAME_FOR_SEARCH'
Get all columns and table names for a 'like column_name' query
SELECT syscol.[name] as Column_Name,
sysobj.name as Table_Name
FROM sysobjects sysobj
INNER JOIN syscolumns syscol
ON sysobj.id=syscol.id
WHERE syscol.name like '%COLUMN_NAME%'
1 comment:
Good for SQL Server 7/2000, for 2005 best practice is to use the sys views rather than system tables directly.
Post a Comment