130 likes | 147 Views
A library has many items. Item. Library. 1:M. An item is categorized by the type. Types. Item. 1:M. For each type, there is a series of “other” classifications. This library is only interested in genre and subject. Genre. Genre. Genre. Genre. Genre. Genre. Type. 1:M. Subject.
E N D
A library has many items Item Library 1:M
An item is categorized by the type. Types Item 1:M
For each type, there is a series of “other” classifications. This library is only interested in genre and subject. Genre Genre Genre Genre Genre Genre Type 1:M Subject Subject Subject Subject Subject 1:M 1:M 1:M
Each item may be removed by a library subscriber. Subscriber Subscriber Subscriber Item Item 1:M
A subscriber is a person. A subscriber may remove between 1 and 5 specific items. Subscriber Item 1:M
Now put it all together Subject 1:M 1:M Library 1:M Types Item 1:M Genre M:N EntitiesLibraryItem Types SubjectGenresSubscriber Subscriber
Primary Keys • Library – Library Code • Item – Call number • Genre – Genre Code • Subject – Subject Code • Subscriber – Subscriber ID
Foreign Keys Library—none Item—Library Code, Type Code, Subject Code, Subscriber Code Type – none Subject – none Subscriber—Call Number
How to build • If you look at the diagram, you see one of the entities has a M:N (many to many) relationship. You can’t build this type, so you need to break it into two separate relationships and introduce another entity….
How to build M:N • So you need to add a bridge entity. • We will call that entity Check Out. • The Primary Key (PK) for Check Out will be the PK from ITEM and the PK from Subscriber but together. Check Out PK is 2 entities…. • When I look at the attributes for the PK individually, I see that makes 2 foreign keys for Check Out • One that points back to the Item and one that points back to the Subscriber…. • This is how you build a M:N (many to many) relationship.
Updated diagram Subject 1:M 1:M Library 1:M Types Item 1:M Genre EntitiesLibraryItem Types SubjectGenresSubscriber Check OUT 1:M Check OUT 1:M Subscriber
Updated Primary Keys • Library – Library Code • Item – Call number • Genre – Genre Code • Subject – Subject Code • Subscriber – Subscriber ID • Check Out – Call Number, Subscriber ID
Updated Foreign Keys Library—none Item—Library Code, Type Code, Subject Code, None Type – none Subject – none Subscriber--None Check Out – Call Number, Subscriber ID Note that the changes in the Item and Subscriber entities.