What OUTPUT clause doing in this statement

Sudip Bhatt 2,281 Reputation points
2021-02-19T19:21:19.84+00:00

Sample taken from https://stackoverflow.com/a/48932734

INSERT INTO #Jedi
OUTPUT INSERTED.*
SELECT 'Luke' AS [Jedi_names], 'Skywalker' AS [Jedi_surname]

just do not understand what will happen for the above statement.

1) first select will give some data that will be inserted into temp table and then those temp table data will be inserted into OUTPUT ?

is my understanding is correct ?

Developer technologies Transact-SQL
0 comments No comments
{count} votes

Accepted answer
  1. Yitzhak Khabinsky 26,586 Reputation points
    2021-02-19T19:47:33.243+00:00

    That's correct.

    The OUTPUT clause is useful for debugging/testing.
    Also, you can redirect its output into a history table as a log of what was inserted.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2021-02-19T20:13:38.597+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.