临时表

临时表只在当前连接可见,当关闭连接时,Mysql会自动删除表并释放所有空间

语法:create temporary table tempEmp

create temporary table temptal(
uid integer(10),
name char(5),
sale varchar(10)
)engine=InnoDB default charset utf8mb4 comment '测试';
select * from temptal;

insert into temptal(uid,name,sale) values(1,'刘姐','100块p');

show tables;//不会显示临时表

也可在当前会话手动删除,drop table temptal;

创建临时表并同时插入另一张表的数据

create temporary table tempTest(

select * from customtable

limit 0,10

)

创建临时表temptal,表结构跟emp一样并插入emp表前三行数据

create temporary table temptal(
select * from emp
limit 0,3
)

原文地址:https://www.cnblogs.com/hebiao/p/14325746.html