Assume there is an entity type called person , and entity subtypes called customer and employee . When a person is created, the designer of the database has two options:
He/she can demand that the person be classified as one of the subtypes.
He/she can allow a person to be created without classifying the person as any subtype.
OPTİONAL VERSUS MANDATORY Neither one is preferable to the other. The proper one to choose depends on the business situation. Mandatory sub-typing is represented by creating a double line from the super-type ( person in the following ER diagram) to the circle. Optional sub-typing is represented by leaving a single line from the super-type to the circle.
Subtypes are generally thought of in terms of X is a Y (which is why these are commonly referred to as is-a relationships). Another type of relationship that needs to be represented in a database is the part of relationship, more formally called aggregation . When an entity is made up of several different types of other entities, an aggregation relationship may be called for.
AGGREGATİON OF ENTİTY TYPES Consider the relationship between a car and its engine and body. The engine and body are both part of the car. The relationship is represented as follows in an ER diagram.
Two entities can have more than one type of relationship. This is not surprising; further, it is not difficult to represent in a database or in an ER diagram. Consider the entity types person and insurance policy and the relationships between them of pays for and is insured under.
PARALLEL RELATİONSHİPS A person pays for zero or more insurance policies. An insurance policy is paid for by exactly one person. A person is insured by zero or more insurance policies. An insurance policy insures one or more persons.
Binary relationships may have different meanings so that they can’t be combined into ternary relationships .
You may have a ternary relationship Customer-Loan-Branch and other binary relationships between Customer, Loan and Branch
Customer Loan Borrow Branch Issue Buy_stock
A CASE STUDY A primary school student writes a composition about a picnic: Today is Sep 9, the weather is fine. My classmates, John, Mary and I go to a picnic in Sai Kung. Our teacher is Ms Wong Initial Design: Picnic weather destination date Students Name Teacher Name
Every student has an ID number, it is better to keep it in the database and use it as a key
I bet that there won’t be teachers with the same name; otherwise, I’ll add employee number and use it as a key
goes is N:M, why ? A picnic has more than one student participating; also, a student can go to more than 1 picnic. However, this N:M relationship allows a student to go to more than one picnic on the same date
leading is N:1 , why? Depends on your assumptions
I assume a teacher can only lead 1 picnic on a certain date, so given the teacher name and the date, I can identify a picnic
Picnic is made a weak entity. I could have added a PicnicNo, but it would be very awkward.
My solution Question: How to record number of students in a picnic? Student StudentNo Name weather date destination Picnic goes leading Teacher Name
The use of an attribute or entity set to represent an object.
Should an address be an attribute or entity?
Whether a real-world concept is best expressed by an entity set or a relation set.
Should marriage be an entity or relationship?
Should picnic be an entity or relationship?
The use of a ternary relationship versus a pair of binary relationships.
See the borrow-loan-branch example
The use of a strong or weak entity set.
See the employee-dependent example
E-R DİAGRAM FOR COMPANY DATABASE EMPLOYEE WORKS_FOR MANAGES CONTROLS Startdate DEPARTMENT WORKS_ON PROJECT Hours DEPENDENTS_OF DEPENDENT SUPERVISION supervisee supervisor Fname Minit Lname Name Sex Address Salary Ssn Bdate Number Of Employees Locations Can you translate it back into English? Name Number Name Number Location Relationship Birthdate Sex Name
A weak entity set becomes a table that includes a column for the primary key of the identifying strong entity set
A strong/regular entity set reduces to a table with the same attributes.
Composite key payment loan-no payment-date payment-no payment-amount L-17 L-15 L-23 5 22 11 10 May 1999 23 May 1999 17 May 1999 50 300 75 customer customer-name customer-street customer-id Jones Hayes Smith 321-12-3123 677-89-9011 019-28-3746 Main Main North customer-city Harrison Rye Harrison
REPRESENTİNG RELATİONSHİP SETS AS TABLES depositor
A many-to-many relationship set is represented as table with columns for the primary keys of the two participating entity sets, and any descriptive attributes of the relationship set.
customer borrow loan loan-no cust-no share% date cust-name
For 1:N and 1:1 relationships, you can create a table for each relationship
But it is more concise to merge the relationship-table with the entity-table on the “N” side
customer cust-no cust-name A12345 B56789 Peter Wong Mary Cheung loan loan-no L-001 L-002 date Sep 2000 Aug 2001 customer borrow loan cust-no cust-name date loan-no cust-no A12345 B56789 indicates who borrowed the loan
Since a weak entity has to include the primary key of the identifying entity, the 1:N relationship is already captured. E.g., The payment table already contains information about the Loan (I.e., loan_no)
Already indicates the 1:N relationship between loan-no and payment-no payment loan-no payment-date payment-no payment-amount L-17 L-17 L-17 5 7 6 10 May 1999 23 May 1999 17 May 1999 50 300 75