+ -
当前位置:首页 → 问答吧 → 请问下现有多个结构相同的sqlserver数据库数据怎么合并?

请问下现有多个结构相同的sqlserver数据库数据怎么合并?

时间:2011-11-16

来源:互联网

请问下现有多个结构相同的sqlserver数据库数据怎么合并?

作者: hello_ww   发布时间: 2011-11-16

结构相同指的是什么,数据表,表结构,表关系???

试试DTS导入导出。

作者: AcHerat   发布时间: 2011-11-16

insert into dbname1..tb1 select * from tbname2..tb1
insert into dbname1..tb1 select * from tbname3..tb1
...
insert into dbname1..tb1 select * from tbnamen..tb1

其他表类似.

作者: dawugui   发布时间: 2011-11-16

结构相同是指数据表结构,关系都相同,DTS导入导出是什么意思

作者: hello_ww   发布时间: 2011-11-16

如果表很多,可以通过系统表找到相关表,然后用程序循环去做.
--表名
select name from sysobjects
where type='U'

作者: dawugui   发布时间: 2011-11-16

用数据库的导入导出向导来做。

作者: fredrickhu   发布时间: 2011-11-16

这样写SQL是不是太慢了,我有几十个数据库,每个库有一百多张表

作者: hello_ww   发布时间: 2011-11-16

数据库的导入导出,右键数据库任务里会出现导入或导出的选项,进去就是那个导入导出向导了。

作者: AcHerat   发布时间: 2011-11-16

select * from A
union all
select * from B

作者: ssp2009   发布时间: 2011-11-16

数据库导入导出会覆盖的,不覆盖就没法导

作者: hello_ww   发布时间: 2011-11-16

引用 6 楼 hello_ww 的回复:
这样写SQL是不是太慢了,我有几十个数据库,每个库有一百多张表
那你不如写程序或存储过程来做.把表用语句找出来,然后使用循环去做.

作者: dawugui   发布时间: 2011-11-16

SQL code
insert into db1.dbo.tb
select * from db2..tb1
union all
select * from db2..tb2
union all
select * from db2..tb3
union all
...

...

union all
select * from db2..tbn
union all
select * from db3..tb1
union all
select * from db3..tb2
union all
select * from db3..tb3
union all
...

...

union all
select * from db3..tbn
union all
...
...
...
...
select * from dbn..tb1
union all
select * from dbn..tb2
union all
select * from dbn..tb3
union all
...

...

union all
select * from dbn..tbn

作者: qianjin036a   发布时间: 2011-11-16

热门下载

更多