The above is the original content of the table soloreztest, which is operated by the output clause.
A. Use output into for simple insert statements.
The following example inserts rows into the soloreztest table and usesOUTPUTClause returns the result of the statement@mytable Table variable
Declare @ mytable table
(
Id int identity (1, 1) primary key,
Name varchar (50)
)
Insert into soloreztest output inserted. Name into @ mytable values ('20140901 ')
Select * From soloreztest
Select * From @ mytable
The result is:
The output into clause is the insert @ mytable Table variable to synchronize data in the soloreztest table.
The output clause is only used to display the changed data inserted or deleted prefix.
Inserted Prefix: used to retrieve data in a newly inserted Table or updated data. The data available in the insert and update statements cannot appear in the delete statement.
Ed Prefix: used to retrieve deleted or updated data. Available and delete and update statements cannot appear in insert statements.
B. Use output in the delete statement
The following example shows how to delete the soloreztest row in the table by putting the information of the deleted row back.
Delete soloreztest output deleted. * Where id = 2
Similarly, you can use the output into statement to insert the deleted information to a new table.
C. Use output for update
The following instances update data in the table by using output to return the data before and after modification.
Update soloreztest set name = 'zz 'output inserted. Name, deleted. name where id = 3
Inserted. Name: indicates the updated data in the soloreztest table.
Deleted. Name: indicates the data before the update in the soloreztest table.