user1132121
user1132121

Reputation: 11

MySQL KEY/UNIQUE KEY

Google mostly answer the question about PRIMARY KEY/UNIQUE KEY difference. But what about KEY/UNIQUE KEY in MySQL? Does`t KEY in MySQL uniquely identify a tuple?

Upvotes: 1

Views: 1966

Answers (4)

Susinthiran
Susinthiran

Reputation: 306

I know it's an old thread but @onedaywhen is correct here. In database theory, the term 'key' refers to candidate or super key and candidate key is a minimal super key. Primary key is chosen to be one of the candidate keys if several, hence 'key' IS unique. I can refer to my DB book used at university if necessary.

Upvotes: 0

onedaywhen
onedaywhen

Reputation: 57023

In database theory, 'key' is a synonym for a unique constraint. Some database management systems use an index (physical) to implement a unique constraint (logical) and is said to be a 'unique index'.

For the mySQL product, KEY is a synonym for a non-unique index and I think the usage is counter-intuitive.

Upvotes: 0

Eugen Rieck
Eugen Rieck

Reputation: 65274

Not at all - a column with a key can easily have duplicate values, the key helps with accessing them fast. A unique key will not allow to insert a row with an already existing value in that column.

Upvotes: 2

N.B.
N.B.

Reputation: 14071

No, KEY is alias for INDEX. INDEX doesn't have to be unique. If the KEY(INDEX) uniquely identified a tuple (a row) then it's a UNIQUE KEY (or a PRIMARY KEY depending on how you defined that key).

Upvotes: 2

Related Questions