7 个解决方案
#1
A,B兩表通過什麼關聯的?
insert C(a, b)
select A.a, B.b
from A inner join B
on ...?
insert C(a, b)
select A.a, B.b
from A inner join B
on ...?
#2
insert into c (a,b) select a.a,b.b from a,b
这里的a,b表是cross join查询的
这里的a,b表是cross join查询的
#3
A表与B表没写清楚是否有关联
insert into C(a,b) select a.a,b.b from a inner join b on A表与B表关联的条件
insert into C(a,b) select a.a,b.b from a inner join b on A表与B表关联的条件
#4
用自动生成的ID 做关联 进行查询插入
#5
declare @t table(id int identity(1,1),name varchar(20))
insert into @t
select a from A
declare @d table(id int identity(1,1),names varchar(20))
insert into @d
select b from B
insert into C
select A.name,B.names from @t inner join @b on A.id=B.id
insert into @t
select a from A
declare @d table(id int identity(1,1),names varchar(20))
insert into @d
select b from B
insert into C
select A.name,B.names from @t inner join @b on A.id=B.id
#6
A表B表没有关联
#7
A中有100行
B中有100行
合并完的C也有100行
B中有100行
合并完的C也有100行
#1
A,B兩表通過什麼關聯的?
insert C(a, b)
select A.a, B.b
from A inner join B
on ...?
insert C(a, b)
select A.a, B.b
from A inner join B
on ...?
#2
insert into c (a,b) select a.a,b.b from a,b
这里的a,b表是cross join查询的
这里的a,b表是cross join查询的
#3
A表与B表没写清楚是否有关联
insert into C(a,b) select a.a,b.b from a inner join b on A表与B表关联的条件
insert into C(a,b) select a.a,b.b from a inner join b on A表与B表关联的条件
#4
用自动生成的ID 做关联 进行查询插入
#5
declare @t table(id int identity(1,1),name varchar(20))
insert into @t
select a from A
declare @d table(id int identity(1,1),names varchar(20))
insert into @d
select b from B
insert into C
select A.name,B.names from @t inner join @b on A.id=B.id
insert into @t
select a from A
declare @d table(id int identity(1,1),names varchar(20))
insert into @d
select b from B
insert into C
select A.name,B.names from @t inner join @b on A.id=B.id
#6
A表B表没有关联
#7
A中有100行
B中有100行
合并完的C也有100行
B中有100行
合并完的C也有100行