SQL Server Output Usage notes

Source: Internet
Author: User
Tags getdate

An INSERT statement with output.

@ @identity can only return the identity column that was last produced by the current session. If you insert more than one statement at a time. You need to return the identity columns for these automated productions. Then the OUTPU comes in handy.

int, v nvarchar (200))
into T1 (Datacol)
Output Inserted.keycol, Inserted.datacol
Into @temp
From @temp

--------------------

INSERT INTO Downlog
Output
NEWID (), inserted.id,inserted.id,inserted.id, Inserted.id,getdate () into Matchorderlog
VALUES (' 123444 ', ' Aaaaaa.txt ', GETDATE (), 1,1,1)

SELECT * FROM Matchorderlog

The DELETE statement with the output and the UPDATE statement are similar.

The DELETE statement can manipulate the deleted temporary table. The essence of update is that delete and insert can operate inserted and updated two tables at a time.

Update loanee Set [email protected],updatetime=getdate ()

Output
NEWID (), deleted.id,deleted. Applicationid,deleted. Matchorder, inserted. Matchorder,getdate () into Matchorderlog
where [email protected] and deletestate=0 and loaneetype=0

============================

deleted. Parameter name is the value before the change

inserted. Parameter names are changed or inserted argument values

Use format: INSERT into table name output inserted. parameter name, inserted. Parameter name 2 into record table values (table value, table value 2, table value 3 ...)

Update table Name set parameter name = parameter value, parameter name 2 = parameter value 2 ... output inserted. parameter name, inserted. Argument name 2 into record table where condition ...

SQL Server Output Usage notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.