This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Whenever you are searching for SQL query optimization tips or prevent SQL injection tips, you can find few common suggestions like: Please do not use Dynamic SQL in your Stored Procedure. Please try to avoid the use of Temp Tables.
I always tell to database developers, please try to avoid the use of Dynamic SQL and Temp Table in your Stored Procedures.
A Temp Table requires additional CPU/IO which degrades the query performance. A Dynamic SQL is not safe against the SQL Injection and It also compiles data every time which requires more Memory.
Here, I am sharing one of the important scripts which gives you list of SQL Server Stored Procedures, which use the Dynamic SQL and Temp Table.
You can easily get the list of Stored Procedures and can make plans of modifying it.
Prepared this script using sys.dm_exec_describe_first_result_set and sys.procedures where error number 4 = Dynamic SQL and error number 10 = Temporary Table.
1 2 3 4 5 6 7 |
SELECT SP_Name ,error_message ,error_type_desc FROM (SELECT schema_name(schema_id)+'.'+name SP_Name FROM sys.procedures) AS T CROSS APPLY sys.dm_exec_describe_first_result_set (SP_Name, NULL, 0) WHERE error_type IN (4,10) |
Leave a Reply