@variable_name datatype [ = initial_value ],
.;
Parameters:
Use DECLARE to declare any variable
DECLARE @quantrimang VARCHAR(50);
This DECLARE statement declares a variable named @quantrimang, with VARCHAR data type and a length of 50 characters.
You then change the value of the @quantrimang variable using the SET statement.
SET @quantrimang = 'Hello world';
Next try the INT data type:
DECLARE @site_value INT;
Use the SET statement to assign values to the @site_value variable
SET @site_value = 10;
So the @site_value variable here is assigned to the integer 10.
How to use the following command:
DECLARE @quantrimang VARCHAR(50),
@site_value INT;
In this example, we have two variables declared: @quantrimang variable with VARCHAR (50) data type and variable @site_value INT data type.
In SQL Server, we can assign the default value to the variable at the time of declaration.
DECLARE @quantrimang VARCHAR(50) = 'Hello world';
So here the @quantrimang variable with VARCHAR data type and the length of 50 characters are assigned by default to the 'Hello world' value.
Similarly, we declare with the INT data type:
DECLARE @site_value INT = 10;
How to use the following command:
DECLARE @quantrimang VARCHAR(50) = 'Hello world';
@site_value INT = 10;
The two variables @quantrimang and @site_value have been declared at the same command and assigned the default initial values.
Previous lesson: LITERAL (Hang) in SQL Server
Next post: SEQUENCE in SQL Server