SQL Server- Output clause

Output Clause:- The SQL SERVER 2005 gives us an Output Clause which gives us the information about each row affected by the Insert, Update , Delete and Merge statement. It is more useful than @@scope_Identity and @@Identity column since these global variables gives us the information about the last inserted identity column value, but the Output clause gives us the last affected identity in case of Inserted, deleted, updated and merge statement. Output clause has the access to the Magic tables (Inserted and deleted) and we can capture the records of affected rows into the temporary tables too for latter use.

Create table Tbl_output (id int identity(1,1), fname nvarchar(100), lname nvarchar(100))

Example of Output clause in case of Insert command

Declare @outputtemp Table  (id int , fname nvarchar(100), lname nvarchar(100))

Insert into tbl_output(fname,lname)
Output inserted.id, inserted.fname, inserted.lname into @outputtemp
values(‘Vivek’, ‘Johari’)

Select * from @outputtemp

Example of Output clause in case of Update command

Update tbl_output set fname=’Vibodh’ 
Output inserted. fname , deleted.fname
where id=1

Example of Output clause in case of Delete command

Delete from tbl_output 
Output deleted.* 
where id=1

Read more about Output Clause

About vivekjohari

Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on different databases like SQL Server, MySQL & Oracle, Azure SQL &  Big Data.
This entry was posted in SQL Output Clause, SQL Server and tagged , . Bookmark the permalink.

28 Responses to SQL Server- Output clause

  1. Pingback: TanaMuzicka - KENCHELLO BOBO

  2. Pingback: สอนเทรด Forex

  3. Pingback: Indian Catering Canton MI

  4. Pingback: chanson française

  5. Pingback: Your Dream Home Improvements

  6. Pingback: Best Tallahassee real estate agent

  7. Pingback: Car Makeover TV Show

  8. Pingback: Mitch Brownlie Queensland

  9. Pingback: 바카라119

  10. Pingback: Human Hair Wigs

  11. Pingback: promotion code

  12. Pingback: Online Casino

  13. Pingback: taipan qq

  14. Pingback: Bhojpuri film Watch Bhojpuri film

  15. Pingback: LigaZ

  16. Pingback: Small business website designs and marketing

  17. Pingback: What Is Paddle Boarding?

  18. Pingback: ทิงเจอร์ขาว

  19. Pingback: sexy baccarat

  20. Pingback: prediksi togel hk

  21. Pingback: poker99

  22. Pingback: Bassett Caterers

  23. Pingback: con heo dat remix

  24. Pingback: link bong88

  25. Pingback: Solesociety gift card

  26. Pingback: AL

  27. Pingback: ทางเข้าlive22

  28. Pingback: cbd

Leave a Reply