# User Defined Variables

__*User defined variable*__

+ You can store the value in a user-defined variable and then reference it in other prepared statements
+ User-defined variables:
  + Prefix it with the **`@`** sign 
  + Use the **`SET`** statement to assign a value to it: **`SET @variable_name = expr`**  
+ Visible only in the current session

------------------------------------------------------------
User variables have the same naming conditions as table and column names. Variable names consist of alphanumeric characters from the current character set and the characters `.`, `_`, and `$`. To use other characters in variable names, include the whole name as a string or identifier within quotation marks. For example: 
```
@'my-var'
@"my-var"
@`my-var`
```

For `SET`, use either `=` or `:=` as the assignment operator. When you assign a value (literal or expression) to a variable, the data type of the value must be integer, decimal, binary, or non-binary string, or `NULL`.

If you assign a string to a user variable, the variable uses the same character set and collation as the string. 

The coercibility of user variables is implicit. (Coercibility defines which value has its collation converted in case of collation conflict between values in a single expression.) This works the same way as table column values when you insert or update strings that have a different collation than the collation defined in the table.
