MySql自动递增字母数字主键? [英] MySql auto-incrementing Alpha-numeric primary key?
本文介绍了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),
...
这篇关于MySql自动递增字母数字主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文