Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

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.
0
Easwaran Paramasivam
Asked:
Easwaran Paramasivam
  • 2
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
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
0
 
jogosCommented:
Previous post give you already a warning. That column can be used as a Foreign key, it can be used in a view, an index, a stored procedure, UDF or trigger.

Just filtering with the like-statement gives you possibility of bad matches
- LogTransID will also match
- commented code also will match

So additional I think it would be wise to see which objects are depending on your table (no column-dependencies are not stored).  On this link you get a way to do this in script
http://blog.sqlauthority.com/2010/02/04/sql-server-get-the-list-of-object-dependencies-sp_depends-and-information_schema-routines-and-sys-dm_sql_referencing_entities/.
In management studio you can do that by right clicking on your audit table and selecting dependencies.
0
 
Kevin CrossChief Technology OfficerCommented:
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!
0
 
Easwaran ParamasivamAuthor Commented:
Thanks.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now