小编Jdr*_*uwe的帖子

基于PostgreSQL继承的数据库设计

我正在开发一个简单的保姆应用程序,它有两种类型的用户:“父母”和“保姆”。我使用 postgresql 作为我的数据库,但我在设计我的数据库时遇到了麻烦。

'Parent' 和 'Babysitter' 实体具有可以概括的属性,例如:用户名、密码、电子邮件……这些属性可以放置在名为“用户”的父实体中。它们也都有自己的属性,例如:Babysitter -> age。

就 OOP 而言,事情对我来说非常清楚,只需扩展用户类就可以了,但在 DB 设计中,情况有所不同。在发布这个问题之前,我在互联网上漫游了一周,以寻找对这个“问题”的洞察。我确实找到了很多信息,但
在我看来,有很多分歧。以下是我读过的一些帖子:

/sf/ask/13320751/ : Table-Per-Type (TPT), Table-Per-Hierarchy (TPH) 和 Table- Per-Concrete (TPC) VS '将 RDb 强制转换为基于类的需求是完全不正确的。

多种用户类型 - 数据库设计建议

Table: `users`; contains all similar fields as well as a `user_type_id` column (a foreign key on `id` in `user_types`
Table: `user_types`; contains an `id` and a `type` (Student, Instructor, etc.)
Table: `students`; contains fields only related to students as well as a `user_id` column (a foreign key …
Run Code Online (Sandbox Code Playgroud)

postgresql database-design inheritance

5
推荐指数
1
解决办法
801
查看次数

标签 统计

database-design ×1

inheritance ×1

postgresql ×1