【发布时间】:2011-01-31 09:12:33
【问题描述】:
我正在尝试弄清楚如何使用 Postgresql 8 定义数据库的架构。
我有 2 张桌子:
Journals, Books
定义我拥有的出版物
Journal:
id_j, name, issn, other fields
Book:
id_b, name, isbn, author, other fields
我还有另一个表 Scans,它在逻辑上引用了前面的两个表。
Scans:
id, medium, source, status
每个Journal 或Book 可以有多个Scan,但每个Scan 只能引用一个Journal 或Book。
为了形式化,我的第一个想法是在Scans 中放入两个外键
Scans:
id, medium, source, status, id_j, id_b
并填写id_j或id_b
但这个解决方案在我看来有点奇怪。
我不想(如果可能的话)以这样的方式定义表格:
Scans:
id, medium, source, status, id_other_table, other_table_name
因为我想在表格之间建立正式的联系。
有什么想法吗?
【问题讨论】:
标签: sql database database-design postgresql