May 2019
Intermediate to advanced
484 pages
11h 23m
English
Parameterization is the practice of replacing a literal value in a T-SQL statement with a parameter marker. Building on the example from the Ad hoc plan caching section, the following code block shows an example of a parameterized query executed in the AdventureWorks sample database:
DECLARE @PersonType AS nchar(2) = N'EM';SELECT LastName, FirstName, MiddleNameFROM Person.PersonWHERE PersonType = @PersonType;
In this case, the literal value, EM, is moved from the T-SQL statement itself into a DECLARE statement, and the variable is used in the query instead. This allows the query plan to be reused for different @PersonType values, whereas sending different values directly in the query string would result in a separate cached ...
Read now
Unlock full access