简体   繁体   English

如何为MySQL中2列的组合创建唯一的

[英]How to create a unique for a combination of 2 columns in mysql

I have a persons table with firstname, lastname, password, email, phone, etc 我有一个人名表,上面有名字,姓氏,密码,电子邮件,电话等

I want to create a unique constraint where many people can have the same firstname or more than one person can have the same email address (in case household uses only one) but no two people can have the same firstname and email address at the same time 我想创建一个独特的约束条件,其中许多人可以具有相同的名字,或者多个人可以具有相同的电子邮件地址(以防家庭仅使用一个人),但是任何两个人都不能同时具有相同的名字和电子邮件地址

Is this possible? 这可能吗?

执行此DDL语句。

ALTER TABLE myTable ADD CONSTRAINT tb_UQ UNIQUE(firstname, email)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM