Sunday, January 20, 2008

Find all tables, which includes column name

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%'
kick it on DotNetKicks.com
 

1 comment:

Bart Czernicki said...

Good for SQL Server 7/2000, for 2005 best practice is to use the sys views rather than system tables directly.