1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to store something like Facebook Groups in DB?

Discussion in 'Databases' started by tlshaheen, Mar 7, 2010.

  1. #1
    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
     
    tlshaheen, Mar 7, 2010 IP
  2. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #2
    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?
     
    killaklown, Mar 7, 2010 IP
    tlshaheen likes this.
  3. tlshaheen

    tlshaheen Peon

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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!
     
    tlshaheen, Mar 7, 2010 IP