Is there a way to set at the time of creating a table a custom ID with some character as prefix and the rest are numbers which is auto incremented so that the first time a record is inserted the ID will be "UID0000001" and the second time a record is inserted the ID will be "UID0000002" and so on automatically in MySQL.
2
Answers
Assuming the prefix would always be
UID
, then you should just maintain an auto incrementid
column and then build theUIDxxxxx
value when you query or in your presentation layer. If the prefix could vary, then you would need to state the rules if you want a concrete answer.For example:
You could do it in the database via a trigger. What you would need to do is to use an auto_increment-column and get the value of it in the BEFORE-trigger: