Suraj Menon
Suraj Menon

Reputation: 1594

Key values in database

Can the primary keys in database be multi-valued ? For eg if the student has multiple bank accounts numbers can we we use this attribute as key ?

Upvotes: 1

Views: 68

Answers (2)

harunahi
harunahi

Reputation: 722

This is an interesting question since the two bank accounts would both be unique to the user and wouldn't be duplicated by any other row as per the definition given in Cthulhu's answer.

However, since you are effectively defining a one-to-many relationship between the student and the bank account, you are establishing the bank account as a separate entity rather than an attribute of the student entity. Therefore you really need to look for a separate unique identifier for the student to use as the primary key.

At best, in this case, you could use the student's 'primary' bank account as the primary key and have another field for alternative bank account which has nothing to do with the key.

Upvotes: 1

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46728

The very definition of Primary key states that

The primary key has to consist of characteristics that cannot be duplicated by any other row.

So if you have non-unique values, you shouldn't use that as primary-key. However, you can have an extended primary key, spanning multiple columns.

Upvotes: 1

Related Questions