将第二个数据库的数据插入到第一个数据库,然后用select distinct * from table,然后将这些导入一个新的数据库,将该数据库附加即可
奥,行了,两个数据库都附加上了。 接下来,我该怎么办啊?一个数据库名是CS,另一个是CS1
说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用) insert into b(a, b, c) select d,e,f from b in ‘具体数据库’ where 条件 例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..
/* Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86) Jul 9 2008 14:43:34 Copyright (c) 1988-2008 Microsoft Corporation Enterprise Evaluation Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3) 愿和大家共同进步 如有雷同、实属巧合 ●●●●●2009-09-03 14:10:36.077●●●●● ★★★★★soft_wsx★★★★★ */ if OBJECT_ID('t1') is not null drop table t1 create table t1(id int identity(100,1),name nvarchar(100)) go insert into t1(name) select 'name1' union all select 'name2' union all select 'name3' union all select 'name4' union all select 'name5' union all select 'name6' union all select 'name7' union all select 'name8' union all select 'name9' union all select 'name10' union all select 'name11' goif OBJECT_ID('t2') is not null drop table t2 create table t2(id int identity(100,1),name nvarchar(100)) go insert into t2(name) select 'name1' union all select 'name2' union all select 'name3' union all select 'name4' union all select 'name5' union all select 'name6' union all select 'name7' union all select 'name8' go select a.* from t1 a(nolock) where not exists(select 1 from t2 b(nolock) where name=a.name)/* id name 108 name9 109 name10 110 name11 *//* 有两个表: T1(ID int ,name varchar(100)) T2(ID int ,name varchar(100))。 要查询出T1种name 不在T2中的数据。 我的习惯写法是 : select * from T1 where name not in (select name from T2); 由于这两个表都是几千万的纪录,不知道怎么写效率最高? */根据这种方法
insert时会出现主键冲突吧,怎么解决啊?
use CS1 insert into CS.table select a.* from table a inner join CS.table b on a.id<>b.id
接下来,我该怎么办啊?一个数据库名是CS,另一个是CS1
说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)
insert into b(a, b, c) select d,e,f from b in ‘具体数据库’ where 条件
例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86) Jul 9 2008 14:43:34 Copyright (c)
1988-2008 Microsoft Corporation Enterprise Evaluation Edition on Windows NT 5.1 <X86>
(Build 2600: Service Pack 3)
愿和大家共同进步
如有雷同、实属巧合
●●●●●2009-09-03 14:10:36.077●●●●●
★★★★★soft_wsx★★★★★
*/
if OBJECT_ID('t1') is not null drop table t1
create table t1(id int identity(100,1),name nvarchar(100))
go
insert into t1(name)
select 'name1'
union all select 'name2'
union all select 'name3'
union all select 'name4'
union all select 'name5'
union all select 'name6'
union all select 'name7'
union all select 'name8'
union all select 'name9'
union all select 'name10'
union all select 'name11'
goif OBJECT_ID('t2') is not null drop table t2
create table t2(id int identity(100,1),name nvarchar(100))
go
insert into t2(name)
select 'name1'
union all select 'name2'
union all select 'name3'
union all select 'name4'
union all select 'name5'
union all select 'name6'
union all select 'name7'
union all select 'name8'
go
select a.* from t1 a(nolock) where not exists(select 1 from t2 b(nolock) where name=a.name)/*
id name
108 name9
109 name10
110 name11
*//*
有两个表:
T1(ID int ,name varchar(100))
T2(ID int ,name varchar(100))。
要查询出T1种name 不在T2中的数据。
我的习惯写法是 :
select * from T1 where name not in (select name from T2); 由于这两个表都是几千万的纪录,不知道怎么写效率最高?
*/根据这种方法
insert into CS.table select a.* from table a inner join CS.table b on a.id<>b.id