How can I look up columns

  • Hello, in the old versions of SQL Server you could do a wildcard search on a column name, does 2005 have this anywhere? I need to do a search for a variety of fields and don't have time to go through every table?

  • Use BOL and read up on sys.columns or execute some T-SQL for example

    To return all column names:

    SELECT * FROM sys.columns

    To search for a particular column

    SELECT object_id,name FROM sys.columns WHERE name LIKE '%insert your column name here%'

    object_id is the ID of the object(table/view) to which this column belongs

    or do something like this

    CREATE procedure [dbo].[FindColumnByName]

    @findcolumn varchar(50)

    as

    begin

    set nocount on

    select sysobjects.name as TableFound,syscolumns.name as ColumnFound

    from sysobjects

    inner join syscolumns on sysobjects.id=syscolumns.id

    where sysobjects.xtype=''U''

    and (syscolumns.name like ''%'' + @findcolumn +''%''

    or sysobjects.name like ''%'' + @findcolumn +''%'' )

    order by TableFound,ColumnFound

    end

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

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