SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist perpetual_dream's Avatar
    Join Date
    Nov 2005
    Location
    Jerusalem
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Database Design - Categories Design Best Practice

    Hi,

    I have a few tables: videos/photos/stories/pages and each of which contains a field which is category_id

    I'm thinking and since each of them has a category_id to design a single table categories

    Categories
    ex:
    id || title || type
    1 album1 1 [photos]
    2 fashion 2 [stories]
    3 about_pages 3 [pages]
    4 album2 1[photos]

    Do you consider this database design a correct design with the type field? Or should each table has its own category table (exages_categories, videos_categories, etc....)

    Thanks.
    Tanzeelnet - Best arabic downloadsite
    Linux Hosting |Free Downloads |

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Why do you have different tables for videos/photos/stories/pages?

    Looking at your categories I wonder... 'fashion' is a category, but 'album1' and 'album2' seem album names to me, not categories?

  3. #3
    SitePoint Evangelist perpetual_dream's Avatar
    Join Date
    Nov 2005
    Location
    Jerusalem
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought since the albums have a similar structure to categories ....

    category_id > album_id
    category_title > album_title

    What do you think ?

    so what you suggest is : designing a table for each category (ex : stories_categories, pages_categories, photos_categories , videos_categories ..... ) instead of having them in a single "categories" table?

    Thanks.

    Regards,

    Khaled
    Tanzeelnet - Best arabic downloadsite
    Linux Hosting |Free Downloads |

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,263
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    If items can be groups together, then using a separate table for that grouping is perfectly valid - that's what normalization is.

    What you call the table doesn't really matter. As long as it makes sense to you if you have to revisit it six months down the line.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  5. #5
    SitePoint Evangelist perpetual_dream's Avatar
    Join Date
    Nov 2005
    Location
    Jerusalem
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dave but in this case .... the same database field is got referenced in multiple tables as a foreign key.... Is that valid as well?
    Tanzeelnet - Best arabic downloadsite
    Linux Hosting |Free Downloads |

  6. #6
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,263
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by perpetual_dream View Post
    Dave but in this case .... the same database field is got referenced in multiple tables as a foreign key.... Is that valid as well?
    Yup. That's fine. There doesn't have to be a 1:1 relationship between tables. You can have as many tables reference one specific table as you want.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •