Jazerix
Jazerix

Reputation: 4801

Multiple primary keys in table

A friend of mine just sent me an image of his new api database design.

When I saw it, I noticed that his user table had three primary ids.

I actually thought this wouldn't be possible.

It got me thinking... Is it okay to do this? As long as each column is unique?

I can't seem to find a reason not to do this, except the id is not primary if there are more than one.

Is this a bad database design? And why?

Upvotes: 1

Views: 349

Answers (1)

ron tornambe
ron tornambe

Reputation: 10780

There should be only one column(s) designated as the PRIMARY KEY per table and most DB's will disallow usage of multiple PRIMARY KEYS. Note that a PRIMARY KEY can span multiple columns. Use UNIQUE for other column(s) that require unique values. UNIQUE keys can also be used in foreign key relationships.

Upvotes: 3

Related Questions