I am designing a user registration table for my website, we need to support login by username/email/mobile using the same password.
The user can register by a username, email or mobile, once they get registered they can bind their email or phone.
Here is the table that I am thinking, but it has some problems:
user_id is AUTO_INCREMENT
user_id | user_name | email | mobile | pwd
--------------------------------------------------------
1 test
2 [email protected]
3 123456
The following registration should fail:
4 123456 // illegal, 123456 is present in mobile
5 [email protected] // illegal, [email protected] is present in email
The requirement is just to support login by username/email/mobile, and there is no limitation regarding the username format, so here username or email or mobile must be unique among the three columns.
It seems that it is impossible to add unique constraint cross multiple columns, any better solution?
insert
for additional values rather thanupdate
?