Home > SQL Server > Find a Column Name within your SQL Tables

Find a Column Name within your SQL Tables

Below is a piece of T-SQL script which can help you find a column name within your user tables in SQL Server. Tested with SQL Server 2005.

 

SELECT      tab.name  AS  TableName,

            col.name  AS  ColumnName

FROM        dbo.sysobjects  tab

INNER JOIN  dbo.syscolumns  col

ON          tab.id       =  col.id

WHERE       tab.xtype    =  ‘U’       — User Table

AND         col.name  LIKE  ‘%geek%’  — Column Name you’re looking for.

ORDER BY    tab.name

Enjoy!

Greg Olsen
Yellow Duck Guy

Advertisements
Categories: SQL Server
  1. Duncan
    January 7, 2009 at 10:51 am

    Hi Greg,It\’s also worth noting that from SQL Server 2005, Microsoft included information schema views which helped mask the complexity of some of these queries. They also hide the underlying table implementations meaning that the information schema queries are tolerant of SQL Server version changes.In this case, try this instead:select * from information_schema.columnswhere column_name = \’%geek%\’Check out all the other information schema views by expanding the views collection then system views in your database.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: