Just now I saw a friend in the blog Park
// Locate the id value just inserted
Datatable dt = Helper. getdatatable ( " Select top 1 msg_id from tb_message_board order by msg_time DESC " );
poor experience, especially when concurrency occurs. Search by yourself for future use.
after the insert statement is run, execute select @ identity to obtain the automatically generated id if it is SQL server, it is best to use select scope_identity () as id because @ identity global similar ident_current ('table') ident_current returns the id value generated at the end of any session and a specific table in any scope. Ident_current is not restricted by the scope and session, but by the specified table. Ident_current returns the value generated for a specific table in any session and scope. @ identity returns the value of the last identifier generated for any table in all scopes of the current session. scope_identity returns the last generated id value for the current session and any table in the current scope scope_identity and @ identity returned in the current session the last Identifier value generated in any table. However, scope_identity only returns the value inserted into the current scope; @ identity is not limited to a specific scope. |