SQL script to find where a column is used?

  • 1. I'd like to find out  where in the SQL Server 2000 system catalog I can look to retrieve the information that indicates where a column X is referenced (for example column X exists in table Y, in stored proc Y1, in user defined function Y2, in view Y3 etc...).  In brief it is a cross reference/where defined/where used report that I am looking to produce.  

    2.  I think the declaration/definition information is in the system catalog but the "where used"  info may not be.  How I can write a SQL script to list all stored procs and save that list to a file to do a find/grep for the column name? 

    Thanks!

     

  • Check out the Xfind script at:

    http://www.sqlservercentral.com/scripts/viewscript.asp?scriptid=1124

  • Finding what tables and views contain a column is pretty straightforward using system tables:

    select o.name,o.xtype from syscolumns c join sysobjects o

           on c.id = o.id

    where c.name = 'column x'

    You'll have to use a script to search stored procedures for a string, like Fred suggested.  There are several in the script section here at SQL Server Central.

    Greg

    Greg

  • Many thanks to both Fred and Charles.  Both suggestions work well.

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

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