【发布时间】:2013-06-05 01:37:38
【问题描述】:
我对数据库设计非常陌生。
我有一个疑问。这个问题非常基本。但请帮帮我。我会尝试通过一个例子来解释它。
假设,我把书放在一张桌子上,而他们的作者放在另一张桌子上(假设一本书只由一位作者(一对多)写,而一位作者可以写多本书(多对一))。 我不知道如何准确链接表格以及应该自动增加什么?
tblBooks //Table 1 contains two entities
{
bookId // This field is auto-incremented
bookName
}
tblAuthors //Table 2
{
authorId // Should this field also be auto-incremented?
authorName
Field3 // What should be the 'Field3' then which acts as link between both the tables?
// What exactly is foreign key? Here 'Field3' would be foreign key or what?
}
帮助赞赏
【问题讨论】:
-
authorID 会自动递增,Field3 实际上会在 tblBooks 中并被称为 authorID 来链接它们
-
@PatrickEvans 所以在一对多关系中,链接字段位于第一个表中?这个字段是否称为外键?
-
是的,“Many”表获取“One”表的外键。
标签: database database-design one-to-many