INSERT INTO A SELECT * FROM B WHERE aid NOT IN(SELECT id FROM A)
insert into A(id,[name]) select id,[name] from B where id not in(select id from A)
insert into a select aid,name from b where not exists(select 1 from a where a.id=b.aid)
declare @a table(id int, name varchar(20)) declare @b table(aid int, name varchar(20)) insert into @a select 1, 'aa' union all select 2, 'bb' union all select 3, 'cc' insert into @b select 1, 'aa' union all select 3, 'cc' union all select 4, 'xx'insert into @A(id, name) select aid, name from @b b where not exists(select 1 from @a a where a.id=b.aid)select * from @a
insert into a select aid,name from b where not exists(select 1 from a where a.id=b.aid)
insert into a select aid,name from b where not exists(select 1 from a where a.id=b.aid)
select aid,name from b where not exists(select 1 from a where a.id=b.aid)
declare @a table(id int, name varchar(20))
declare @b table(aid int, name varchar(20))
insert into @a select 1, 'aa' union all select 2, 'bb' union all select 3, 'cc'
insert into @b select 1, 'aa' union all select 3, 'cc' union all select 4, 'xx'insert into @A(id, name)
select aid, name from @b b where not exists(select 1 from @a a where a.id=b.aid)select * from @a
select aid,name from b where not exists(select 1 from a where a.id=b.aid)
a
select
aid,name
from
b
where
not exists(select 1 from a where a.id=b.aid)