Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

How to trace/profile for references to tables when sp_executesql() is used extensively? Expand / Collapse
Posted Thursday, July 5, 2012 8:21 AM

SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Saturday, July 9, 2016 11:36 AM
Points: 861, Visits: 750
I've been tasked with trolling for references to tables on a particular server/database. We're in the process of moving most of the data to a new machine, but the migration isn't well documented (or executed).

It's my suspicion that a lot of the jobs and processes still running on the old box are in vain.

I'd like to capture all table references in that database over the span of say, 45 days, but PLENTY of code is executed using sp_executesql().

Further, I've found that when stores procs are called, the code shown in SQL Profiler stops well before the entire definition of the sproc, potentially leaving out some references.

Can someone please help me work around these shortfalls with the Profiler? Is there a better approach without incurring too much overhead?

Thanks in advance SSC!
Post #1325456
Posted Sunday, July 8, 2012 4:33 AM



Group: General Forum Members
Last Login: Today @ 12:17 PM
Points: 17,173, Visits: 32,139
Profiler won't show the code from a stored proc if you're capturing execution calls. It will only show the code if you're capturing statement calls, which you don't want to do.

You'll need to combine the work. Capture all the calls using Profiler out to file. Then input that to a table where you can parse out the sql statements to get the ad hoc statements and each of their table references. Then you can query the databases directly to get table references from within the stored procedures (although, remember, some stored procs will directly reference the tables, others will build ad hoc statements internally).

In short, this is a huge undertaking.

"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server Query Performance Tuning
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1326552
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse