如何在mysql中使用字母自动增量

如何在mysql中使用字母自动增量

问题描述:

有没有办法用mysql中的字母进行自动增量



例如:

如果我的自动ID从00001开始盯着

让我们说:



Is there any way to do Auto increment with letters in mysql

for eg:
If my auto id is staring from 00001
let say:

autoid=0001
if(autoid=9999)
autoid=A0001



聪明的


like wise

if(autoid=A9999)
then
autoid=B0001 



等......

有没有简单的方法可以做到这一点?


and so on....
is there any simple way to do this??

我认为你不能用Mysql或SQL MS Access做到这一点。自动增量字段是整数类型,因此在那里添加字母会违反约束。



可以将varchar列分成两个不同的列,其中一个将具有整数部分和其他将有字母表。一旦你自动递增所有整数行只是连接这两列。但是如果你需要像A,B,C这样的自动字母......那就不可能了。
I think you cannot do that with Mysql or SQL MS Access has this ability. An auto increment field is of integer type, so adding a letter there violates the constraint.

May be you can divide varchar column into two different columns one will have integer part and other will have alphabet. once you auto increment all integer rows just concatenate these two columns. But if you need automatic letters like A, B , C... so on its not possible.