sql - Multiple row insert into two tables avoiding loops -
i have set of value have inserted 2 tables.input has 5 row , have insert these 5 rows table first.table has identity column.next have insert these 5 rows table b column identity table a. how can done out using loops? highly helpful.
insert table_a(col2,col3) select col2,col3 #temp_tab set @identityval=@@identity insert table_b(cola,colb,colc) select @identityval,col2,col3,col4 #temp_tab
you cannot insert multiple tables using single statment.
what create insert trigger on table after insert occurs performs new insert identity of value inserted table , insert table b.