Home >Database >Mysql Tutorial >What's the Difference Between User-Defined, Local, and System Variables in MySQL?
MySQL variable declaration and usage
In MySQL, in order to use variables in the second query, they need to be declared and initialized first.
User-defined variables (starting with @)
<code class="language-sql">SET @start = 1, @finish = 10; SELECT * FROM places WHERE place BETWEEN @start AND @finish;</code>
Local variables (no prefix)
<code class="language-sql">DECLARE start INT unsigned DEFAULT 1; DECLARE finish INT unsigned DEFAULT 10;</code>
Server system variables (starting with @@)
<code class="language-sql">SET GLOBAL sort_buffer_size=1000000;</code>
The above is the detailed content of What's the Difference Between User-Defined, Local, and System Variables in MySQL?. For more information, please follow other related articles on the PHP Chinese website!