On Facebook, you can join/become a fan of groups. How do they keep track of things like that? For my use, I'm looking at having users become a fan of different things. Would you store it like this in the database: Table: Fans Columns: User_ID || Fan_Of (ID of group is stored here) || ID (Primary key? can't see ever using this field for any output...) Row: 1 || 3 || 1 Row: 1 || 5 || 2 Row: 1 || 4 || 3 Row: 3 || 9 || 4 Where each time a user becomes a fan of something, they get a a new row in the table. Is there a more efficient way of doing this? Thanks in advance! P.S. In the same topic (I think), would you store comments on a article the same way? Table: Comments Columns: User_ID || Article_ID || Comment || ID (Primary key? can't see ever using this field for any output...) Row: 1 || 3 || "Great article!" || 1 Row: 1 || 5 || "Good job!" ||2 Row: 1 || 4 || "Impressive!" || 3 Row: 3 || 9 || "Good job!" || 4
you wouldnt need the last column if 'Fans', just make User_ID + Fan_Of the primary key. For Comments wouldnt Article_ID be the primary key?
Article_ID couldn't be the PK, no, because there would be more than 1 comment on an article! I forgot about composite keys (Duh!), thank you! For the Comments table, adding a datetime column could make my PK User_ID+Article_ID+Datetime the PK. Thanks!