AUTO_INCREMENT

When using AUTO_INCREMENT, you cannot know what value has been given to a column before a row is inserted. Instead, if you need to know it, you must ask MySQL afterward using the mysql_insert_id function. This need is common: for instance, when you process a purchase, you might insert a new customer into a Customers table and then refer to the newly created CustId when inserting a purchase into the Purchases table.

Using AUTO_INCREMENT is recommended instead of selecting the
highest ID in the id column and incrementing it by one, because
concurrent queries could change the values in that column after the
highest value has been fetched and before the calculated value is
stored.

Adding data to the devices table and reporting the insert ID

Leave a Reply

Your email address will not be published. Required fields are marked *