gpt4 book ai didi

mysql - 防止基于 2 列的数据库表中的重复条目

转载 作者:行者123 更新时间:2023-11-29 05:18:56 24 4
gpt4 key购买 nike

我在 MySQL 数据库中记录了比赛的数据。

我需要为每个玩家设置唯一的条目,所以我这样做了:

alter table xtu_datas_competition add unique index(email);

它完美地工作。

但是有几个比赛,所以我也有一个 colum id_ 比赛,我想为电子邮件和特定的 colum id_ 比赛提供独特的条目

例如:

2 identical email for 2 identical colum id_ competition : duplicate
2 identical email for 2 different colum id_ competition : not duplicate

我如何调整我以前的代码?

最佳答案

您只需定义一个包含两列的唯一约束:

alter table xtu_datas_competition add unique index(id_competition,email);

希望对您有所帮助。

关于mysql - 防止基于 2 列的数据库表中的重复条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28780591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com