The variables in SQL Server are first declared and then assigned:
Local variables with an @ identifier, global variables with two @ (common global variables are generally defined);
Declare local variable syntax: DECLARE @ variable name data type; For example: declare @num int;
Assignment: There are two methods (@num is the variable name, value is the values)
Set @num =value; or select @num =value;
If you want to get a field value in a query statement, you can assign a value to a variable with SELECT, as follows:
Select @num = field name from table name where ...
The variables in MySQL do not have to be declared beforehand, use "@ variable name" when using it.
First usage: Set @num = 1; or set @num: = 1; To use variables to save the data, use the @num variable directly
Second usage: select @num: = 1; or select @num: = field name from table name where ...
Note the above two assignment symbols, which can be "=" or ": =" when using set, but must use ": = Assignment" When using Select
MYSQL declaration Variable and assignment