Finding a Field

  • I have a database with over a hundred tables. Is there a way to track down the all the tables that have the 'CustomerID' column?

  • One option is to use the system table "syscolumns"...

    SELECT object_name(id) as TableName,* FROM syscolumns

    where name = 'CustomerID'

  • To follow MS guidelines, use the Information_Schema views:

    SELECT * FROM Information_Schema.Columns WHERE Column_Name = ''

  • SELECT * FROM INFORMATION_SCHEMA.COLUMNS C

    INNER JOIN INFORMATION_SCHEMA.TABLES T

    ON T.table_name = C.table_name

    WHERE table_type = 'base table'

    AND column_name = '**your column**'

    This can be used for any column name without returning system tables. I know customer_id isn't likely to be in a system table, but maybe it will help somebody with a similar issue.

    We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true. -- Robert Wilensky

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply