scriptB0y
V2EX  ›  问与答

MySQL 如何针对相同外键设置自增 ID(类似 github 每一个 project 的 issue id 都是从 1 开始的)

  •  
  •   scriptB0y · Feb 11, 2019 · 2341 views
    This topic created in 2693 days ago, the information mentioned may be changed or developed.

    如题。

    不知道 MySQL 有没有类似的实现,或者通用的设计模式? 不会是每一个项目一个 table 吧...

    3 replies    2019-02-11 10:44:23 +08:00
    justfindu
        1
    justfindu  
       Feb 11, 2019   ❤️ 1
    好像是自增涨联合主键. 就是把 project_id , issue_id 联合主键. MyISAM 引擎, 联合主键时以 project_id, issue_id, 然后设置 issue_id 自增涨. 差不多这样
    scriptB0y
        2
    scriptB0y  
    OP
       Feb 11, 2019
    @justfindu 谢谢,看了一下是可以的: https://blog.csdn.net/shujianhenu/article/details/46609545

    我看下自己的需求吧,如果用不到事务就用 MyISAM 引擎。
    scriptB0y
        3
    scriptB0y  
    OP
       Feb 11, 2019
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3119 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 05:49 · PVG 13:49 · LAX 22:49 · JFK 01:49
    ♥ Do have faith in what you're doing.