In MySQL, the main uses of the @ symbol are: 1. Declare and obtain user variables; 2. Obtain the value of system variables; 3. Declaration and transfer of stored procedure parameters; 4. Check query cache hits; 5 . Create a temporary table.
In MySQL, the @
symbol has the following usages:
@
symbols can be used to declare and obtain user variables. The syntax is:
<code>SET @variable_name = value;</code>
For example:
<code>SET @total_sales = (SELECT SUM(sales) FROM orders);</code>
@
symbols can also be used to obtain the values of system variables. The syntax is:
<code>SELECT @@system_variable_name;</code>
For example:
<code>SELECT @@version;</code>
In stored procedures, the @
symbol is used to declare and pass parameters. The syntax is:
<code>CREATE PROCEDURE procedure_name ( IN @param_name1 data_type, IN @param_name2 data_type, ... );</code>
For example:
<code>CREATE PROCEDURE GetCustomerOrders ( IN @customer_id INT );</code>
@
symbol can be used to check whether the query hits the query cache. The syntax is:
<code>SELECT /*!@SQL_CACHE*/ * FROM table_name;</code>
If the query hits the cache, the value of @SQL_CACHE
is 1, otherwise it is 0.
@
symbol can be used to create a temporary table. The syntax is:
<code>CREATE TEMPORARY TABLE table_name ( column_name1 data_type, column_name2 data_type, ... ) ;</code>
For example:
<code>CREATE TEMPORARY TABLE OrderSummary ( order_id INT, product_id INT, quantity INT ) ;</code>
The above is the detailed content of Usage of @ in mysql. For more information, please follow other related articles on the PHP Chinese website!