ER Diagram
ER Diagram
ER Diagram
Entity:A real-world object that can be distinctly identified may represent some real physical object.
E.g., Satish is a government employee; Kareena Kapoor is an actress; my car is a Honda City
May represent some conceptual idea E.g., SC304 is a course; Semester 1 2001/2002 is a semester
An entity set is a set of entities of the same type that share the
same properties.
Example: set of all persons, companies, trees, holidays.
Attributes: An entity is represented by a set of attributes, that is,descriptive properties possessed by all members
of an entity set.(value from corresponding entity)
Example: customer = (customer-name, social-security, customer-street, customer-city)
account = (account-number, balance)
Attribute types:
• Simple and composite attributes.
• Single-valued and multi-valued attributes
• Null attributes
• Derived attributes
• Identifiers(Key) attributes
Composite Simple
Key is underlined
Single valued versus multivalued
Single valued: single value associated with an attribute
Multivalued: may have more than one values. E.g., University degree attribute may contain B.Eng., M.Eng., or Ph.D.
• Composite attributes b/w ( ) and separating with commas and multivalued b/w { }. Such attributes r
called COMPOSITE ATTRIBUTES
Null : An attribute takes a null value when an entity does not have a value for it. eg house_no
Height of a person attribute is missing n homephone attribute is not known attribute.
Identifiers (Keys): An attribute(or combination of attributes) that uniquely identifies the instances of an entity type.
Identifiers will not change in value,will not be null.No intelligent Identifiers( containing people or locations
that might change).
ENTITY TYPE
RELATIONSHIP TYPE
ATTRIBUTE
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
TOTAL PARTICIPATION OF E2 IN R
GENERALIZATION OR SPECIALIZATION
ROLE INDICATOR
An attribute can also be a property of a relationship set. For instance, the depositor relationship set between entity sets
customer and account may have the attribute access-date.
Relationship sets that involve two entity sets are binary (or degree two). Generally, most relationship sets in a database
system are binary.
Relationship sets may involve more than two entity sets. The entity sets customer, loan, and branch may be linked by
the ternary (degree three) relationship set. Or may say: Urnary Relationship, Binary relationship, Ternary Relationship
One entity related Entities of two different types Entities of three different
to another of the same entity type related to each other types related to each other
The labels “manager” and “worker” are called roles; they specify how employee entities interact via the works-for
relationship set. Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles.
Role labels are optional, and are used to clarify semantics of the relationship.
.
Most useful in describing binary relationship sets For a binary relationship set the mapping cardinality must be
one of the following types:
– One to one: Each entity in the relationship must have exactly one related entity.
– One to many (many to one): An entity in the relationship on one side can have many related entities but on the other side
will have maximum of one related entity.
– Many to many: Entities on both the sides can have many related entities on the other side.
We distinguish among these types by drawing either a directed line ( ), signifying “one,” or an undirected line (—),
signifying many,” between the relationship set and the entity set.
Unary Relationships:
Binary Relationships:
Ternary Relationships:
Note: Relationships can have
Attributes of their own.
Employee WORKS_FOR
Department
r1
emp1
r2 d1
emp2
r3 d2
emp3
r4 d3
emp4
emp5 r5
DDL: customer(ssn,cust_nm,cust_st,cust_city)
Loan( Loan_nmbr,amt)
Borrower(ssn,loan_nmbr)
OR
customer(ssn,cust_nm,cust_st,cust_city)
Loan( Loan_nmbr,amt)
A customer is associated with at most one loan via the relationship borrower and a loan is associated with at most one
customer via borrower.
If borrower also has attributes(say: amount,date) then DDL : borrower(amt,dt#)
In the one-to-many relationship, a loan is associated with at most one customer via borrower; a customer is associated with
several (including 0) loans via borrower
In the many-to-one relationship, a loan is associated with several (including 0) customers via borrower; a customer is
associated with at most one loan via borrower.
A customer is associated with several (possibly 0) loans via borrower. A loan is associated with several (possibly 0)
customers via borrower.
Each entity may result in a relation whose attributes are the properties for the entity .Each relationship may result in
a relation whose attributes link the entities described in the relationship
Weak Entity Sets: A weak entity is an entity that cannot be uniquely identified by its own attributes alone.
An entity set that does not have a primary key is referred to as a weak entity set.Has no key attributes.
The existence of a weak entity set depends on the existence of a strong entity set; it must relate to the strong
set via a one-to-many relationship set.
The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the
entities of a weak entity set.(or Set of attributes that uniquely identify weak entities related to same owner entity).
The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak
entity set is existence dependent, plus the weak entity set’s discriminator.(Primary key of weak entity: identifying
owner’s primary key + partial key)
We depict a weak entity set by double rectangles. We underline the discriminator of a weak entity set with a dashed line.
Example:
Primary Key
III] A publishing company produces scientific books on various subjects. The books are written by authors who specialize in
one particular subject. The company employs editors who, not necessarily being specialists in a particular area, each take
sole responsibility for editing one or more publications. A publication covers essentially one of the specialist subjects and is
normally written by a single author. When writing a particular book, each author works with on editor, but may submit another
work for publication to be supervised by other editors. To improve their competitiveness, the company tries to employ a variety
of authors, more than one author being a specialist in a particular subject.
IV] A General Hospital consists of a number of specialized wards (such as Maternity, Paediatry, Oncology, etc). Each ward
hosts a number of patients, who were admitted on the recommendation of their own GP and confirmed by a consultant
employed by the Hospital. On admission, the personal details of every patient are recorded. A separate register is to be held
to store the information of the tests undertaken and the results of a prescribed treatment. A number of tests may be conducted
for each patient. Each patient is assigned to one leading consultant but may be examined by another doctor, if required.
Doctors are specialists in some branch of medicine and may be leading consultants for a number of patients, not necessarily
from the same ward. Partial Answer
FULL ANSWER
V] A database is to be designed for a Car Rental Co. (CRC). The information required includes a description of cars,
subcontractors (i.e. garages), company expenditures, company revenues and customers. Cars are to be described by such
data as: make, model, year of production, engine size, fuel type, number of passengers, registration number, purchase price,
purchase date, rent price and insurance details. It is the company policy not to keep any car for a period exceeding one year.
All major repairs and maintenance are done by subcontractors (i.e. franchised garages), with whom CRC has long-term
agreements. Therefore the data about garages to be kept in the database includes garage names, addressees, range of
services and the like. Some garages require payments immediately after a repair has been made; with others CRC has made
arrangements for credit facilities. Company expenditures are to be registered for all outgoings connected with purchases,
repairs, maintenance, insurance etc. Similarly the cash inflow coming from all sources - car hire, car sales, insurance claims -
must be kept of file.CRC maintains a reasonably stable client base. For this privileged category of customers special credit
card facilities are provided. These customers may also book in advance a particular car. These reservations can be made for
any period of time up to one month. Casual customers must pay a deposit for an estimated time of rental, unless they wish to
pay by credit card. All major credit cards care accepted. Personal details (such as name, address, telephone number, driving
licence, number) about each customer are kept in the database.
VI] A database is to be designed for a college to monitor students' progress throughout their course of study. The students are
reading for a degree (such as BA, BA(Hons) MSc, etc) within the framework of the modular system. The college provides a
number of module, each being characterised by its code , title, credit value, module leader, teaching staff and the department
they come from. A module is co-ordinated by a module leader who shares teaching duties with one or more lecturers. A
lecturer may teach (and be a module leader for) more than one module. Students are free to choose any module they wish
but the following rules must be observed: some modules require pre-requisites modules and some degree programmes have
compulsory modules. The database is also to contain some information about students including their numbers, names,
addresses, degrees they read for, and their past performance (i.e. modules taken and examination results).
An entity that is member of a subclass represents the same real-world entity as some member of the superclass .The
Subclass member is the same entity in a distinct specific role :-
1. An entity cannot exist in the database merely by being a member of a subclass; it must also be
a member of the superclass
2. A member of the superclasscan be optionally included as a member of any number of its subclasses
Example: A salaried employee who is also an engineer belongs to the two subclasses
ENGINEER and SALARIED_EMPLOYEE (It is not necessary that every entity in a superclass
be a member of some subclass).
Example:
SPECIALIZATION:
Specialization is process of defining a set of subclasses of an entity type.It’s a set of subclasses form a
specialization on the basis of some distinguishing characteristic(s). Top-down design process; we designate subgroupings
within an entity set that are distinctive from other entities in the set.These subgroupings become lower-level entity sets that
have attributes or participate in relationships that do not apply to the higher-level entity set.
Define different roles for different entities of same entity type. Associate additional specific attributes to subclass.
Depicted by a triangle component labeled ISA (i.e., savings-account “is an” account)
GENERALIZATION:
Specialization and generalization are simple inversions of each other; they are represented in
an E-R diagram in the same way.
A bottom-up design process:A combine a number of entity sets that share the same features into a
higher-level entity set.To generalize a set of entity types into a single superclass .Identify common features.
Generalize into a superclass; original entity types become subclasses.
Membership Constraint:
Determine which entity belong to specific subclass using condition (predicate) on attribute of superclass.
Condition is a constraint specifying subclass membership. Predicate-defined (or condition-defined) subclasses: All
subclasses have membership condition on same attribute of superclass
E.g., attribute JobType added to EMPLOYEE can be used to specify membership condition
Disjointness/Overlapping constraint
Disjoint: Entity can be a member of at most one subclass of specialization (“d” in circle)
Overlapping: Entity can be a member of more than subclass(default; some notations depict this as “o” in circle)
Total/Partial constraint
Total specialization: Every entity in superclass must be a member of some subclass (double-line)
Partial specialization: Some entities in superclass may not be a member of subclasses (single-line)
Independence of completeness and disjointness constraints; hence 4 constraints on specialization
Specialization Lattice: A subclass may participate in more than one class/subclass relationship.One subclass can have
more than one superclass
Hierarchy(ladder) has a constraint that every subclass has only one superclass(called single inheritance)
In a lattice(web,network,pattern), a subclass can be subclass of more than one superclass(called multiple inheritance)
(two superclass can have one common subclass)
AGGREGATION
In E-R, a relationship type cannot be connected directly to another relationship type.
To overcome this, aggregates are used.
Example:
3) Weak Entity
4) M:M
5) 1:1
(ii)