简体   繁体   中英

Database design for Content Management System

In designing a content management system, I want a particular table to contain certain data which will be displayed in more than one page (but not all pages).

What is the best way to approach such a situation?

Tables

  • pages
    • pageID - primary key Auto
    • pagename varchar 50
    • pagetitle varchar 50
    • mainimageURL varchar 200
  • themes
    • themeID - primary key auto
    • themname - varchar 50
    • imageURL - varchar 200
    • themelocation - array of pageIDs.

The theme table would contain a list of themes, each of which would be displayed in particular pages from the list above, but not neccessarily all.

Sample tables

pages

pageID - pagename - pagetitle - mainimage
1 - kids - Kids Party - some image
2 - corporate - corporate events - some image
3 - adults - Adult parties - some image

themes

themeID - themename - mainimage - linkimage - themelocation 2 pizza imageURL - imageURL 1,3
3 minions imageURL - imageURK 1,2,3
4 rainbow imageURL - imageURL 1

If each page would contain multiple themes, and each theme might appear in multiple pages, then you're talking about an many to many (or n:m ) relationship.

This is usually solved by introducing a third table (commonly referred to as junction table or cross link table ) that contains the links.

So you would create a table named PageThemes that lists alls the themes of a page. This table contains a page ID and a theme ID. While each page ID can be referenced multiple times, and each theme ID too, the combination of those two fields can be made unique, because each row in the table represents one link between a page and a theme, and it's pointless to link the same theme to the same page twice.

This table replaces the comma separated list of page IDs in themeLocations .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM