15.24数据库(24):MySQL临时表+复制表
程序员文章站
2024-03-21 14:06:34
...
创建临时表
--创建临时表
create temporary table person(
id integer primary key auto_increment,
name varchar(20) not null unique,
rmb float default 1.0
);
insert into person(name) values
('张鸡蛋'),('穆铜柱'),('张鸭蛋');
复制表的两种方式
use china;
-- 方式1
-- 获得t_province一模一样结构的表
show create table t_province \G;
-- 拷贝并修改得到的建表语句
CREATE TABLE `tpcopy` (
`ProID` int(11) NOT NULL AUTO_INCREMENT,
`ProName` varchar(50) NOT NULL,
`ProSort` int(11) DEFAULT NULL,
`ProRemark` varchar(50) DEFAULT NULL,
PRIMARY KEY (`ProID`)
) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8;
-- 向副本中插入母表的全部数据
insert into tpcopy
select * from t_province;
-- 向副本中插入母表的部分字段
insert into tpcopy(ProName)
select ProName from t_province;
-- 方式2
-- 创建一个和城市表一模一样的表
create table tccopy like t_city;
insert into tccopy
select * from t_city;