您的位置:首页 > 数据库

SQL——表结构或数据的复制

2013-10-30 16:42 113 查看
一.复制表结构及数据到新表

create table new_tb  select  * from old_tb

二.只复制表结构到新表

create table new_tb  select  * from old_tb where 1=2

或者如下所示:

create table new_tb like old_tb

三、复制旧表的数据到新表(假设两个表结构一样)

insert into db1.t1 select * from db2.t2 where 1=1(完全复制/不同数据库)
insert into db1.t1(col2,col3) select  col5 as col2,col6 as col from db2.t2 where 1=1(不完全复制/不同数据库)
update dbo.tb1 set col1=(select  clo2 from  dbo.tb2 where dbo.tb1.col2=dbo.tb2.col3)(复制某张表的某个字段)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: