Search code examples
mysqlsqlauto-increment

Automatically add letters in front of an auto-increment fieild


Is it possible to attach a letter in front of an auto-increment in MySQL. I have several tables in my database, some of which have unique id's created by auto-increment. I want to be able to distinguish between the auto-generated numbers by a letter at the front.

This is not a feature which is absolutely required but it would just help making small tasks easy.


Solution

  • Unfortunately you cannot do that. At least not in sql. An autoincrement field is of integer type, so adding a letter there violates the constraint.

    You can have a look to the link below for some sort of a solution to this problem.

    MySQL auto increment plus alphanumerics in one column

    I hope that this can guide you to the right direction.