CREATE TABLE a1
(
id INT NOT NULL AUTO_INCREMENT COMMENT '编号',
txt VARCHAR(20) NOT NULL DEFAULT '' COMMENT '文本',
PRIMARY KEY (id)
);
INSERT INTO a1 (txt)
SELECT "111" UNION ALL
SELECT "222" UNION ALL
SELECT "333" ;
-- 复制表结构
CREATE TABLE b1 LIKE a1; -- 会复制主键
CREATE TABLE b2 SELECT * FROM a1 WHERE 1=2; -- 不会复制主键
-- 复制表数据
CREATE TABLE b3 SELECT * FROM a1; -- 创建一张新表并复制数据
INSERT INTO b1 SELECT * FROM a1; -- 向已存在的表复制数据
INSERT INTO b1 (txt) SELECT txt FROM a1; -- 向已存在的表复制某列数据
-- 显示a1表的create语句
SHOW CREATE TABLE a1;