Professional Documents
Culture Documents
In the following example each student fills one seat in a class. Each seat is filled by one
student. (In this usage a "seat" implies not only a physical place to sit but also a specific
day and time.) This is a one-to-one relationship.
In the next example a single instructor may teach several courses. Each course has only
one instructor. This is a one-to-many relationship.
As shown below, a single student may register for several courses. A single course can
have many students enrolled in it. This is the many-to-many relationship.
The next example shows a relationship in which it is possible that no instances exist.
Each professor may teach several course sections but may not teach at all if on sabbatical.
Assume there is no team teaching, therefore each section must have a single professor.
Finally, a more complex example which shows more than one relationship. All of the
examples above depict single relationships. An actual E-R diagram would show the many
entities and relationships that exist within a system. Here each department offers at least
one course; there is no cross-listing of courses with other departments. Each course must
have at least one section but often has several sections.
Entity
An entity is an object or concept about which you want to store information.
Learn how to edit text on an entity.
Weak Entity : Occasionally, entities of an entity set need “help” to identify them
uniquely.
Entity set E is said to be weak if in order to identify entities of E uniquely, we need to
follow one or more many-one relationships from E and include the key of the related
entities from the connected entity sets.
Example : Nname is almost a key for football players, but there might be two with the
same name. Number is certainly not a key, since players on two teams could have the
same number. But number, together with the team name related to the player by Plays-on
should be unique.
Multivalued attribute
A multivalued attribute can have more than one value. For example, an employee entity
can have multiple skill values.
Derived attribute
A derived attribute is based on another attribute. For example, an employee's monthly
salary is based on the employee's annual salary.
Relationships
Relationships illustrate how two entities share information in the database structure.
Cardinality
Cardinality specifies how many instances of an entity relate to one instance of another
entity.
Ordinality is also closely linked to cardinality. While cardinality specifies the occurences
of a relationship, ordinality describes the relationship as either mandatory or optional. In
other words, cardinality specifies the maximum number of relationships and ordinality
specifies the absolute minimum number of relationships.
Recursive relationship
In some cases, entities can be self-linked. For example, employees can supervise other
employees.
We can express the overall logical structure of a database graphically with an E-R
diagram.
Its components are:
• rectangles representing entity sets.
• ellipses representing attributes.
• diamonds representing relationship sets.
• lines linking attributes to entity sets and entity sets to relationship sets.
In the text, lines may be directed (have an arrow on the end) to signify mapping
cardinalities for relationship sets. Figures 2.8 to 2.10 show some examples.
INFORMATION:
Entity : A data entity is anything real or abstract about which we want to store data.
Entity types fall into five classes: roles, events, locations, tangible things or concepts.
E.g. employee, payment, campus, book. Specific examples of an entity are called
instances. E.g. the employee John Jones, Mary Smith's payment, etc.
4. Fill in Cardinality
From the description of the problem we see that:
• Each department has exactly one supervisor.
• A supervisor is in charge of one and only one department.
• Each department is assigned at least one employee.
• Each employee works for at least one department.
• Each project has at least one employee working on it.
• An employee is assigned to 0 or more projects.
5. Define Primary Keys : The primary keys are Department Name, Supervisor Number,
Employee Number, Project Number.
6. Draw Key-Based ERD : There are two many-to-many relationships in the rough ERD
above, between Department and Employee and between Employee and Project. Thus we
need the associative entities Department-Employee and Employee-Project. The primary
key for Department-Employee is the concatenated key Department Name and Employee
Number. The primary key for Employee-Project is the concatenated key Employee
Number and Project Number.
7. Identify Attributes : The only attributes indicated are the names of the departments,
projects, supervisors and employees, as well as the supervisor and employee NUMBER
and a unique project number.
8. Map Attributes
Attribute Entity Attribute Entity
Department Department Supervisor Supervisor
Name Number
Employee Employee Supervisor Supervisor
Number Name
Employee Employee Project Project
Name Name
Project Project
Number
9. Draw Fully Attributed ERD
10. Check Results : The final ERD appears to model the data in this system well.
FURTHER DISCUSSION:
Step 1. Identify Entities
A data entity is anything real or abstract about which we want to store data. Entity types
fall into five classes: roles, events, locations, tangible things, or concepts. The best way to
identify entities is to ask the system owners and users to identify things about which they
would like to capture, store and produce information. Another source for identifying
entities is to study the forms, files, and reports generated by the current system. E.g. a
student registration form would refer to Student (a role), but also Course (an event),
Instructor (a role), Advisor (a role), Room (a location), etc.
(note that I’m now using singular names since my somewhat controversial decision to
switch to naming entities in the singular)
To read the notations of an Entity Relationship Diagram:
An Entity Relationship Diagram conveys a lot of information with a very concise
notation. The important part to keep in mind is to limit what you’re reading using the
following technique:
1. Choose two entities (e.g. Company and Employee)
2. Pick one that you’re interested in (e.g. how a single Company relates to
employees)
3. Read the notation on the second entity (e.g. the crow’s feet with the O above it
next to the Employee entity).
The set of symbols consist of Crow’s feet (which Wikipedia describes as looking like the
forward digits of a bird’s claw), O, and dash, but they can be combined in four distinct
combinations. Here are the four combinations:
• Zero through Many (crow's feet, O)
• One through Many (crow's feet, dash)
• One and Only One (dash, dash)
• Zero or One (dash, O)
Zero through Many
If, as in the diagram above, the notation closest to the second entity is a crow’s feet with
an O next to it, then the first entity can have zero, one, or many of the second entity.
Consequently the diagram above would read: “A company can have zero, one, or many
employees”.
This is the most common relationship type, and consequently many people ignore the O.
While you can consider the O optional, I consider it a best practice to be explicit to
differentiate it from the less common one through many relationship.
One through Many
If, as the next diagram shows, the notation closest to the second entity is a crow’s feet
with a dash, then the first entity can have one through many of the second entity. More
specifically it may not contain zero of the second entity. The example above would thus
read (read bottom to top): “A Project can have one through many Employees working on
it.”
This is an interesting combination because it can’t (and for various reasons probably
shouldn’t if it could) be enforced by a database. Thus, you will only see these in logical,
but not a physical, data models. It is still useful to distinguish, but your application will
need to enforce the relationship in business rules.
One and Only One (onne)
If the notation closest to the second entity contains two dashes it indicates that the first
entity can have one and only one of the second. More specifically it cannot have zero,
and it cannot have more than one. The example would thus read: “An Employee can have
one and only one Company.”
This combination is the most common after zero through many, and so frequently people
consider the second dash optional. In fact, some ignore both dashes, but I would highly
recommend at least using one for clarity so as not to confuse the notation with “I’ll fill in
the relationship details later”.
Zero or One
A zero or one relationship is indicated by a dash and an O. It indicates that the first entity
can have zero or one of the second, but not more than one. The relationship in the
example above would thus read: “A Project can have zero or one Technology Project.”
The zero or one relationship is quite common and is frequently abbreviated with just an O
(however it is most commonly seen in a many-to-many relationship rather than the one-
to-one above, more on this later).
Relationship Types
Having examined the four types of notation, the discussion wouldn’t be complete without
a quick overview of the three relationship types. These are:
• One to Many
• Many to Many
• One to One
One-to-Many
A one-to-many (1N) is by far the most common relationship type. It consists of either a
one through many or a zero through many notation on one side of a relationship and a
one and only one or zero or one notation on the other. The relationship between Company
and Employee in the example is a one-to-many relationship.
Many-to-Many
The next most common relationship is a many-to-many (NM). It consists of a zero
through many or one through many on both sides of a relationship. This construct only
exists in logical data models because databases can’t implement the relationship directly.
Physical data models implement a many-to-many relationship by using an associative (or
link or resolving) table via two one-to-many relationships.
The relationship between Employee and Project in the example is a many to many
relationship. It would exist in logical and physical data models as follows:
One-to-One
Probably the least common and most misunderstood relationship is the one-to-one. It
consists of a one and only one notation on one side of a relationship and a zero or one on
the other. It warrants a discussion unto itself, but for now the Project to Technology
Project relationship in the example is a one to one. Because these relationships are easy to
mistake for traditional one-to-many relationships, I have taken to drawing a red dashed
line around them. The red dashed line is not standard at all (although a colleague, Steve
Dempsey uses a similar notation), but in my experience it can help eliminate confusion.
Data models are tools used in analysis to describe the data requirements and assumptions
in the system from a top-down perspective. They also set the stage for the design of
databases later on in the SDLC.
There are three basic elements in ER models:
• Entities are the "things" about which we seek information.
• Attributes are the data we collect about the entities.
• Relationships provide the structure needed to draw information from multiple
entities.
3. In a college, every student takes many courses and every course is taken by many
students
4. In a library, a member may borrow many books and there may be books which are not
borrowed by any member
5. A teacher teaches many students and a student is taught by many teachers. A teacher
conducts examination for many students and a student is examined by many teachers.
6. An extension of example-3 above is that student-grades depend upon both student and
the course. Hence it is an associative entity
7. An employee can play the role of a manager. In that sense, an employee reports to
another employee.
8. A tender is floated either for materials or services but not both.
ER Notation
There is no standard for representing data objects in ER diagrams. Each modeling
methodology uses its own notation. The original notation used by Chen is widely used in
academics texts and journals but rarely seen in either CASE tools or publications by non-
academics. Today, there are a number of notations used, among the more common are
Bachman, crow's foot, and IDEFIX.
All notational styles represent entities as rectangular boxes and relationships as lines
connecting boxes. Each style uses a special set of symbols to represent the cardinality of a
connection. The notation used in this document is from Martin. The symbols used for the basic
ER constructs are:
• entities are represented by labeled rectangles. The label is the name of the entity.
Entity names should be singular nouns.
• relationships are represented by a solid line connecting two entities. The name of the
relationship is written above the line. Relationship names should be verbs.
• attributes, when included, are listed inside the entity rectangle. Attributes which are
identifiers are underlined. Attribute names should be singular nouns.
• cardinality of many is represented by a line ending in a crow's foot. If the crow's foot
is omitted, the cardinality is one.
Relationships
The lines with symbolized ends connecting database entities represent the relationship
between two tables. Each line describe both directions of the relationship. There are four
basic relationships that can be used to describe the relationship of one table to another.
Above figure gives the E-R Diagram for Purchase Order Application.
A Customer has a one-to-many relationship with a Purchase Order because a customer
can place many orders, but a given purchase order can be placed by only one customer.
The relationship is optional because zero customers might place a given order (it might
be placed by someone not previously defined as a customer).
A Purchase Order has a many-to-many relationship with a Stock Item because a
purchase order can refer to many stock items, and a stock item can be referred to by many
purchase orders. However, you do not know which purchase orders refer to which stock
items.
Therefore, you introduce the notion of a Line Item. A Purchase Order has a one-to-
many relationship with a Line Item because a purchase order can list many line items,
but a given line item can be listed by only one purchase order.
A LineItem has a many-to-one relationship with a StockItem because a line item can
refer to only one stock item, but a given stock item can be referred to by many line items.
The relationship is optional because zero line items might refer to a given stock item.
Example 2 :Take a simple manufacturing system. Here, we can have many entity sets.
Let us limit the list to only six entity-sets, namely, Worker, Department, Project, Buy-
order, Product, and Supplier. Below given is a sample E-R diagram drawn using
Microsoft Visio software.
Department
Dept_Code
Dept_Name
College_Code
(FK)
Emp_ID
(FK)
Student Exercises: Go through the following examples and draw the E-R diagrams.
Example 1
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.
Example 2
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.
Example 3
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.
Example 4
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).
Example 5
A relational database is to be designed for a medium sized Company dealing with
industrial applications of computers. The Company delivers various products to its
customers ranging from a single application program through to complete installation of
hardware with customized software. The Company employs various experts, consultants
and supporting staff. All personnel are employed on long-term basis, i.e. there are no
short-term or temporary staff. Although the Company is somehow structured for
administrative purposes (that is, it is divided into departments headed by department
managers) all projects are carried out in an inter-disciplinary way. For each project a
project team is selected, grouping employees from different departments, and a Project
Manager (also an employee of the Company) is appointed who is entirely and exclusively
responsible for the control of the project, quite independently of the Company's hierarchy.
The following is a brief statement of some facts and policies adopted by the Company.