Академический Документы
Профессиональный Документы
Культура Документы
Diagram
A complete guide to design ER Diagrams
19-Dec-14
Contents / Agenda
Definition
Basic Components
ERD Representations
Chens Notation Symbols
Crows foot Notation Symbols
UML Notation Symbols
Type of Entities
Types of Attributes
How to solve multivalued attributes
Types of Relationships
Implementation of 1:1
Implementation of 1:M
Implementation of M:M
Definition
The Relational Database Model (ERM-database
containing tables) forms on the basis of an ERD. The
ERD represents the conceptual database as viewed by
the end user.
ERDs depict the databases main components: entities,
attributes, and relationships. Because an entity
represents a real-world object, the words entity and
object are often used interchangeably. Thus, the entities
(objects) of the Tiny College database design (mostly
discussed in these slides) include students, classes,
teachers and classrooms.
19-Dec-14
Attributes:
Attributes are characteristics of entities. For example, the STUDENT entity includes, among many others, the attributes
STU_LNAME, STU_FNAME, and STU_INITIAL. In the original Chen notation, attributes are represented by ovals and are
connected to the entity rectangle with a line. Each oval contains the name of the attribute it represents.
In the Crows Foot notation, the attributes are written in the attribute box below the entity rectangle. Because the
Chen representation is rather space-consuming, software vendors have adopted the Crows Foot style attribute display.
Relationships:
A relationship is an association between entities. The entities that participate in a relationship are also known as
participants, and each relationship is identified by a name that describes the relationship. The relationship name is an
active or passive verb; for example, a STUDENT takes a CLASS, a PROFESSOR teaches a CLASS and an AIRCRAFT is
flown by a CREW.
Relationships between entities always operate in both directions. That is, to define the relationship between the
entities named CUSTOMER and INVOICE, you would specify that:
1. A CUSTOMER may generate many INVOICEs.
2. Each INVOICE is generated by one CUSTOMER.
19-Dec-14
ERD Representations
There are three main notations to represent and ERD
1. The Chen notation favors conceptual modeling.
2. The Crows Foot notation favors a more implementationoriented approach.
3. The UML notation can be used for both conceptual and
implementation modeling.
19-Dec-14
19-Dec-14
19-Dec-14
Usage:
1. An ERD leads to ERM, means when ever you need to build a
database with tables, firstly, you need to create an ERD.
2. Crows foot notation is used most of all because its easy to
point of view.
19-Dec-14 understand in implementation
Mudasir Qazi - mudasirqazi00@gmail.com
Types of Entities
Existence Dependent
An entity is said to be existence-dependent if it can exist in the
database only when it is associated with another related entity
occurrence. In implementation terms, an entity is existencedependent if it has a mandatory foreign keythat is, a foreign key
attribute that cannot be null.
Existence Independent.
If an entity can exist apart from one or more related entities, it is
said to be existence-independent (Sometimes designers refer to
such an entity as a strong or regular entity). Here foreign key
attribute can be null.
19-Dec-14
10
Optional
An optional attribute is an attribute that does not require a value; therefore, it can be left
empty.
Domains
Attributes have a domain, a domain is the set of possible values for a given attribute. For
example, the domain for the grade point average (GPA) attribute is written (0,4) because the
lowest possible GPA value is 0 and the highest possible value is 4. The domain for the gender
attribute consists of only two possibilities: M or F (or some other equivalent code).
Identifiers
The ERM uses identifiers, that is, one or more attributes that uniquely identify each entity
instance. In the relational model, such identifiers are mapped to primary keys (PKs) in tables.
There are Simple(Primary Key) and Composite (Composite Key) identifiers.
19-Dec-14
11
Simple
A simple attribute is an attribute that cannot be subdivided. For example, age, sex, and marital status would be
classified as simple attributes.
Single-Valued
A single-valued attribute is an attribute that can have only a single value. For example, a person can have only one
Social Security number, and a manufactured part can have only one serial number. Keep in mind that a single-valued
attribute is not necessarily a simple attribute. For instance, a parts serial number, such as SE-08-02-189935, is singlevalued, but it is a composite attribute because it can be subdivided into the region in which the part was produced
(SE), the plant within that region (08), the shift within the plant (02), and the part number (189935).
Multi-Valued
Multivalued attributes are attributes that can have many values. For instance, a person may have several college
degrees, and a household may have several different phones, each with its own number. Similarly, a cars color may
be subdivided into many colors (that is, colors for the roof, body, and trim).
Derived
A derived attribute is an attribute whose value is calculated (derived) from other attributes. The derived attribute
need not be physically stored within the database; instead, it can be derived by using an algorithm. For
example, an employees age, EMP_AGE, may be found by computing the integer value of the difference between the
current date and the EMP_DOB.
19-Dec-14
12
13
Solution 2: (Best)
Solution to Multi-Valued
attribute by adding new
entity with 1:M relation to
CAR entity.
19-Dec-14
14
Relationships
Ways of Classifying Relationships Types
A relationship type can be classified by thenumber of entity types involved, and by
thedegreeof the relationship type.
Following is a brief picture showing all types of relationships.
19-Dec-14
15
One-to-Many
When one participant can have multiple instances of other participants but other
participant can have only one instance of first participants. (mostly used and stable).
For Example, CUSTOMER may generate many ORDERs but each ORDER is generated
by one CUSTOMER. This is 1:M relation between CUSTOMER and ORDER.
Many-to-Many
When both participants can have multiple instances of each other. (not practice).
For Example, STUDENT can be enrolled in many SUBJECTs and one SUBJECT can be
chosen by many STUDENTs. This is M:M relation between STUDENT and SUBJECT.
19-Dec-14
16
Strong relationship
Also known as an identifying relationship, exists when the PK of the related entity
contains a PK component of the parent entity (implemented in left picture).
Recursive relationship
A recursive relationship is one in which a relationship can exist between occurrences of
the same entity set (Naturally, such a condition is found within a unary relationship).
19-Dec-14
17
certificate. We assume that everyone has one and that a certificate registers the
birth of one person only.
Where there is a one-one relationship type we have the option of merging the
two entity types. The birth certificate attributes may be considered as attributes
of the person and placed in the person entity type. The birth certificate entity
type would then be removed.
There are two reasons for not merging them:
1. The majority of processing involving PERSON records might not involve any or many of
the BIRTH_CERTIFICATE attributes. The BIRTH_CERTIFICATE attributes might only be
subject to very specific processes which are rarely executed.
2. the BIRTH_CERTIFICATE entity type has relationship types to other entity types that the
PERSON entity type does not have. The two entity types have different relationship types
to other entity types.
Merging is not very harmful practically. so, its just a matter of choice which
implementation you want.
19-Dec-14
18
19-Dec-14
19
19-Dec-14
20
Relationships (M:N)
Implementation (1)
Consider the EMPLOYEE and PROJECT tables. The business rule is as
follows: One employee can be assigned to multiple projects, and one
project can be supported by multiple employees. Therefore, it is
necessary to create an M:M relationship to link these two tables.
In the relational database we dont implement the M:N relation by just
giving FKs to each other and the reason is we dont want two sided
links (circles). So, we create a new entity called Bridge Entity and its
PK is a composite key made up with PKs of both tables. It may or may
not have any other attributes but composite key is must.
After doing this, there becomes two 1:M relations.
1. One between Bridge and EMPLOYEE table (1:M).
2. One between Bridge and PROJECT table (1:M).
19-Dec-14
21
Relationships (M:N)
Implementation (2)
In this example we made Bridge
Table under name
EMPLOYEE_PROJECT containing
PKs of both above tables. It has
one more attribute for some
extra information.
Now, it becomes like this and
we have three tables now.
19-Dec-14
22
Ternary
Relation
19-Dec-14
23
Cardinalities:
Cardinality expresses the minimum and maximum number of entity
occurrences associated with one occurrence of the related entity. In the ERD,
cardinality is indicated by placing the appropriate numbers beside the
entities, using the format (min , max).
1. Cardinality / mandatory:
maximum cardinality.
2. Modality / optional:
Picture says, one PROFESSOR can teach
minimum cardinality or optionality.
one (min 1) or more (max 4) CLASSes but
each single (min 1) CLASS can be taught
by one (max 1) PROFESSOR at time.
19-Dec-14
24
Summary
Following are main steps to create an ERD
1. Decide what are the entitles in your database.
2. Decide attributes for each entity.
3. Describe relationships between entities.
1. If there is any M:N relation, solve it into 1:M relationships.
25