SQL returns the ID of the data just inserted

Source: Internet
Author: User

The processing method adds an identity ID int identity to a field, three ways to create the identity and a comparison: in SQL Server 2000, there are three similar features: they are: scope_identity, Ident_ Both the current and @ @IDENTITY return values that are inserted into the IDENTITY column. Ident_current returns the identity value that was last generated for any session and for a particular table in any scope. Ident_current is not subject to scope and session restrictions, but is limited to the specified table. Ident_current returns the value generated for a specific table in any session and scope. @ @IDENTITY Returns the identity value that was last generated for any table in all scopes of the current session. Scope_identity returns the last identity value generated for the current session and any tables in the current scope, scope_identity and @ @IDENTITY return the last identified values generated within any table in the current session. However, scope_identity only returns the value inserted into the current scope, and the @ @IDENTITY is not restricted to a specific scope. AJQC Experiment: (40 local thread, 40+40 remote thread Concurrent test, insert 1200W Line), the conclusion is: 1. In a typical cascade application. Cannot use @ @IDENTITY, in the cii850,256m SD machine on the 1W more rows will be concurrently rushed More than 6,000 rows on p42.8c,512m DDR. 2.scope_identity () is absolutely reliable, can be used in stored procedures, even the trigger is not built, no concurrency conflict Select ident_current (' TableName ')--Returns the last marked value generated in the specified table select IDENT_INCR (' TableName ')--Returns the increment value of the marked field for the specified table select Ident_seed (' TableName ')-- Returns the indicated field seed value of the specified table returns the AutoNumber of the last inserted record select Ident_current (' TableName ') returns the next AutoNumber: Select Ident_current (' TableName ') + (select IDENT_INCR (' TableName ')) SELECT @ @IDENTITY--Returns the last value generated in all tables in the current session

SQL returns the ID of the data you just inserted

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.