简体   繁体   English

在网站中为不同页面设置单独的数据库是否是一种好习惯?

[英]Is it good practice having separate database for different pages in a website?

I have a website xyz.com that is going to be launched in an online server. 我有一个网站xyz.com ,该网站将在在线服务器中启动。 I have three pages x , y and z (suppose x is for image gallery, y is for video gallery, and z is for another gallery). 我有三个页面xyz (假设x用于图像库, y用于视频库, z用于另一个库)。 I need to have a comment section for each of the pages, and user input is going to be stored in database. 我需要为每个页面提供一个注释部分,并且用户输入将存储在数据库中。 There need not be any relation between the comments in different pages, or in another words, comment from one page doesn't have to relate with the comments in another pages. 不同页面中的注释之间不必有任何关系,换句话说,一个页面中的注释不必与另一页面中的注释相关。 I want to deal them separately. 我想分开处理。

Now my question is: 现在我的问题是:

Should I use one database and create just three different tables for each pages or should I create three completely different database each of them having one table? 我应该使用一个数据库并为每个页面创建三个不同的表,还是应该创建三个完全不同的数据库,每个数据库都有一个表? Which one is good practice? 哪个是好的做法?

You do not need to create the different databases and why would you? 您无需创建其他数据库,为什么要这么做?

  1. Create single database 创建单个数据库
  2. Create 2 tables " galleries " and " comments " 创建2个表“ galleries ”和“ comments

     galleries (id|title|name|type|date etc....) 

Gallery type can be "image" or "video" or etc... 画廊type可以是“图像”或“视频”等。

  1. when you load data for image(s) page do 当您加载图像页面的数据时

     select * from galleries where type='image' 

and when for video 以及何时观看视频

select * from galleries where type='video'

so on... 等等...

For comments: 征求意见:

create table 创建表

comments (id|comment_text|gallery_type...)

where gallery_type is the foreign key 其中gallery_type是外键

If your gallery types are lots you can always create a sperate table for gallery_types and give reference accordingly. 如果您的画廊类型很多,您总是可以为gallery_types创建一个单独的表并提供相应的参考。

根据需要使用一个数据库,该数据库具有多个表,因此无需为项目创建多个数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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