Home Forums SQL Server 2005 SQL Server 2005 Strategies How to trace/profile for references to tables when sp_executesql() is used extensively? RE: How to trace/profile for references to tables when sp_executesql() is used extensively?

  • 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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning