当行都不存在时,有没有更好的方法将一个表中的行插入到另一个表中?
-- Insert all the rows from the temp table into the perm table
-- if none of the rows in the temp table exist in the perm table
-- Insert none of the rows from the temp table into the perm table
-- if any of the rows in the temp table exist in the perm table
insert perm_table (key_field_a, key_field_b, attrib_c, attrib_d, attrib_e)
select key_field_a, key_field_b, attrib_c, attrib_d, attrib_e from #temp_table
where not exists
(
select *
from #temp_table temp
join perm_table perm
on perm.key_field_a = temp.key_field_a
and perm.key_field_b = temp.key_field_b
)