patternModerate
Can I determine if a stored procedure uses dynamic sql without parsing the definition?
Viewed 0 times
storeddefinitioncanwithoutthesqlusesprocedureparsingdetermine
Problem
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
Or can I get this information from any system view?
cf. my question about stripping comments
Solution
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
You have to search the definition...
There are 2 ways to execute dynamic SQL
- sp_executesql
EXEC (..orEXECUTE ('
You can search for the first in sys.sql_modules, the 2nd using LIKE
WHERE
REPLACE(definition, ' ', '') LIKE '%EXEC(%'
OR
REPLACE(definition, ' ', '') LIKE '%EXECUTE(%'
OR
definition LIKE '%sp[_]executesql%'Code Snippets
WHERE
REPLACE(definition, ' ', '') LIKE '%EXEC(%'
OR
REPLACE(definition, ' ', '') LIKE '%EXECUTE(%'
OR
definition LIKE '%sp[_]executesql%'Context
StackExchange Database Administrators Q#1720, answer score: 11
Revisions (0)
No revisions yet.