Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How do I find where a query is used? Expand / Collapse
Author
Message
Posted Friday, August 16, 2013 7:11 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 12:12 PM
Points: 41, Visits: 364
I have to add a column to a table. No big deal, right? Except I've got to find where there are production queries that might crash when this column is added. Queries such as

Insert Into Some_Table
Select * from Changing_Table

What is the best way to find the source of a particular query? Would it be to search query plans using DMVs (I tried that but didn't find a DMV that gave me what I need)? Or would it be to set up a trace for, say, 24 hours looking at StatementCompleted? How could I find the queries I'm looking for in the trace results (I've been trying to look for a string in the textdata column )?
Post #1485186
Posted Friday, August 16, 2013 7:22 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:07 PM
Points: 21,657, Visits: 15,325
Before deciding on how to retrieve the queries, we would need to determine how queries are written against your database.

Does your application build dynamic strings which are then executed as queries against your database (adhoc queries from the app)?

Does your application strictly call stored procedures from the database?

Or is there a mix of adhoc and procs?

If the application is building dynamic adhoc queries, you need to go chat with your developers to find all of the potential places a query could hit your database and fail due to the new changes.

In the case of stored procedures and triggers - you can query the definitions of those to find anything in the database that may need to be changed due to your pending change. There are several scripts on SSC for doing that type of search to make it easier.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1485196
Posted Friday, August 16, 2013 7:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:41 PM
Points: 13,315, Visits: 12,182
As a follow up to Jason's excellent advice, when you chat with those developers you need to slap them around if they are using queries like that in production. What you are experiencing is the reason that select * should not be allowed in production code (unless it is used as an exists or count).

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1485198
Posted Friday, August 16, 2013 7:32 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 12:12 PM
Points: 41, Visits: 364
You said it, Sean. I'm going to get out my whoopbutt stick when I find out who coded something like "Select * into..."

Jason, it's a mix of adhoc and procs. I'm doing string searches on code libraries to find .Net programs that might use queries that cause problems. You're right about the sprocs. I used a SQL Search SSMS add-on to review those.
Post #1485204
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse