Sql 中关于表复制问题

来源:互联网 发布:网络电影会给独立账号 编辑:程序博客网 时间:2024/05/29 02:22

表复制分为好几种情况:

1、table 1 和table2 结构相同情况下 :

insert into table2  select * from table1


2、table1和table2结构不同情况下(字段1,字段2为需要复制的列):

insert into table2(字段1,字段2,..) select 字段1,字段2,.. from table1


3.还没有创建table2,需要将table1表结构和表记录全复制到table2中的情况下(主外键关系不能复制):

select * into table2 from table

create table table2 as select * from table1


3、只想复制table1的结构到table2中时(就是在复制的语句后面加个永不成立的条件):

select * into table1 from table1 where 1<>1

create table table2 as select * from table1 where 1=2

0 0
原创粉丝点击