How to get next alpha-numeric ID based on existing value from MySQL

前端 未结 6 507
我在风中等你
我在风中等你 2020-12-19 07:28

First, I apologize if this has been asked before - indeed I\'m sure it has, but I can\'t find it/can\'t work out what to search for to find it.

I need to generate un

6条回答
  •  無奈伤痛
    2020-12-19 07:41

    Easiest way to avoid duplicate values for the reference column is to add a unique constraint. So if multiple processes try to set to the same value, MySQL will reject the second attempt and throw an error.

    ALTER TABLE table_name ADD UNIQUE KEY (`company_ref`);
    

    If I were faced with your situation, I would handle the company reference id generation within the application layer, triggers can get messy if not setup correctly.

提交回复
热议问题