Insertion of record in two tables? On the Sql server?

On an Sql server, you can insert one record into two temporary tables at a time.

insert into #TmpTAApproval insert into #TmpFinal select reqid,applicationid from Mytable 

How can we write, is this possible? thanks.

+4
source share
1 answer

You can OUTPUT ... INTO second table.

Execution plan

 CREATE TABLE #tmpTest1 ( FirstCol INT ); CREATE TABLE #tmpTest2 ( FirstCol INT ); INSERT INTO #tmpTest1 OUTPUT inserted.FirstCol INTO #tmpTest2 SELECT 1; SELECT * FROM #tmpTest1; SELECT * FROM #tmpTest2; DROP TABLE #tmpTest1; DROP TABLE #tmpTest2; 
+3
source

Source: https://habr.com/ru/post/1391809/


All Articles