locked
How to find column name with query RRS feed

  • Question

  • Hello,

    I have a database with a lot of tables and i need to find in what table do i have specific column. I have to do it with a query because if i do open table by  table it will take forever. can somebody help me to query the system tables in order to get the table name where i have the specific column? Example : I have a table Customer that has column FirstName. How do I find "Customer" table name that is containing column "First Name"?

    Thanks

    Monday, August 11, 2008 6:50 AM

Answers

  •  

    Yes you can:

     

    Three different possibilities:

     

    Code Snippet

    select * from INFORMATION_SCHEMA.COLUMNS where column_name='FirstName'


    OR


    select object_name(object_id) as TableName, Name as columnName from sys.columns where name='FirstName'


    OR


    select object_name(id) as TableName, Name as columnName from syscolumns where name='FirstName'

     

     

    Monday, August 11, 2008 7:39 AM