MySQL临时表
MySQL
临时表在我们需要保存一些临时数据时是非常有用的。临时表只在当前连接可见,当关闭连接时,Mysql
会自动删除表并释放所有空间。
创建临时表
关键字是temporary
1 | -- 创建临时表 |
当退出了当前的MySQL
对话,再次使用select
命令来读取临时表中的数据,发现表已经被销毁了。
删除临时表
关键字是drop
1 | drop table user; |
复制表
只复制表结构到新表
1 | create table new_table select * from old_table where 1=2; -- 不会复制时的主键类型和自增方式 |
复制表结构和数据到新表
1 | create table new_table select * from old_table; |
复制数据到新表
1 | insert into new_tabel select * from old_table; -- 两个表结构相同 |