您的位置:首页 > 数据库 > MySQL

Mysql 复制一条数据

2016-07-07 16:08 197 查看
从不同的表复制

insert into 表1 select * from 表2 where id =** ;

 

同一张表中复制(无主键)

insert into 表1 select * from 表2 where id =** ;

 

同一张表中复制(有主键)

insert into 表1(字段1,字段2,字段3) select 字段1,字段2,字段3 from 表1 where id= ** ; 

一、复制表里面的一条记录并插入表里面

    ① insert into article(title,keywords,desc,contents) select title,keywords,desc,contents from article where article_id = 100;

二、复制表里的多条数据/记录,并插入到表里面

    ① INSERT INTO `power_node`(title,type,status) SELECT title,type,status FROM power_node WHERE id < 5;

    ② INSERT into jiaban (num,overtime) SELECT num,overtime from jiaban where id IN(1,3,5,6,7,9);

三、在创建表时,就插入另一张表里面的某些数据

    ① create table user AS select * from member where id < 10  

CREATE TABLE  表1 as  select * from  表2; 

​as创建出来的表1(新表)缺少表2(源表)的索引信息,只有表结构相同,没有索引。

CREATE TABLE  表1  like  表2;

like 创建出来的新表包含源表的完整表结构和索引信息 

 as用来创建相同表结构并复制源表数据

  like用来创建完整表结构和全部索引

oracle支持as,也是只有表结构没有索引;oracle不支持like。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: