Mysql – Can you use auto-increment in MySql with out it being the primary Key

auto-incrementMySQLnhibernateprimary-keysql

I am using GUIDs as my primary key for all my other tables, but I have a requirement that needs to have an incrementing number. I tried to create a field in the table with the auto increment but MySql complained that it needed to be the primary key.

My application uses MySql 5, nhibernate as the ORM.

Possible solutions I have thought of are:

  • change the primary key to the auto-increment field but still have the Id as a GUID so the rest of my app is consistent.

  • create a composite key with both the GUID and the auto-increment field.

My thoughts at the moment are leaning towards the composite key idea.

EDIT: The Row ID (Primary Key) is the GUID currently. I would like to add an an INT Field that is Auto Incremented so that it is human readable. I just didn't want to move away from current standard in the app of having GUID's as primary-keys.

Best Answer

A GUID value is intended to be unique across tables and even databases so, make the auto_increment column primary index and make a UNIQUE index for the GUID