CREATETEMPORARYTABLESalesSummary( ->product_nameVARCHAR(50)NOTNULL ->,total_sa"/> CREATETEMPORARYTABLESalesSummary( ->product_nameVARCHAR(50)NOTNULL ->,total_sa">
As the name suggests, a temporary table is a table where we can save temporary data. The most important thing about temporary tables is that they are deleted when the current client session terminates. It can be created with the help of CREATE statement but we have to use keyword "Temporary" while creating it. To illustrate the creation of temporary table, we are using the following example -
mysql> CREATE TEMPORARY TABLE SalesSummary ( -> product_name VARCHAR(50) NOT NULL -> , total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00 -> , avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00 -> , total_units_sold INT UNSIGNED NOT NULL DEFAULT 0 ); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO SalesSummary -> (product_name, total_sales, avg_unit_price, total_units_sold) -> VALUES -> ('cucumber', 100.25, 90, 2); mysql> SELECT * FROM SalesSummary; +--------------+-------------+----------------+------------------+ | product_name | total_sales | avg_unit_price | total_units_sold | +--------------+-------------+----------------+------------------+ | cucumber | 100.25 | 90.00 | 2 | +--------------+-------------+----------------+------------------+ 1 row in set (0.00 sec)
The above query has created the value and inserted it into a temporary table named "SalesSummary" middle.
The above is the detailed content of What are MySQL temporary tables? How do we create them?. For more information, please follow other related articles on the PHP Chinese website!