mardi 13 mai 2014

In SQL, how can I handle a relation that is of the form a->b AND b->a?


Vote count:

0




I'm developing a project for my Database course, and the application has the functionality of adding friends. The way I'm approaching it is having a table, defined below: CREATE TABLE Friend( friend_from VARCHAR(10), friend_to VARCHAR(10), PRIMARY KEY(friend_from, friend_to), FOREIGN KEY(friend_from) REFERENCES Users(username) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY(friend_to) REFERENCES Users(username) ON UPDATE CASCADE ON DELETE CASCADE );


Let's say there's a User A who is friends with User B. Should I have them both in the table, i.e. +-------------+-----------+ | friend_from | friend_to | +-------------+-----------+ | A | B | +-------------+-----------+ | B | A | +-------------+-----------+


Thanks in advance for the help!



asked 13 secs ago






Aucun commentaire:

Enregistrer un commentaire