Search code examples
mysqlsqlrdbms

Two primary non composite keys in a table


I am working on a project and I realized I am unsure about how to use multiple primary keys. I have a table named "User_Details" that has the details of Customer ID, email address and password. From my understanding, I can use both Customer ID and email address as the primary key. In this case do I use only one as Primary Key or both? If I use both, do they become composite primary keys?

(PS. I have other tables, where the foreign key is the customer ID)


Solution

  • You can only have one primary key, but you could definitely have other unique fields.

    Usually using an integer / id as primary key is preferred over a string key, and an id is presumably auto assigned, where as email could change - which would be a problem for foreign key relations.

    Since you already use customer Id as a foreign key in other tables, I would suggest you continue to do that.