Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the case that in the DB I'm checking, there is an archive table which keeps the user history, and there is a trigger or store procedure that after some time delete rows from this table, in order to avoid the oversize of the same, I didn't desing the DB, I'm just taking the mantainance of an application that use this DB, so I don't know the name of these SP's or triggers, what I want to do is locate this SP or trigger, check the code and modify it to leave this "user history" longer on the table.

Someone told me to check the "sysobjects" table, where I can actually see something with the same name of the table, but this is the only information I have been able to retrieve, any advise?

Thank you.

share|improve this question
up vote 6 down vote accepted

Search all code using sys.sql_modules

FROM sys.sql_modules sm
WHERE definition LIKE '%Mytable%'

Or use Red Gate SQL Search which is completely free

Do not use syscomments or INFORMATION_SCHEMA.RUBBISH

share|improve this answer
Can't the fellow also right-click on the target table and hit "Show Dependencies" (or some text to that effect)? – Nick Chammas Nov 16 '11 at 14:27
@Nick Chammas: nope, this is well known as being unreliable – gbn Nov 16 '11 at 14:29
@gbn, I understand that syscomments is for backwards compatability and may be removed from a future release, but can you elaborate on why not to use INFORMATION_SCHEMA? thx – datagod Nov 16 '11 at 14:32
gbn has fully answered my question, thanks a lot. All the best. – farp332 Nov 16 '11 at 15:04
@datagod: same why syscomments as always a poor choice: the definition column is nvarchar(4000). This means you may miss a table reference if in string position >4000 or spans the boundary between nvarchar(4000) rows (depends how you handle it, could concat I suppose if you really wanted... – gbn Nov 16 '11 at 18:51

Try out ApexSQL Search

ApexSQL Search is a FREE SQL Server Management Studio and Visual Studio add-in that, among other features, has the View Dependencies feature. The View Dependencies feature has the ability to visualize all SQL database objects’ relationships, including those between encrypted and system objects, SQL server 2012 specific objects, and objects stored in databases encrypted with Transparent Data Encryption (TDE)

The View Dependencies feature also allows you to set up and customize the visual dependencies diagram layout, including the relationships that will be presented, the layout and size of the generated diagram, and the drill-down depth of the dependencies

Disclaimer: I work for ApexSQL as a Support Engineer

share|improve this answer
Thanks for disclosing your role at ApexSQL. As long as promoting ApexSQL isn't the majority of your contribution to the site, it's OK to post like this from time to time. – Jack Douglas Oct 19 '13 at 11:11

For future reference as of 2008 there is also a DMV that can be used. sys.dm_sql_referencing_entities. I generally prefer it to using SQL_Modules as it avoids false positives among other things. I discussed it here but basically if you have a piece of code like this:

FROM sys.sql_modules WHERE [definition] LIKE '%ABC%'

You will end up with results for the table ABC, the table ABCLog the view vw_ABC, the stored procedure sp_Update_ABC etc. Also to the best of my knowledge the DMV will handle encrypted SPs as well as unencrypted while the sql_modules method only works with unencrypted SPs.

The DMV version of the same query is this:

SELECT * FROM sys.dm_sql_referencing_entities('dbo.ABC', 'OBJECT')
share|improve this answer

Also you can use the sys.sql_expression_dependencies catalog view. Use this query:

referencing_object_name =, 
referencing_object_type_desc = obj.type_desc, 
referenced_object_name = referenced_entity_name
FROM sys.sql_expression_dependencies sd 
INNER JOIN sys.objects obj 
ON sd.referencing_id = obj.[object_id] 
WHERE referenced_entity_name = 'MyTable'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.