Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-19
4
Medium Priority
?
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 60

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 2000 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 60

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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 …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

670 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