Ident_current, @ identity, scope_identity

Source: Internet
Author: User
    • Ident_current returns the last identity value generated for a specific table in any session and any scope.

    • @ Identity returns the last identity value generated for any table in the current session, using SS all scopes.
    • Scope_identity returns the last identity value generated for any table in the current session and the current scope.

Ident_current is not limited by scope and session; it is limited to a specified table. ident_current returns the value generated for a specific table in any session and any scope. For more information, see .

Scope_identity and @ identity return the last identity values that are generated in any table in the current session. however, scope_identity returns values inserted only within the current scope; @ identity is not limited to a specific scope.

For example, there are two tables,T1AndT2, And an insert trigger is defined onT1. When a row is insertedT1, The trigger fires and inserts a row inT2. This scenario extends strates two scopes: The insert onT1, And the insert onT2By the trigger.

Assuming that bothT1AndT2Have identity columns, @ identity and scope_identity will return different values at the end of an insert Statement onT1. @ Identity will return the last identity column value inserted into SS any scope in the current session. This is the value inserted inT2. Scope_identity () will return the identity value inserted inT1. This was the last insert that occurred in the same scope. the scope_identity () function will return the null value if the function is invoked before any insert statements into an identity column occur in the scope.

 
Use adventureworks; goselect ident_current ('Person. Address') As current_identity; go
 
 

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.