- 爱易网页
-
MySQL教程
- Mysql 复构图
日期:2014-05-16 浏览次数:20932 次
Mysql 复制表
Mysql 复制表
> create table mark (id int auto_increment primary key,name char(10),math int,phy int);
> insert into mark values (null,"John",60,70),(null,"Sarah",90,88),(null,"Mike",70,80);
> select * from mark;
+----+-------+------+------+
| id | name | math | phy |
+----+-------+------+------+
| 1 | John | 60 | 70 |
| 2 | Sarah | 90 | 88 |
| 3 | Mike | 70 | 80 |
+----+-------+------+------+
创建副本(复制整个表,但不能复制键)
> create table grade select * from mark;
> select * from grade;
+----+-------+------+------+
| id | name | math | phy |
+----+-------+------+------+
| 1 | John | 60 | 70 |
| 2 | Sarah | 90 | 88 |
| 3 | Mike | 70 | 80 |
+----+-------+------+------+
复制表的部分字段(不能复制键)
> create table student select name from mark;
> select * from student;
+-------+
| name |
+-------+
| John |
| Sarah |
| Mike |
> create table id select id from mark;
> select * from id;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
+----+
mysql> desc id; // 不能复制键
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | NO | | 0 | |
+-------+---------+------+-----+---------+-------+
创建已存在表的空副本(不能复制键)
> create table empty select * from mark where 0=1;
手动创建键
> alter table empty add primary key (id);
> alter table grade add primary key (name);
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。