Rarely are used to refer to variables when it comes to a declarative language like SQL, but these can be really useful in some cases, such as simple operations for the numbering of the records.
In a well-designed database, usually makes extensive use of auto-increment unique identifiers for the records but the records themselves often face the cancellation, which makes the IDs are not sequential, in this case may be useful global variables. Imagine having to execute a statement like this:
* SELECT id, name, surname FROM agenda;
Most likely IDs are sequential not shown, then initialize a global variable (by default it has value NULL) :
* set @ N = 0;
At this point simply increments the variable for each extraction in order to obtain the records for consecutively numbered from “1″ to “n”:
* SELECT N @ : = @ N +1 AS contarecord, the name FROM agenda;
A global variable there for the duration of a connection, and only until it is active.