Suggest a table structure

Discussion in 'Databases' started by coldfire7, Mar 18, 2009.

  1. #1
    Hi all,

    i am developing a DB for the website. The scenario is, there are multiple types of subscription forms for the user to register for. So, for each form there are some fields that are common.

    I have tried to put the common fields and the user's personal detail in the single table. BUT, when the forms (subscriptions' types )will get more than I had to add more fields to the same user table. Should i do this, or should I make a new table for each subscription form.

    I am just avoiding the form-specific table in order to have one type of field in more than 1 table.

    any suggestions..?

    help appreciated
     
    coldfire7, Mar 18, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    I suggest keeping common fields into one table and creating separate tables for different subscriptions by keeping the specific relational userid into
     
    crivion, Mar 19, 2009 IP
  3. coldfire7

    coldfire7 Peon

    Messages:
    504
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i also think so, but the problem will comes when common fields become more in number...

    apart from that, i used to create tables using phpmyadmin, and to have a Foreign Key in some table, i goto > "Relational View" and than add "Internal Relations".... does this work instead of explicitly creating a Foreign Key,,,,if I have to explicitly add the FK in a table, than how to do that from phpmyadmin gui?

    thanks all
     
    coldfire7, Mar 19, 2009 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    3 tables...

    Users:
    user_id (Pri, auto...)
    any_other_fields

    Subscriptions:
    subscription_id (Pri, auto...)
    any_other_fields

    UserSubscriptions:
    id (Pri, auto...)
    user_id
    subscription_id

    You can then add as many subscriptions as you want to the UserSubscriptions table. Use Innodb tables and put a foreign key from the UserSubscriptions.user_id to Users.user_id, and from UserSubscriptions.subscription_id to Subscriptions.subscription_id. This will keep accurate relationships between your tables.
     
    jestep, Mar 21, 2009 IP
  5. coldfire7

    coldfire7 Peon

    Messages:
    504
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks for all the replies.....

    one question i will repeat from my above question:
    If i am using a single Database in phpmyadmin than making an 'internal relations', using phpmyadmin user interface, between keys is same as making 'foreign keys' ?
    If not than how to make foreign keys from the phpmyadmin user interface?

    much thanks
     
    coldfire7, Mar 23, 2009 IP