SQL Server 2000 has three similar functions: scope_identity, ident_current, and @ identity. Both return values inserted into the identity column.Nbsp; ident_current returns the final id value generated for any session and a specific table in any
Select @ identity usage 11:25:39| Category: JSP Dev|Report|Font SizeSubscription Use select @ identity to obtain the ID automatically generated when the last record is inserted. If you use a stored procedure, the Code is as follows: Set @ [email
[Original address:] The differences between scope_identity, ident_current, and @ identity (comparison)
@ Identity (TRANSACT-SQL) returns the system function of the last inserted Identifier value.
Note: After an insert, select into, or large-capacity
In actual database applications, we often need to get the inserted flag value to write data into the relevant table. But what we usually get is the value we need?Sometimes we use select @ identity to obtain the value we just inserted, such as the
1 INSERT INTO user (Username,password) VALUES ('zyl','123' ); 2 // gets the value of the self-growth ID just inserted 3 Select last_insert_id (); In MySQL, using the ID field of the Auto_increment type as the primary key for the table, and use
Mysql_insert_id () returns the auto_increment ID generated in the previous insert query in the given link_identifier. If link_identifier is not specified, the last opened connection is used.
If no auto_increment value is generated in the previous
many times we want to know when inserting data to MySQL The ID of the channel just inserted the data this is useful for us. Below I say three kinds of common methods and analyze their pros and cons one with the following statement: mysql_query ("
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.
@ @IDENTITY Returns
How to obtain the newly inserted id value in the sqlserver/MySQL database
In the sqlserver Database
In actual database applications, we often need to get the inserted flag value to write data into the relevant table. But what we usually get is the
1. Get the last bar to insert dataLAST_INSERT_ID ();2. Gets the number of update impact rows.Row_count ();mysql> UPDATE T , SET address = ' beijing111 ' , WHERE id = 1 , and NAME = ' Yubowei '; Query OK, 1 row affected (0.30 sec) Rows
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.