Grab our RSS feeds Follow us on Twitter Join our Facebook Group Connect with us on LinkedIn
myITforum.com, Powered by You.
you are not logged in

Articles

Newslinks

Links

Downloads

Site Services

Community Forums

Discussion Lists

Article Search

Newsletter

Web Blogs

FAQs

Live Support

myITforum TV

Take a Poll

Monthly Drawing

myITforum Network

User Group Directory

Our Partners

About Us

Register

Login

BRONZE PARTNER:

BRONZE PARTNER:



Industry News:




  Home : Articles : SQL Server print | email | | Forums |   print | email | | Blogs |   print | email | | Wiki |   print | email | | FAQs |   print | email | Article Search  
SQL Query To Find Specified Table Column Names


Bookmark and Share

By: Don Hite
Posted On: 11/28/2007

This article was Previously posted on Don Hite's Blog

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'


  myITforum.com ©2010 | Legal | Privacy