【发布时间】:2015-02-15 00:30:06
【问题描述】:
我有一张名为 production 的表。该表将包含与电影、电视剧、纪录片和动漫相关的数据,这样我就不必为每种类型的作品创建一个表。但它产生了一个问题。由于电视剧也可以是纪录片,我将不得不使用一个连接表来定义我们正在谈论的制作类型。我将在下面粘贴我的结构。
Table I : production
production_id (Auto Increment & Unique)
production_start_date (Movies won't get any value because start_date is only valid for Tv Series, so some columns will be empty in this table.)
production_name
production_end_date (See below)
production_season_number (see below)
Table II : types
type_id (Auto Increment & Unique)
type_value (This column will store only four values)
Table III : production_type
production_id (Foreign Key From production table)
type_id (Foreign Key from types table)
这是为特定目的构建数据库的正确方法吗?请尽可能具体和残酷。 :)
【问题讨论】:
-
实现目标的完美方式。
-
您的问题在更一般的情况下确实非常好,令人惊讶的是,我不确定它是否已得到充分回答。这是一个类似问题的链接:stackoverflow.com/a/7097323/4350148。然而,那里的答案主要是指性能考虑和数据库的规范化(这当然很重要,但不是全部)。我认为有一个更大的问题与“本体建模”有关。我认为还需要考虑可能形成的查询是什么,以及模型是否充分区分数据以回答这些查询。
标签: mysql sql foreign-keys relational-database foreign-key-relationship