Solved

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

Posted on 2013-12-19
4
382 Views
Last Modified: 2013-12-19
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
Comment
Question by:Easwaran Paramasivam
  • 2
4 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 39728930
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
 
LVL 25

Accepted Solution

by:
jogos earned 500 total points
ID: 39730153
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
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 39730194
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
 
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
ID: 39731048
Thanks.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question