Source: Internet
Author: User

The syntax @ @IDENTITY returns the last-inserted identity value.
return type

After an INSERT, SELECT into, or bulk copy statement completes, the @ @IDENTITY contains the last identity value produced by this statement. If this statement does not affect any table that has an identity column, the @ @IDENTITY returns NULL. If more than one row is inserted, multiple identity values are generated, and the @ @IDENTITY returns the last-generated identity value. If this statement fires one or more triggers that perform an insert operation that produces an identity value, calling the @ @IDENTITY immediately after the statement executes returns the last identity value produced by the trigger. If the INSERT or SELECT into statement fails or the bulk copy fails, or the transaction is rolled back, the @ @IDENTITY value is not restored to the previous setting.

The @ @IDENTITY, scope_identity, and ident_current functions are similar in terms of returning the last value inserted into the @ @IDENTITY column of the table.

@ @IDENTITY and Scope_identity will return the last identity value generated in all tables in the current session. However, scope_identity only returns values within the current scope, while the @ @IDENTITY is not limited to a specific scope.

The following example inserts a row into the table with an identity column and displays the identity value used in the new row with the @ @IDENTITY.

VALUES (' accountant ', 12,125)

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.