Reputation: 21465
What's the difference between accessing a variable with @
or without?
Upvotes: 34
Views: 30367
Reputation: 6105
The @
makes it a user defined session variable. Otherwise it would be locally scoped variable (in a stored procedure), you would have to DEFINE
your local before you can SET
it. You could also set a global system variable (with SET GLOBAL
or SET @@global
) if you wanted to. As well as a session system variable with SET SESSION var
or SET @@session var
or SET @@var
.
More details about SET
from the documentation: If no modifier is present, SET
changes the session variable (that's why you DEFINE
your locals in the stored procedure first). If you set several system variables, the most recent GLOBAL
or SESSION
modifier in the statement is used for following variables that have no modifier specified.
More (and some good examples) here:
Upvotes: 26
Reputation: 173642
That notation is used for user-defined variables, as explained here: http://dev.mysql.com/doc/refman/5.0/en/user-variables.html
Upvotes: 5