dsk88199 2018-01-09 08:52
浏览 19
已采纳

MySql:插入具有相同唯一标识符的多行[关闭]

I have a table for team partners:

id - Primary Key (auto inc)
first_name - text
last_name - text
team_number - number

I insert two records at the same time, and I want them to have a unique (if possible auto incrementing) team number.

At the moment, I do a count of the current table results, add 1 and insert that as a team number.

If I had 20 people entering data at the same time, I believe there's a risk of two teams getting the same team number.

Are my fears based in reality? If so, how do I mitigate that?

  • 写回答

1条回答 默认 最新

  • dsb12300 2018-01-09 09:03
    关注

    I think you do not mean that 'team_number' should be really unique, right?

    So a team is based on two players, right? If so I would suggest to handle the logic in the program itself. Why you didn`t create a queue for that?

    In that case you can insert 100 members at once but the queue should only get two at the same time and insert them before getting the next two members!?

    Or do you need to handle this problem via SQL?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看