Sometimes we store the largest ID in the database, and this ID is automatically added whenever there is a new record.
Create the following table:
Create Table maxidtest ('id' int (10) unsigned not null auto_increment, 'name' varchar (100) not null, primary key ('id ')) engine = InnoDB auto_increment = 23 Default charset = utf8;
The ID field is the automatically added field.
Insert a record:
Insert into maxidteset (name) values ("hello ');
Then use:
Select last_insert_id ();
Obtain the id value automatically added and generated when the inserted record is obtained.
Because last_insert_id () is session-oriented, there is no problem when multiple users operate simultaneously.
In addition, if you useProgramming LanguageTo obtain the maximum ID of the inserted record.CodeAs follows:
Dataset DS = mysqlquery ("select last_insert_id ()"); string id = Ds. Tables [0]. Rows [0] [0]. tostring ();