I'd like to create a table something like.
CREATE TABLE `testing` (
`prefix` tinyint(3) unsigned NOT NULL,
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`,`prefix`) USING BTREE
);
and with an insert statement like
insert into testing(prefix) values(1),(1),(2),(2);
I'd like to get
prefix | id |
---|---|
1 | 1 |
1 | 2 |
2 | 1 |
2 | 2 |
instead of the
prefix | id |
---|---|
1 | 1 |
1 | 2 |
2 | 3 |
2 | 4 |
which it currently produces.
And not having to rely on lock tables and calculating next increment values for the current prefix in code. Also using multiple tables for each prefix would be a maintenance nightmare.
Any ideas how this may be done?
I read something about the SEQUENCE Storage Engine. Not sure if/how that would work for this use case.