如何在mysql中使用字母自动增量 [英] How to do Auto increment with letters in mysql

查看:223
本文介绍了如何在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.


这篇关于如何在mysql中使用字母自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆