为类别和子类别设计数据库

时间:2018-04-04 05:16:07

标签: database database-design

基本上,我试图弄清楚亚马逊如何构建他们的图书部分。查看亚马逊的书页(https://www.amazon.com/s/ref=lp_2_ex_n_1?rh=n%3A283155&bbn=283155&ie=UTF8&qid=1522817105)。

我们有几个主要类别:Arts&摄影,传记&回忆录等。

如果我点击传记&回忆录,例如,我导致了一系列子类别。 I.E.传记与传记回忆录>历史>亚洲>日本

例如,有重复的子类别名称:历史>亚洲>日本

如何映射此类信息以使其可扩展?

以下是错误的方法......?

Categories table
+----+-----------------------+-----------+
| id |         name          | parent_id |
+----+-----------------------+-----------+
|  1 | Biographies & Memoirs | null      |
|  2 | Historical            | 1         |
|  3 | Asia                  | 2         |
|  4 | History               | null      |
|  5 | Asia                  | 4         |
|  6 | Japan                 | 5         |
|  7 | Japan                 | 3         |
+----+-----------------------+-----------+

Books
+----+-------------------------------------+----------+
| id |                name                 | category |
+----+-------------------------------------+----------+
|  1 | The Lone Samurai                    |        7 |
|  2 | The Human Tradition in Modern Japan |        7 |
|  3 | Okinawa: The Last Battle            |        6 |
+----+-------------------------------------+----------+

Authors
+----+---------------+----------+
| id |   firstname   | lastname |
+----+---------------+----------+
|  1 | James M.      | Burns    |
|  2 | Roy E.        | Appleman |
|  3 | Russell A.    | Gugeler  |
|  4 | John          | Stevens  |
|  5 | William Scott | Wilson   |
|  6 | Anne          | Walthall |
+----+---------------+----------+

Authors to books (Many to many)
+---------+-----------+
| book_id | author_id |
+---------+-----------+
|       3 |         1 |
|       3 |         2 |
|       3 |         3 |
|       3 |         4 |
|       1 |         5 |
|       2 |         6 |
+---------+-----------+

0 个答案:

没有答案