mysql - Auto incrementing part of a composite key -


currently have composite-primary key consisting of (user, id). user john smith , there 30 rows pertain him, hence id auto increments each time new entry made. however, if wanted add new user, jill smith same table, there way in can start @ (jill smith, 1) , have id auto increment without messing previous entries?

no. auto_increment in mysql cannot have multiple "states" keep track of multiple counters. have described behaviour, need implement own application logic (w/o using autoincrement feature) , calculate number part of key before inserting new rows.

update

the above true in general in mysql how auto_increment works depends on storage engine.

the documentation quite specific on particular scenario myisam tables:

if auto_increment column part of multiple indexes, mysql generates sequence values using index begins auto_increment column, if there one. example, if animals table contained indexes primary key (grp, id) , index (id), mysql ignore primary key generating sequence values. result, table contain single sequence, not sequence per grp value.

https://dev.mysql.com/doc/refman/5.6/en/example-auto-increment.html


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -