Unit - 2: Data Modeling Using The Entity-Relationship (ER) Model
Unit - 2: Data Modeling Using The Entity-Relationship (ER) Model
Chapter 7
Conceptual Design
Logical Design
Physical Design
Application Program Design
Example COMPANY Database
Complex Attributes
Arbitrary Nesting of Composite and Multivalued
attributes
(),{}
Ex: If a person can have more than one residence and
each residence can have a single address and multiple
phones, an attribute Address_phone for a person can
be specified as
Address_phone ({Phone (Area_code, Phone_number)},
Address (Street_address (Number, Street,
Apartment_number), City, State, Zip) ) }
Entity Types, Entity Sets, Keys and Value sets
Entity type: a collection of entities that have the
same attributes.
Ex: employee, student, etc.,
Participation
Cardinality Ratios for Binary Relationships
Specifies the maximum number of relationship
instances that an entity can participate in.
Possible Cardinality ratios for binary relationship
types are :
– one-to-one (1:1)
– one-to-many (1:N)
– many-to-many (M:N)
Ex: employee head-of department (1:1)
student enrolls course (m:n)
lecturer offers course (1:n) assuming a
course is taught by a single lecturer
Participation Constraints and Existence Dependence
Two types:
Total participation
Partial participation
Total Participation :
Every entity instance must be connected through the
relationship to another instance of the other participating
entity types.
Here the participation of Employee in works_for is called
total participation.
Means, every entity in the total set of employee
entities must be related to a department entity via
Works_for.
Assumptions:
Find relationships
• One Bank has many branches and each branch belongs to only one
bank, hence the cardinality between Bank and Branch is One to Many.
• One Branch offers many loans and each loan is associated with one
branch, hence the cardinality between Branch and Loan is One to Many.
• One Branch maintains multiple accounts and each account is
associated to one and only one Branch, hence the cardinality between
Branch and Account is One to Many
• One Loan can be availed by multiple customers, and each Customer
can avail multiple loans, hence the cardinality between Loan and
Customer is Many to Many.
• One Customer can hold multiple accounts, and each Account can be
held by multiple Customers, hence the cardinality between Customer
and Account is Many to Many
Solution Step 2: Identify relationships between entities
• Bank has Branch
• Branch maintains accounts
• Branch offers loans
• Account is held by customer
• Loan is availed by customer
Solution Step 2: Analyze cardinality of relationships
•Bank has Branch : A bank has many branches->1:N
•Branch maintains accounts: One branch maintains
many accounts-> 1:N
•Branch offers loans : One branch offers many loans -
> 1:N
•Account is held by customer -> M:N
•Loan is availed by customer -> M:N
Step 3: Identify the key attributes
• BankCode (Bank Code) is the key attribute for the Entity “Bank”, as
it identifies the bank uniquely.
• Branch# (Branch Number) is the key attribute for “Branch” Entity.
• Customer# (Customer Number) is the key attribute for “Customer”
Entity.
• Loan# (Loan Number) is the key attribute for “Loan” Entity.
• Account No (Account Number) is the key attribute for “Account”
Entity.
Merits
• Easy to understand. Represented in Business Users
Language.
• Can be understood by non-technical specialist.
• Intuitive and helps in Physical Database creation.
• Can be generalized and specialized based on needs.
• Can help in database design.
• Gives a higher level description of the system.
Demerits
• Physical design derived from E-R Model may have
some amount of ambiguities or inconsistency.
• Sometime diagrams may lead to misinterpretations
Exercise 2.7 The Prescriptions-R-X chain of
pharmacies has ordered to give you a free
lifetime supply of medicines if you design its
database. Given the rising cost of health care,
you agree. Here's the information that you
gather:
Patients are identified by an SSN, and their names,
addresses, and ages must be recorded.
Doctors are identified by an SSN. For each doctor,
the name, specialty, and years of experience must
be recorded.
Each pharmaceutical company is identified by name
and has a phone number.
For each drug, the trade name and formula must be
recorded.
Each drug is sold by a given pharmaceutical company, and
the trade name identifies a drug uniquely from among the
products of that company. If a pharmaceutical company is
deleted, you need not keep track of its products any longer.
Each pharmacy has a name, address, and phone number.
Every patient has a primary physician. Every doctor has at
least one patient.
Each pharmacy sells several drugs and has a price for
each. A drug could be sold at several pharmacies, and the
price could vary from one pharmacy to another.
Doctors prescribe drugs for patients. A doctor could
prescribe one or more drugs for several patients, and a
patient could obtain prescriptions from several doctors.
Each prescription has a date and a quantity associated
with it. You can assume that if a doctor prescribes the
same drug for the same patient more than once, only the
last such prescription needs to be stored.
Pharmaceutical companies have long-term contracts with
pharmacies. A pharmaceutical company can contract with
several pharmacies, and a pharmacy can contract with
several pharmaceutical companies. For each contract,
you have to store a start date, an end date, and the text of
the contract.
Pharmacies appoint a supervisor for each contract. There
must always be a supervisor for each contract, but the
contract supervisor can change over the lifetime of the
contract.
Draw an ER diagram that captures the above
information. Identify any constraints that are not
captured by the ER diagram.
Exercise 2.8 : Although you always wanted to be an artist, you ended
up being an expert on databases. So now you set up a database
company, ArtBase, that builds a product for art galleries. The core of this
product is a database with a schema that captures all the information
that galleries need to maintain.
Galleries keep information about artists, their names (which are unique),
birthplaces, age, and style of art.
For each piece of artwork, the artist, the year it was made, its unique
title, its type of art (e.g., painting, lithograph, sculpture, photograph), and
its price must be stored. Pieces of artwork are also classified into groups
of various kinds, for example, portraits, still lifes, works by Picasso, or
works of the 19th century; a given piece may belong to more than one
group.
Each group is identified by a name (like those above) that describes the
group.
Finally, galleries keep information about customers. For each customer,
galleries keep their unique name, address, total amount of dollars they
have spent in the gallery (very important!), and the artists and groups of
art that each customer tends to like.
Draw the ER diagram for the Art Gallary database.
Proper Naming of Schema Constructs
Played Played
by Player _in
_of
Team Ground