Table Choise Suggestion

Discussion in 'Databases' started by krdzal, Sep 3, 2008.

  1. #1
    I have a table where i want to store data for Favorites games. It will store
    iser_id and game_id. So when user login to i have query for displaying the game_ids for the user who is logged in (user_id)
    Which is better?
    To store for every game new row, (1 user has 10 games that means 10 rows)
    or
    ne row for every user and fiels for the games
    example
    ID_USER GAME_ID
    1 10,50,1,1024

    Suggestions?
     
    krdzal, Sep 3, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    The first idea is a much better and scalable database structure. Generally you would want to have a user table, and then a second table with an individual entry for each game that each user has.

    Basically:

    Users_table:
    user_id
    other_user_info

    Games_table:
    id (auto incrementing)
    user_id
    game_id

    Also if you want to keep your data accurate, and free from dead entries, put a foreign key on the user_id in the games table.
     
    jestep, Sep 3, 2008 IP