Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

Auto increment a varchar in MySQL

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to auto increment a varchar value. I'm getting as an exception. I want to do without triggers,procedures and function.
So any suggestions are welcome.
insert into idsdf(name,sid) values("JKL",concat("JKL",convert(id,char)));
The output is like this
id(auto_increment) name sid

i want sid value as JKL1.

Please help me.
Thanks in advance..
Posts: 24950
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's pretty clear from the MySQL documentation that you can only use numeric columns as auto-incremented values. In fact if you poke around a bit you'll find this statement:

MySQL wrote:AUTO_INCREMENT applies only to integer and floating-point types.

So your hopes of no extra coding aren't going to come true.

If it was me I would aim for a solution where you had a proper auto-increment column and then build your "JKL1" value later. However I have no idea what your requirements are because you asked a question about a proposed solution and not a question about your actual problem. If you'd like to explain your requirements you might well get suggestions which solve your problem better than the idea you proposed here, I think.
I've been selected to go to the moon! All thanks to this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!