Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Since there seems to be no way to strip the procedure definition from comments without parsing cf. this, there seem to be no reliably T-SQL query to answer this question.

Or can I get this information from any system view?

cf. my question about stripping comments

share|improve this question
up vote 11 down vote accepted

No. There is no flag or metadata about "UsesDynamicSQL"

You have to search the definition...

There are 2 ways to execute dynamic SQL

You can search for the first in sys.sql_modules, the 2nd using LIKE

   REPLACE(definition, ' ', '') LIKE '%EXEC(%'
   REPLACE(definition, ' ', '') LIKE '%EXECUTE(%'
   definition LIKE '%sp[_]executesql%'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.