Mysql has an automatically growing id. Now if you write a piece of data into it, the specific process is whether to write the data first and then give the data an id, or give the id first and then insert it. Write the data into
. Just curious
过去多啦不再A梦2017-05-18 10:53:19
MYSQL has already calculated the auto-increment ID that needs to be filled in next time
As shown in the picture below. The database has 62 rows, and the value has increased to 63.
If the ID is not specified, MYSQL will fill it in by itself. If the filling is less than the automatic increment, an error will be reported! If the filling is greater than the automatic increment, the automatic increment will become the filling number + 1
Get insert ID:
MYSQLI: mysqli_insert_id method
PDO: PDO::lastInsertId method
MYSQL: mysql_insert_id method
The MYSQL method of connecting to the database has been deprecated and may be removed in future versions
The SQL below can achieve what you want, but I’m not sure if it’s a good idea. Also, is it really good to set the data structure like this?
INSERT INTO sta_log_fun(`FCNAME`,`STATUS`) VALUES('WOQU',(SELECT auto_increment FROM information_schema.`TABLES` WHERE TABLE_SCHEMA='test2' AND TABLE_NAME='sta_log_fun'));
The effect is as shown below:
PHP中文网2017-05-18 10:53:19
I haven’t researched it, but I guess it’s the same as when we manually insert data, it’s written together. Get the maximum value of the current table id, add the set auto-increment value, and insert the data together. . . .