I'd like to know if / how it's possible to make a second column auto-increment for each primary key:
CREATE TABLE test (
`id` INTEGER UNSIGNED NOT NULL,
`subId` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`text` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`, `subId`)
)
ENGINE = InnoDB;
This creation, unfortunately, doesn't work, only if I specify ID
as primary key and subId
as index key (but I need them both together and ID
can repeat).
Example data (what I need):
1, 1
1, 2
1, 3
2, 1
2, 2
3, 1
The problem with making ID
primary and subId
index is that subId
will increment independently of ID
.
How to achieve this and is it even possible?