Can you use auto-increment in MySql without being the primary key

I use the GUID as the primary key for all my other tables, but I have a requirement that must have an increasing number. I tried to create a field in a table with auto-increment, but MySql complained that it should be a primary key.

My application uses MySql 5, nhibernate as ORM.

Possible solutions that I thought of:

  • change the primary key to the auto-increment field, but still make sure the GUID so that the rest of my application is consistent.

  • Create a composite key with both a GUID and an auto-increment field.

My thoughts are currently leaning towards the idea of โ€‹โ€‹a composite key.

EDIT: The row identifier (primary key) is the current GUID. I would like to add an INT field that is automatically added so that it is human readable. I just did not want to move away from the current standard in the application with the GUID as primary keys.

+3
source share
6 answers

The GUID value must be unique for tables and even databases, so make the primary column index auto_increment and make the UNIQUE index for the GUID

+9
source

I would lean the other way.

? , , GUID , .

+5

GUID , AUTO_INCREMENT .

AUTO_INCREMENT MyISAM. (GUID, INT) AUTO_INCREMENT.

GUID, UUID() INSERT .

0

:

  • GUID , ?

  • , : MySQL, .

, :

  • , GUID . MySQL MySQL, .

  • , (, false), GUID, . , : P

0

, auto_increment .

0

- , , - SEQUENCE, SEQUENCE . . . , , , NHibernate .

0

Source: https://habr.com/ru/post/1704573/


All Articles