114497 114497 - 1 month ago 10
MySQL Question

Can you have a primary key and a unique key in the same table in MySQL?

In what situations will this be beneficial in? If you can.


In same table?

Yes definitely you can have.

In what situation?

That depends, one example would be: say you have a synthetic ID column in your table designated as primary key (AUTO_INCREMENT) but you want FirstName of the customer to be unique always. In that case define a UNIQUE constraint on the FirstName column.