It is very often you find that a column such as the ID column on a table will auto increment. This simply means that the next insert made in the table will have an ID that is one more then the previous one and therefore all ID's will be unique. This is done by Auto_Increment keyword in MySQL.
Auto_Increment is a keyword in SQL that operates on Number data types. Auto_Increment is used to automatically generate sequential numeric values every time that a new record is inserted into a table for a field defined as Auto_Increment.
MySQL removes the complexity of generating unique Primary Key ID by the user programmatically and provides Auto_Increment keyword feature to generate primary keys. Auto_Increment keyword is used with the INT data type.
By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record you enter in the table. To change the AUTO_INCREMENT sequence start value with some another value, you can use the following SQL statement:
But, if you delete one row from the table, the table will still auto-increment as if the row had not been deleted at all. The result is a gap in the sequence numbers. This is normally not that big issue, but you may want to reset the auto-increment field.
If someone Deletes Row in the middle and then again wants to Reset the Auto_Increment Column value to the next successive number or 1.
You cannot reset the counter value to be less than or equal to any value that have already been used.
If you want to view the last Auto_increment ID that was generated by MySQL, you can use the LAST_INSERT_ID function in MySQL. Below is the Syntax for that
Our Website is viewed by more than 400K Technical Enthusiasts every month.
For Sponsored Advertisement OR Guest Posts, Contact us at email@example.com