May 2019
Intermediate to advanced
484 pages
11h 23m
English
One reason to use parameterized queries is for security. Using a properly formatted parameterized query can protect against SQL injection attacks. A SQL injection attack is where a malicious user can execute database code (in this case, T-SQL) on a server by appending it to a data-entry field in the application. As an example, imagine we have an application that contains a form that asks the user to enter their name into a text box. If the application were to use an ad hoc statement to insert this data into the database, it would generally concatenate a T-SQL string with the user input, as in the following code:
DECLARE @sql nvarchar(MAX);SET @sql = N'INSERT Users (Name) VALUES (''' + <user input> + ''');';EXECUTE (@sql);
A malicious ...
Read now
Unlock full access