How to add a series of string in incrementing id in any table?

前端 未结 4 689
野趣味
野趣味 2021-01-21 14:46

I have MySQL Table with an Order table in a DB this table has an auto-incremental id. Up-till now we have general numeric Order-ID likewise 1,2,3,4,5... From now onwards I have

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 15:16

    You can't have an auto-increment which is not a numeric field. You will better keep the current auto-incrementing column, and add a new one which you will compute manually according to your rules.

    You'll probably want to use the MAX() function to get the latest order and generate the next value: remember to do it within a transaction.

    You could create a function or a trigger, to do the insert cleanly for you.

提交回复
热议问题