SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How do I find where a query is used?


How do I find where a query is used?

Author
Message
rburko
rburko
SSC Journeyman
SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)

Group: General Forum Members
Points: 97 Visits: 365
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 )?
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33322 Visits: 18560
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, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26746 Visits: 17557
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 Modens 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)
rburko
rburko
SSC Journeyman
SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)

Group: General Forum Members
Points: 97 Visits: 365
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search