Mysql临时表用法

Mysql 临时表概念

 *  偶尔需要运行很多查询获取一个大量数据的子集
 *  临时表在连接数据库时存在; 断开,自动删除表并释放空间
 *  两个不同连接可以使用相同的临时表名称,二者不会相互冲突
 *  创建的时候,使用关键词 IF NOT EXISTS 可以防止发生错误

创建临时表

create temporary table if not exists  tmp_table
(name VARCHAR(10) NOT NULL,
value INTEGER NOT NULL,
userName varchar(500),
phone varchar(500) );

查询结果导入临时表

select user_id, phone 
select username, deposition
from user, compay
where user.id = compay.id
order by user.city
INTO TEMP user_compay

查询临时表

select * from user_company 

创建并将结果导入临时表

CREATE TEMPORARY TABLE tmp_table  AS 
(SELECT * FROM table_name where xxx )

猜你喜欢

转载自blog.51cto.com/11726705/2467410