to zjcxcinsert A.dbo.a(e,f,g) select (h,i,j) from B.dbo.b提示:Server: Msg 2627, Level 14, State 1, Line 1 Violation of PRIMARY KEY constraint 'PK_SUPPLY'. Cannot insert duplicate key in object 'SUPPLY'. The statement has been terminated.其中A.dbo.a的PRIMARY KEY 为e,这是怎么回事?
insert into OpenDateSource('SQLoledb','data source=服務器B;user id=用戶名;password=12345').數據庫B.dbo.表B (col1,col2,col3....) select (col1,col2,col3....) from 表A where..... A表與B表的字段數要一樣多。
你要将PRIMARY KEY或IDENTITY限制去掉。
insert A.dbo.a(e,f,g) select (h,i,j) from B.dbo.b b where not exists(select * from A.dbo.a where e=b.h) --忽略主键重复的记录
to zjcxc 对于insert A.dbo.a(e,f,g) select (h,i,j) from B.dbo.b b where not exists(select * from A.dbo.a where e=b.h) --忽略主键重复的记录提示:Server: Msg 446, Level 16, State 9, Line 1 Cannot resolve collation conflict for equal to operation.现在A.dbo.a中只有一条数据,是用insert A.dbo.a(e,f,g) select (h,i,j) from B.dbo.b where h='001' 导过来的
select (h,i,j)
from B.dbo.b提示:Server: Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_SUPPLY'. Cannot insert duplicate key in object 'SUPPLY'.
The statement has been terminated.其中A.dbo.a的PRIMARY KEY 为e,这是怎么回事?
A表與B表的字段數要一樣多。
select (h,i,j)
from B.dbo.b b
where not exists(select * from A.dbo.a where e=b.h) --忽略主键重复的记录
对于insert A.dbo.a(e,f,g)
select (h,i,j)
from B.dbo.b b
where not exists(select * from A.dbo.a where e=b.h) --忽略主键重复的记录提示:Server: Msg 446, Level 16, State 9, Line 1
Cannot resolve collation conflict for equal to operation.现在A.dbo.a中只有一条数据,是用insert A.dbo.a(e,f,g)
select (h,i,j)
from B.dbo.b
where h='001' 导过来的