SQL Query To Find Specified Table Column Names

 

This script will allow you look for any specified column name from all of the user tables from within the current database object. This can be of particular interest to those wanting for example to find which SQL table holds the LastHWScan column.

 

SQL Query:

 

Set NoCount On

Declare @ColVar VarChar(25)

Set @ColVar = '%last%' -- String To Find

 

Select

SysObjects.Name 'Table Names:',

SysColumns.Name 'Column Names:'

 

From SysObjects, SysColumns, SysTypes

 

Where SysObjects.ID = SysColumns.ID

And SysColumns.xType = SysTypes.xType

And SysColumns.Name like @ColVar

 

Order by SysObjects.Name Asc

Set NoCount Off

 

Usage Examples:

 

Pattern Match

Set @ColVar = '%Last%'

Set @ColVar = '%last%time%'

 

Exact Match

Set @ColumnNames = 'Last'

 

 

Published Sunday, November 25, 2007 6:57 AM by dhite
Filed under:

Comments

No Comments