HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How can I know which stored procedure or trigger is using a table on SQL Server 2008 R2?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
storedcantriggerknow2008serversqlprocedureusinghow

Problem

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 design the DB, I'm just taking the maintenance of an application that use this DB, so I don't know the name of these stored procedures or triggers, what I want to do is locate this stored procedure 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.

Solution

Search all code using sys.sql_modules

SELECT OBJECT_NAME(object_id)
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

Code Snippets

SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules sm
WHERE definition LIKE '%Mytable%'

Context

StackExchange Database Administrators Q#7956, answer score: 6

Revisions (0)

No revisions yet.