Differences between and mysql variable assignment and MySqlDeclare bitsCN.com
Both SQL server and mysql are our frequently used database systems. next we will introduce the differences between the values of SQL server and mysql variables, and hope to enlighten you.
Variables in SQL server must be affirmed first and then assigned values:
The local variables are identified with one @ and the global variables with two @ (common global variables are usually defined );
Declare the local variable syntax: declare @ variable name data type; for example, declare @ num int;
Value assignment: There are two methods (@ num is the variable name and value is the value)
Set @ num = value; or select @ num = value;
If you want to obtain a field value in the query statement, you can use select to assign values to the variable, as shown below:
Select @ num = field name from table name where ......
You do not need to declare the value assignment of mysql variables beforehand. you can simply use "@ variable name" when using it.
First usage: set @ num = 1; or set @ num: = 1; // use the variable to save the data. use the @ num variable directly.
Second usage: select @ num: = 1; or select @ num: = field name from table name where ...... (Zhang Ying: It seems that mysql cannot use the select @ p1: = c1, @ p2: = c2 from tb method to assign values)
Note that the above two values can be set with "=" or ": =", but you must use ": =" bitsCN.com "when using select.