Assigns a new value to a previously declared variable. The new value does not need
to be of the same type as the previous value. It is an error to assign a value to an undeclared variable. Use the
DECLAREstatement to declare variables.
SET variable-name = new-value;
- variable-name: identifier
A name beginning with an at sign (
@), dollar sign (
$), or colon (
:). The name must have been previously declared in this script.
- new-value: scalar
The value to assign to the variable. It may be a scalar expression or a parentheses-enclosed
DECLARE @a = 1;
SET @a = 2;