AUTO_INCREMENT keys in MySQL

For ages I have been using AUTO_INCREMENT keys in MySQL. All of my projects needed either a unique numeric id, which is perfectly taken care of by AUTO_INCREMENT or non-numeric key which I was generating myself. Today I found myself in a situation where I needed to import some data into a table that has a unique numeric key generated by AUTO_INCREMENT. I was confused for a second. I didn’t know how to combine the provided keys from the data to be imported together with the incremental keys of the table itself. It turned out that everything is much simplier than I thought. If a key value is provided when creating a record, MySQL will use it; otherwise it will generate one using an AUTO_INCREMENT feature.

Now I am trying to understand how could I live up to this age and not use this feature even once…

2 thoughts on “AUTO_INCREMENT keys in MySQL”

Leave a Comment