MySql自动递增字母数字主键?

MySql自动递增字母数字主键?

问题描述:

在MySql中这可能吗?我可以有一个以字母为前缀的自动递增主键,例如R1234,R1235,R1236 ...等等吗?

Is this possible in MySql ?? Can I have an auto-incrementing Primary Key, prefixed with a letter, something like R1234, R1235, R1236... ect ??

您可以做的是将密钥存储为两列.一个char前缀和一个auto-incrementing int,它们都被分组为主键.

What you could do is store the key as two columns. A char prefix and an auto-incrementing int, both of which are grouped for the primary key.

CREATE TABLE myItems (
    id INT NOT NULL AUTO_INCREMENT,
    prefix CHAR(30) NOT NULL,
    PRIMARY KEY (id, prefix),
    ...