Link to home
Start Free TrialLog in
Avatar of Easwaran Paramasivam
Easwaran ParamasivamFlag for India

asked on

How to identify particular table's particular column refer in which SPs and UDFs

In my DB I have a table called tAuditLog which has column TranID. I would like to get list of StoredProcedures/ Functons which refer this column.

How to achive this? Please assist.
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Hi again, EaswaranP!

This one may get tricky because you have other tables with TranID.  

Here is a basic example, using either sys.syscomments or sys.sql_modules:
/* http://technet.microsoft.com/en-us/library/ms186293.aspx */
SELECT OBJECT_NAME(id), [text]
FROM sys.syscomments
WHERE [text] LIKE '%TranID%';

Open in new window

/* http://technet.microsoft.com/en-us/library/ms175081.aspx */
SELECT OBJECT_NAME(object_id), [definition]
FROM sys.sql_modules
WHERE [definition] LIKE '%TranID%';

Open in new window


If you are consistent with use of columns that you have tAuditLog.TranID in procedural usage, you can replace the find text below with the fully qualified name and it should work out.  Otherwise, you can try to search out both the table and column at same time.

SELECT objName = OBJECT_NAME(m.object_id), objType = o.type_desc, m.[definition]
FROM sys.sql_modules m
JOIN sys.objects o ON o.object_id = m.object_id
/* Check for both table and column names. */
WHERE [definition] LIKE '%tAudiLog%' AND [definition] LIKE '%TranID%'
/* 
Filter to stored procedures and functions.
http://technet.microsoft.com/en-us/library/ms190324.aspx
*/
AND [type] IN ('TF','IF','FN','P')
;

Open in new window


I hope that helps!

Respectfully yours,

Kevin
ASKER CERTIFIED SOLUTION
Avatar of jogos
jogos
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Referencing entities is a good approach and Pinal Dave does a good job explaining usually; therefore, without reading in detail, I suspect I agree. *smile* Good addition, @jogos!
Avatar of Easwaran Paramasivam

ASKER

Thanks.