The OUTPUT Clause for INSERT and DELETE Statements

  • excellent article.!!!

  • Use the OUTPUT Inserted.* INTO #tmp on an INSERT when you need the IDENTITY / NEW_ID / SEQUENCE values for the new records (e.g. for further processing / creating referencing entries in child tables ...).

    Uuse the OUTPUT Deleted.* INTO ... to move data from one table into another one, either for archiving or because you are refactoring your data structure. Or you can use it for some logging / auditing stuff, but in this case I would prefer triggers.

    PS: you can use OUTPUT on a MERGE statement too, there you can refer to Inserted.*, Deleted.* and a special "variable" $action, that will be set to INSERT, UPDATE or DELETE, depending what happend to this row in the MERGE.

    God is real, unless declared integer.

Viewing 2 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply