需要数据库设计指导

Mic*_*les 6 sql database database-design erd

一位兼职漫画家的奶农也有几头奶牛.他将每头牛分配给一个特定的牛群.在每个牛群中,农民都有一头他最喜欢的牛 - 通常是牛在动画片中的特色.每个牛群中的一些不满,主要是那些认为应该出现在卡通片中的人,不同意农民对最喜欢的牛的选择,他们贬低地称之为神圣的牛.结果,每个牛群现在都选出了一个牧群领袖.

这就是我认为表格应该是什么样的,如果可以做得更好,你可以告诉我吗?到目前为止,我正在使用喜欢的表做多对多,因为中间是这是最好的解决方案,也不需要SQL语句这只是出于设计目的.

先感谢您

Table Herd           Table Favorite               Table Cartoon   Table Cow
PK herdID          Intermediate Table             PK cartoonID     PK cowID
   herdname                                          cartoonTitle     cowName
   herdleader                                        cartoonType
                                                     cartoonDate
Run Code Online (Sandbox Code Playgroud)

编辑图片@ 3:01 pmEST这是对的吗?

cowErd http://img838.imageshack.us/img838/1268/capture3h.png

添加了新的图像@ 8:57 am 7/20/2010可以有人评论这个ERD请 Erd2 http://img37.imageshack.us/img37/5794/capture3fc.png

添加新图片@ 12:47 pm 7/20/2010除非有任何异议,这是每个Mark的解释标记ERD的最终草案 http://img651.imageshack.us/img651/691/capture4b.png

Ada*_*sch 5

迈克尔:

问题陈述中的名词是什么,有多少名词?

Farmer  - There is one farmer
Cow     - There are many cows
Herd    - There are many herds
Cartoon - There are many cartoons
Run Code Online (Sandbox Code Playgroud)

因为只有一个农民,所以不要让他参加未来的讨论.这些是您的基础实体.

每个实体有哪些属性?

Cow     - each cow has a name
        - each cow is a member of a herd
Herd    - each herd has a name
        - each herd has a cow that is the sacred cow
        - each herd has a cow that is the herd leader
Cartoon - each cartoon has a name
        - each cartoon may have a cow that appears in it 
             (not specified definitively)
Run Code Online (Sandbox Code Playgroud)

所以这些属性中的一些引用其他引用,而有些则不引用.不引用其他基本实体的属性很简单.其他的需要更多的考虑.

Can a cow be a member of more than one herd?
Must a cow be a member of a herd?
Can a herd have more than one cow that is the sacred cow?
Must each herd have a cow that is the sacred cow?
Can a herd have more than one cow that is the herd leader?
Must each herd have a cow that is the herd leader?
Run Code Online (Sandbox Code Playgroud)

这些问题有助于概述实体之间的关系是强制性的还是可选的,以及这些关系是一对多还是多对多.