Wednesday, 14 August 2013

How can I set foreign key relation in non-unique column

How can I set foreign key relation in non-unique column

Suppose I've got two tables
TABLE A
id name
1 emon
2 sumon
3 mamun
4 bonna
5 ferdousi
TABLE B
id name_id score
1 1 100
2 2 0
3 2 10
4 3 50
5 3 60
I want this DATA
name score
emon 100
sumon 0
sumon 10
mamun 50
mamun 60
I know this is easy query, just like:
SELECT A.name, B.score FROM A
RIGHT JOIN B
ON A.id=B.name_id
My question is how can I set foreign key in this situation? I know in
relational database, without relation may be not good decision. Any good
idea?

No comments:

Post a Comment