简体   繁体   English

多种数据类型-一个表与多个表

[英]Many types of data - One table vs multiple tables

I am working on a webapplication, which main functionality will be to present some data to user. 我正在开发一个Web应用程序,其主要功能是向用户显示一些数据。 However, there are several types of these data and each of them have to be presented in a diffrent way. 但是,这些数据有几种类型,并且每种数据都必须以不同的方式表示。

For example I have to list 9 results - 3 books, 3 authors and 3 files. 例如,我必须列出9个结果-3本书,3位作者和3个文件。

Book is described with (char)TITLE, (text)DESCRIPTION. 用(char)TITLE,(text)DESCRIPTION描述书。

Author is described with (char)TITLE, (char)DESCRIPTION. 作者用(char)TITLE,(char)DESCRIPTION描述。

File is described with (char)URL. 文件用(char)URL描述。

Moreover, every type has fields like ID, DATE, VIEWS etc. Book and Author are presented with simple HTML code, File use external reader embed on the website. 此外,每种类型都有ID,DATE,VIEWS等字段。Book和Author带有简单的HTML代码,文件使用外部阅读器嵌入网站。

Should I build three diffrent tables and use JOIN while getting these data or build one table and store all types in there? 我应该建立三个不同的表并在获取这些数据时使用JOIN还是建立一个表并在其中存储所有类型? Which attitude is more efficient? 哪种态度更有效?

Additional info - there are going to be really huge amounts of records. 其他信息-将会有大量记录。

The logical way of doing this is keeping things separate, which is following the 3NF rules o the database design. 这样做的逻辑方法是使事情分开,这遵循数据库设计中的3NF规则。 This gives more flexibility while retrieving different kinds of results specially when there is huge amount of data. 这将提供更大的灵活性,同时特别是在有大量数据的情况下检索不同类型的结果时。 Putting everything in a single table is absolutely bad DB practice. 将所有内容放在单个表中绝对是DB的不良做法。

That depends on the structure of your data. 这取决于您的数据结构。

If you have 1:1 relationships, say one book has one author, you can put the records in one row. 如果您具有1:1的关系,比如说一本书有一位作者,则可以将记录放在一行中。 If one book has several authors or one author has several books you should set up seperate tables books and authors and link those with a table author_has_books where you have both foreign keys. 如果一本书有多位作者,或者一位作者有多本书,则应设置单独的表格booksauthors ,并将它们与具有两个外键的表格author_has_books链接。 This way you won't store duplicate data and avoid inconsistencies. 这样,您将不会存储重复的数据并避免不一致。

More information about db normalization here: 有关数据库规范化的更多信息,请参见:

http://en.wikipedia.org/wiki/Database_normalization http://en.wikipedia.org/wiki/Database_normalization

Separate them and create a relationship. 分开他们并建立关系。 That way, when you start to get a lot of data, you'll notice a performance boost because you are only calling 3 fields at a time (IE when you are just looking at a book) instead of 7. 这样,当您开始获取大量数据时,您会注意到性能有所提高,因为您一次只调用3个字段(即,当您只看书时即使用IE)而不是7。

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

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