Solved

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

Posted on 2013-12-19
4
378 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need help with a query 6 54
Sql to find top3 for each record 7 16
IN with @variable 5 16
Delete Trigger in SQL Server2008R2 5 0
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now