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_TableSelect * 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 )?

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 CirqueDeSQLeilI have given a name to my pain...MCM SQL Server, MVPSQL RNNR

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).

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.