Groups | Blog | Home
all groups > sql server (microsoft) > march 2006 >

sql server (microsoft) : Find objects that access a particular column


k0mput3r
3/20/2006 12:26:54 PM
Hi,
Is there a store procedure or a simple way to find all objects (
sps, views... ) that access a particular column of a particular table?
Thanks.

Komp.
Brad Joss
3/20/2006 5:24:17 PM
Well, there is the old brute-force way: rename the column of interest
and see what breaks.
This actually can work pretty well if you think about it. You can
easily write a cursor that loops through syscomments and creates a copy
of every object in your database. Those that fail were the ones trying
to reference the column in question. This will not work for select
*'s, or with dynamic sql, but anywhere in an object where you reference
the named column explicitly, this would likely help. You could narrow
down the scope of this by joining on sysdepends, or just use that as a
crib sheet and do it by hand.

Sorry it's not more elegant. Maybe someone else has a good idea...
Brad Joss
3/20/2006 9:58:28 PM
I felt stupid, because after posting that last message, I realized you
have a very simple solution:

select
o.name, c.text
from syscomments c
INNER JOIN sysobjects o
ON (c.id = o.id)
WHERE c.text like '%<my column>%'
AND c.text like '%<my table>%'

Hope this helps
AddThis Social Bookmark Button