insert into dbname1..tb1 select * from tbname2..tb1 insert into dbname1..tb1 select * from tbname3..tb1 ... insert into dbname1..tb1 select * from tbnamen..tb1其他表类似.
结构相同是指数据表结构,关系都相同,DTS导入导出是什么意思
如果表很多,可以通过系统表找到相关表,然后用程序循环去做. --表名 select name from sysobjects where type='U'
这样写SQL是不是太慢了,我有几十个数据库,每个库有一百多张表
select * from A union all select * from B
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
insert into dbname1..tb1 select * from tbname3..tb1
...
insert into dbname1..tb1 select * from tbnamen..tb1其他表类似.
--表名
select name from sysobjects
where type='U'
union all
select * from B
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