码迷,mamicode.com
首页 > 数据库 > 详细

Mysql临时表用法

时间:2020-01-17 21:07:27      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:order by   where   存在   temporary   获取   临时表   需要   数据库   phone   

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 )

Mysql临时表用法

标签:order by   where   存在   temporary   获取   临时表   需要   数据库   phone   

原文地址:https://blog.51cto.com/11726705/2467410

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!