内容管理系统的数据库设计。

时间:2022-10-03 16:27:11

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
    • pageID -主键自动。
    • pagename varchar 50
    • pagename varchar 50
    • pagetitle varchar 50
    • pagetitle varchar 50
    • mainimageURL varchar 200
    • mainimageURL varchar 200
  • 页pageID -主键Auto pagename varchar 50 pagetitle varchar 50 mainimageURL varchar 200。
  • themes
    • themeID - primary key auto
    • 主键自动。
    • themname - varchar 50
    • themname - varchar 50
    • imageURL - varchar 200
    • imageURL - varchar 200
    • themelocation - array of pageIDs.
    • 主题定位——pageIDs的数组。
  • 主题主题-主键自动主题- varchar 50 imageURL - varchar 200主题定位-数组的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

pageID - pagename - pagetitle - mainimage 1 - kids - kids Party -一些image 2 - corporate - corporate events -一些image 3 -成人-成人派对-一些图片。

themes

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

主题- themename - themename - mainimage - themelocation 2 pizza imageURL - imageURL 1,3 - 3 minions imageURL - imageURL 1,2,3 4 rainbow imageURL - imageURL 1。

1 个解决方案

#1


0  

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.

如果每个页面都包含多个主题,并且每个主题可能出现在多个页面中,那么您将讨论许多(或n:m)关系。

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.

因此,您将创建一个名为pagetopic的表,它列出了页面的主题。此表包含一个页面ID和一个主题ID。而每一页ID可以多次引用,和每个主题ID,这两个领域的结合可以独特,因为表中的每一行代表一个页面与主题之间的联系,这是没有意义的两次相同的主题相同的页面的链接。

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

这个表替换了themeLocations中使用逗号分隔的页面id列表。

#1


0  

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.

如果每个页面都包含多个主题,并且每个主题可能出现在多个页面中,那么您将讨论许多(或n:m)关系。

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.

因此,您将创建一个名为pagetopic的表,它列出了页面的主题。此表包含一个页面ID和一个主题ID。而每一页ID可以多次引用,和每个主题ID,这两个领域的结合可以独特,因为表中的每一行代表一个页面与主题之间的联系,这是没有意义的两次相同的主题相同的页面的链接。

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

这个表替换了themeLocations中使用逗号分隔的页面id列表。