I am integrating a friends system for my website...
One question I have about the mysql table is how it is to be set up.
Will I have many columns for each friend they add, such as freind 1, 2, 3, 4, 5 and so on and the row will be the user who has added them.
Is there a better way to do this?? With my first thought doing it that way would mean a cap on the amount of friends someone can have...
preguntado el 27 de agosto de 11 a las 15:08
Your suggestion of multiple columns would violate primera forma normal. As well as artificially restricting the number of friends such structures are tedious to work with and inefficient.
You need a junction table for friends with 2 columns (
userid2) that form a composite primary key. Both columns would have a FK relationship with the
In many RDBMSs you would also have a check constraint
userid1 > userid2 so a relationship can only be stored in one form but I believe check constraints are somewhat broken in MySQL.
You will need an additional table with records for each friend a member has. For example:
members (id, name) friends (member1, member2)