|
临时表: 创建后只在当前连接可见,当关闭时 mysql 会自动删除该表。
先BB下临时表的特点: 当使用PHP 来创建MYSQL 临时表,PHP脚本执行完后,临时表会自动销毁。如果是客户端连接 ,则关闭客户端时候关闭临时表。- 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)
复制代码 当使用show tables 命令显示数据表是们无法看到 临时表,
手动删除临时表- 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)
- mysql> DROP TABLE SalesSummary;
- mysql> SELECT * FROM SalesSummary;
- ERROR 1146: Table 'RUNOOB.SalesSummary' doesn't exist
复制代码
|
|