SQL server, SQLServerPedia Syndication

Parameterized Queries.

The query optimizer takes in a T-SQL query and parametrizes the query if decided. If the query is NOT simple, parametrization is not used. The SIMPLE PARAMETERIZATION setting tells the query optimizer to only parameterize simple queries. But when the PARAMETERIZATION option is set to FORCED this query is automatically parameterized.

The following SELECT statement can be used look into a clean buffer pool that contains only the cached plan for a T-SQL statement. You can see that the query optimizer has rewritten the T-SQL query as a parameterized T-SQL statement.

SELECT stats.execution_count AS cnt, p.size_in_bytes AS [size], [sql].[text] AS [plan_text] 
FROM sys.dm_exec_cached_plans p OUTER APPLY sys.dm_exec_sql_text (p.plan_handle) sql 
JOIN sys.dm_exec_query_stats stats ON stats.plan_handle = p.plan_handle; GO 

The stored procedure sp_executesql can be used to parametrize sql statements, if they are not automatically

parametrized.

Advertisements
Standard

Thinking about someting? Leave a Reply...

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s