9、mysql临时表、复制表

一、mysql临时表

mysql临时表在我们保存一些临时数据时非常有用的,临时表只有当前连接可见,当关闭连接时,mysql会自动删除表并释放表空间。

1、创建临时表

create temporary table table_name();

当使用show tables命令显示数据表列表时,将无法看到临时表。

2、删除临时表

默认情况下,断开数据库的连接后,临时表就会自动被销毁,也可以通过drop table命令手动删除临时表。

drop table table_name;

二、mysql复制表

1、复制表实例

步骤一:获取数据表的完整结构

show create table runoob_tb1 \G;

步骤二:修改SQL语句的数据表名,并执行SQL语句

步骤三:复制数据

inert into clone_tb1 select * from runoob_tb1;

2、另一种复制表的方法

create table targettable like sourcetable;

insert into target table select * from sourcetable;

3、区分mysql复制表的两种方式

第一:只复制表结构到新表

create table newtable_name select *from oldtable_name where 1=2;

或者

create table newtable_name like oldtable_name;

第二:复制表结构及数据到新表

create table newtable_name select *from oldtable_name;

posted @ 2019-11-28 15:45  清净心境  阅读(224)  评论(0编辑  收藏  举报