SQL Server- Output clause

SQL Output Clause SQL Server
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

28 thoughts on “SQL Server- Output clause

  1. Pingback: chanson française
  2. Pingback: 바카라119
  3. Pingback: Human Hair Wigs
  4. Pingback: promotion code
  5. Pingback: Online Casino
  6. Pingback: taipan qq
  7. Pingback: LigaZ
  8. Pingback: sexy baccarat
  9. Pingback: prediksi togel hk
  10. Pingback: poker99
  11. Pingback: Bassett Caterers
  12. Pingback: con heo dat remix
  13. Pingback: link bong88
  14. Pingback: AL
  15. Pingback: cbd

Leave a Reply