Home > Database > Mysql Tutorial > body text

如何对MySQL数据表进行复制、表结构复制_MySQL

WBOY
Release: 2016-06-01 13:30:48
Original
1268 people have browsed it

bitsCN.com

如何对MySQL数据表进行复制、表结构复制

 

为大家介绍如何对MySQL进行复制、表结构复制,也可以分字段进行复制。也可以将一张表中的数据复制到另一张表当中。

 

1、复制表结构(语法 creata table 旧表 select * from 新表)

create table t1(  id int unsigned auto_increment primary key,  name varchar(32) not null default '',  pass int not null default 0 );
Copy after login

desc 查看表结构

如何对MySQL数据表进行复制、表结构复制_MySQL

创建表 t2 同时复制表 t1 表结构 create table t2 select * from t1;

desc t2 查看表结构

如何对MySQL数据表进行复制、表结构复制_MySQL

注意:两张的表字段结构一样,但是 主键 primary key 和 自增 auto_increment 没有了,所以这种方法不推荐大家使用,那如何才能创建出两张完全一样的表呢,办法肯定有的,如下面语句。

create  table  t2 like t1; 
Copy after login

这就可以创建一张 t2 和 t1 完全一样的表了。

2、指定字段复制表结构

语法: create table 新表 select 字段1,字段2 … from 旧表

3、复制表中数据

假设要把表 t1 中的数据全部复制到表 t2中insert  into  t2 select * from  t1;如果只想复制某个字段 insert  into  t2(字段1,字段2) select 字段1,字段2 from  t1;
Copy after login

 


bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!