Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Erd cardinality

3,179 views

Published on

Published in: Education, Business

Erd cardinality

  1. 1. ERD Cardinality OOD Inge Powell
  2. 2. ERD Cardinality  When we show relationships between tables we need to show the cardinality.  Depending on the data we are storing there are several options to choose from.  If using Visio to create a diagram, it takes its initial value from the database store.
  3. 3. Erd Cardinality  The cardinality relationship is shown with lines between two entities to indicate a relationship. Entity A  This Entity B line denotes that there is a relationship between the entities.
  4. 4. ERD Cardinality  The ENDS of these lines denote the cardinality to that entity. Entity A  This Entity B is a ‘One to One’ relationship.  This means that Entity A will relate to only one of Entity B.  And Entity B will relate to only one of Entity A
  5. 5. Erd Cardinality  Here is an example.. Bus Driver  One Driver drives just one Bus.  One Bus has just one Driver.  The records might be held like this: Bus Bus PK BusID PK BusID Colour Colour NoOfSeats NoOfSeats FK DriverID FK DriverID Driver Driver PK DriverID PK DriverID Name Name Points Points FK BusID FK BusID
  6. 6. ERD Cardinality  The use of ‘Crows Feet’. Entity A  This Entity B is a ‘One to Many’ relationship.  This means that Entity A will relate to many of Entity B.  And Entity B will relate to only one of Entity A.
  7. 7. Erd Cardinality  Here is an example. Customer Order  One Customer may have many orders.  One Order is for just one Customer.  The records might be held like this: Customer Customer PK CustID PK CustID Name Name Address Address TelNo TelNo Order Order PK OrderNo PK OrderNo Date Date FK CustID FK CustID
  8. 8. ERD Cardinality  The use of ‘Crows Feet’. Entity A Entity B  This is a ‘Many to One’ relationship.  This means that Entity A will relate to only one of Entity B.  And Entity B will relate to many of Entity A.  (We still tend to refer to as a one to many, just the other way round from B to A)
  9. 9. Erd Cardinality  Here is an example. Product Supplier  One Product will have just one Supplier.  One Supplier will supply many Products.  The records might be held like this: Product Product PK ProdID PK ProdID PName PName Price Price Supplier Supplier PK SuppID PK SuppID Name Name Address Address TelNo TelNo
  10. 10. ERD Cardinality  The use of ‘Crows Feet’. Entity A  This Entity B is a ‘Many to Many’ relationship.  This means that Entity A will relate to many of Entity B.  And Entity B will relate to many of Entity A.
  11. 11. ERD Cardinality  Many to Many - This can cause problems with data, as we can’t pinpoint the link. Entity A Entity B  Imagine this, a Lender can borrow many Books. But a Book can be borrowed by more than one Lender. Lender Book
  12. 12. ERD Cardinality  How do we know who has each individual book? Lender Book  Also when we look at the data, how will we store this? Lender Lender PK LenderID PK LenderID Name Name Address Address FK BookID FK BookID FK BookID FK BookID FK BookID Book Book PK BookID PK BookID FK FK Title Title Author Author LenderID LenderID
  13. 13. ERD Cardinality  To manage the many to many relationship, the data would need to keep growing.  This still causes problems,  Who has the book now?  This  We is silly!! can resolve this  By adding a link table. Book Book PK BookID PK BookID Title Title Author Author FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID
  14. 14. ERD Cardinality  To resolve a many to many relationship. Entity A  We Entity B resolve it by adding a link table. Entity A  This Entity C Entity B means we now have two manageable one to many relationships instead.
  15. 15. ERD Cardinality  The resolved many to many relationship. Lender LendRecord Book  One lender can have several LendRecords  One LendRecord is for just one Lender  One Book can have several LendRecords  One LendRecord is for just one Book
  16. 16. ERD Cardinality  Here is the resolved example. Lender LendRecord Book  The data for this system might look something like this: Lender Lender PK LenderID PK LenderID Name Name Address Address Book Book LendRecor LendRecor d d PK RecordID PK RecordID FK BookID FK BookID FK LenderID FK LenderID PK BookID PK BookID Title Title Author Author
  17. 17. ERD Cardinality  The LendRecord record could be deleted when the book is returned. Lender  Or LendRecord Book fields added to identify the current loan. Lender Lender PK LenderID PK LenderID Name Name Address Address Book Book LendRecor LendRecor d d PK RecordID PK RecordID FK BookID FK BookID FK LenderID FK LenderID OnLoanYN OnLoanYN Date PK BookID PK BookID Title Title Author Author

×