ERD Manynotation
ERD Manynotation
Contents
• Conceptual, logical and physical data models
• What is an ER diagram?
• History of ER models
• Uses of entity relationship diagrams
• Mapping natural language
• The components and features of an ER diagram
• Entity Relationship Diagram Tutorial
• Create ERD from existing database.
• Different Types of Keys in DBMS
• ERD symbols on several notation styles
• ERD Examples
Learn the essentials of ER Diagrams and ER Models, along with their origins, uses, examples, components, limitations and guidelines on
how to draw them using our ER diagram tool.
• Conceptual data model: The highest-level view containing the least detail. Its value is showing overall scope of the model and
portraying the system architecture. For a system of smaller scope, it may not be necessary to draw. Instead, start with the logical
model.
• Logical data model: Contains more detail than a conceptual model. More detailed operational and transactional entities are now
defined. The logical model is independent of the technology in which it will be implemented.
• Physical data model: One or more physical model may be developed from each logical model. The physical models must show
enough technology detail to produce and implement the actual database.
Sometimes, engineers will branch out ER diagrams with additional hierarchies to add necessary information levels for database design. For
example, they may add groupings by extend up with superclasses and down with subclasses. It is Extended ERD.
ER diagrams are related to data structure diagrams (DSDs), which focus on the relationships of elements within entities instead of
relationships between entities themselves. ER diagrams also are often used in conjunction with data flow diagrams (DFDs), which map out
the flow of information for processes or systems.
Diagramming is quick and easy with Lucidchart, draw.io, smartdraw.com. It's quick, easy, and completely free.
Peter Chen (a.k.a. Peter Pin-Shan Chen), currently a faculty member at Carnegie-Mellon University in Pittsburgh,
is credited with developing ER modeling for database design in the 1970s. While serving as an assistant professor
at MIT’s Sloan School of Management, he published a seminal paper in 1976 titled “The Entity-Relationship
Model: Toward a Unified View of Data.”
In a broader sense, the depiction of the interconnectedness of things dates back to least ancient Greece, with the
works of Aristotle, Socrates and Plato. It’s seen more recently in the 19th and 20th Century works of philosopher-
logicians like Charles Sanders Peirce and Gottlob Frege.
By the 1960s and 1970s, Charles Bachman (above) and A.P.G. Brown were working with close predecessors of
Chen’s approach. Bachman developed a type of Data Structure Diagram, named after him as the Bachman
Diagram. Brown published works on real-world systems modeling.
The database query language ERROL (Entity Relationship Role Oriented Language - Victor M. Markowitz, Yoav R,
1983) actually mimics natural language constructs. ERROL is based on reshaped relational algebra (RRA) and works
with ER models, capturing their linguistic aspects.
Entity
A definable thing - such as a person, object, concept or event - that can have data stored about it. Think of entities as nouns. Examples: a
customer, student, car or product.
Organisations require information in order to carry out the tasks and activities for which they are responsible. The information that these
organisations need could be categorised in a number of ways, for example:
People Things Locations Events Concepts
• Payroll • Furniture • Offices • Sale is made • Image of product
• Pensions • Equipment • Warehouses • Purchase order is • Advertising
raised
• Annual leave • Stationery • Stock rooms • Marketing
• Item is hired
• Sick leave • Fire extinguishers • Research and
• Invoice is issued development.
Entity set: Same as an entity type, but defined at a particular point in time, such as students enrolled in a class on the first day. Other examples:
Customers who purchased last month, cars currently registered in Florida. A related term is instance, in which the specific person or car would
be an instance of the entity set.
Entity categories: Entities are categorized as strong, weak or associative. A strong entity can be defined solely by its own attributes, while a
weak entity cannot. An associative entity associates entities (or elements) within an entity set.
SHOULD BE:
• The actor ”Bruce Willis” should not be an entity type - there is only one instance.
• ”Middle-aged actors” is not an entity type - could be a query
• Year is not an entity because it does not have multiple attributes (that we want to model, anyway)
• The title of a film is not an entity type, unless we want to associate more info with each title (like relationships among movies with that
title)
© Yuriy Shamshin 7/46
Identifiers
Entity keys (identifiers): Refers to an attribute that uniquely defines an entity in an entity set. Entity keys can be super, candidate or primary.
• Super key: A set of attributes (one or more) that together define an entity in an entity set.
• Candidate key: A minimal super key, meaning it has the least possible number of attributes to still be a super key. An entity set may
have more than one candidate key.
• Primary key: A candidate key chosen by the database designer to uniquely identify the entity set.
• Foreign key: Identifies the relationship between different entities. When a copy of the primary key for one entity is included in the
collection of attributes of another entity, the copy of the primary key held in the second entity is known as a foreign key.
mysql> INSERT INTO Student VALUES ('12345-6789', 'Bill Gades', 'No Way 8');
1 row inserted.
mysql> INSERT INTO Student VALUES ('12345-6789', 'Bill Gades', 'No Way 8');
ERROR at line 1:
INSERT INTO Student VALUES ('12345-6789', 'Bill Gades', 'No Way 8');
#1062 - Duplicate entry '12345-6789' for key 'PRIMARY'
mysql> INSERT INTO Student VALUES ('12345-6789', 'Bill Gades', 'No Way 8');
ERROR at line 1:
INSERT INTO Student VALUES (NULL,’Don Pedro’,’No Way 8’)
#1048 - Column 'sid' cannot be null
If we want the DBMS to check other uniqueness constraints, we may add to the SQL relation schema any number of lines of the form:
Uniqueness is not guaranteed for tuples having NULL values in the key attributes. However, NULL values can be prevented by adding a NOT
NULL constraint after the declaration of each key attribute.
Relationships are typically shown as diamonds or labels directly on the connecting lines.
1. Unary Relationship
When there is only ONE entity set participating in a relation, the relationship is called as unary relationship. For example, one person is
married to only one person.
Many-to-many
2. Binary Relationship
When there are TWO entities set participating in a relation, the relationship is called as binary relationship.For example, Student is
enrolled in Course.
4. n-ary Relationship
When there are n entities set participating in a relation, the relationship is called as n-ary relationship.
Multiple relationship
Entities can be related to one another in more than one way
Here, the date completed attribute pertains specifically to the employee’s completion of a course.
A one-to-one example: would be one student associated with one login name.
A one-to-many example (or many-to-one, depending on the relationship direction): One product line contains multiple products.
Many-to-many example: Students as a group are associated with multiple faculty members (teachers), and faculty members (teachers) in
turn are associated with multiple students.
Cardinality views: Cardinality can be shown as look-across or same-side, depending on where the symbols are shown.
Cardinality constraints and obligated (or participation constraint): The minimum or maximum numbers that apply to a relationship.
Identifying relationship
• links strong entity type to weak entity type
• represented with double line diamond
Associative Entities
• It’s an entity type – it has attributes, identifier.
• AND it’s a relationship – it links entities together.
• Should be seen as a way of visualizing the above, but: Behaves in all ways just like an entity type.
Values:
Entity: Book
Attributes:
Values:
Entity: Employee
Attributes:
Values:
A null is a special symbol, independent of data type, which means either unknown or inapplicable. It does not mean zero or blank. Features of
null include:
• No data entry
• Not permitted in the primary key
• Should be avoided in other attributes
• Can represent
o An unknown attribute value
o A known, but missing, attribute value
o A “not applicable” condition
• Can create problems when functions such as COUNT, AVERAGE and SUM are used
• Can create logical problems when relational tables are linked
NOTE: The result of a comparison operation is null when either argument is null. The result of an arithmetic operation is null when either
argument is null (except functions that ignore nulls).
1. Purpose and scope: Define the purpose and scope of what you’re analyzing or modeling. Add a description of your Subject Area.
Document any assumptions and restrictions then you make. Show the level of detail necessary for your purpose. You might want to
draw a conceptual, logical or physical model, depending on the detail needed. (See above for descriptions of those levels.)
2. Entities: Identify the entities that are involved. Identify all of the entities you will use. An entity is a description of something that your
system stores information about. This could be a customer, a manager, an invoice, a schedule, etc. Draw a rectangle (or your system’s
choice of shape) for each entity you can think of on your page and labeling them as nouns. Keep them spaced out a bit.
3. Relationships: Determine how the entities are all related. Look at two entities, are they related? If so draw a solid line connecting the
two entities and label them. Some entities may not be related, and that’s fine. In different notation systems, the relationship could be
labeled in a diamond, another rectangle or directly on top of the connecting line. How are the entities related? Write a brief description
of how they are related. Each of your entities may not have any relationships, some may have multiple relationships. That is okay.
4. Cardinality: Show whether 1-1, 1-many or many-to-many.
5. Obligated (or participation): Show whether the relationship is mandatory or optional.
6. Attributes: Layer in more detail by adding attributes of entities. Attributes are often shown as ovals. Any key attributes of entities should
be added.
7. Analyze and complete the diagram: Execute the tips for effective ER diagrams:
a) Make sure the ER diagram supports all the data you need to store.
b) Make sure all your entities and relationships and attribute are labeled on your diagram.
c) Make sure that each entity only appears once per diagram. Eliminate any redundant entities.
d) Examine relationships between entities closely. Are they necessary? Are there any relationships missing? Eliminate any redundant
relationships. Don't connect relationships to each other.
e) Use colors to highlight important portions of your diagram.
f) You can transition relational tables and ER diagrams back and forth, if that helps you achieve your goal.
g) If you’re troubleshooting a database problem, watch for holes in relationships or missing entities or attributes.
2.
3.
4,5.
6.
7.
© Yuriy Shamshin 20/46
Create ERD from existing database.
There are two reasons to create a database diagram:
• designing a new schema,
• document your existing structure.
If you have an existing database you need to document, you can create a database
diagram using data directly from your database.
You can export your database structure as a CSV file, then have a program generate
the ERD automatically (for example on smartdraw.com site).
This will be the most accurate potrait of your database and will require no drawing on
your part.
Here's an example of a very basic database structure generated from data.
If you want to create a new plan, you can also edit the generated diagram and
collaborate with your team on what changes to make.
1. Super Key
• A super key is a set of attributes that can identify each tuple uniquely in the given relation.
• A super key is not restricted to have any specific number of attributes.
• Thus, a super key may consist of any number of attributes.
Given below are the examples of super keys since each set can uniquely identify each student in the Student table
Note. All the attributes in a super key are definitely sufficient to identify each tuple uniquely in the given relation but all of them may not be
necessary.
Notes.
• All the attributes in a candidate key are sufficient as well as necessary to identify each tuple uniquely.
• Removing any attribute from the candidate key fails in identifying each tuple uniquely.
• The value of candidate key must always be unique.
• The value of candidate key can never be NULL.
• It is possible to have multiple candidate keys in a relation.
• Those attributes which appears in some candidate key are called as prime attributes.
3. Primary Key
A primary key is a candidate key that the database designer selects while designing the database.
OR
Candidate key that the database designer implements is called as a primary key.
Notes.
4. Alternate Key
5. Foreign Key
• An attribute ‘X’ is called as a foreign key to some other attribute ‘Y’ when its values are dependent on the values of attribute ‘Y’.
• The attribute ‘X’ can assume only those values which are assumed by the attribute ‘Y’.
• Here, the relation in which attribute ‘Y’ is present is called as the referenced relation.
• The relation in which attribute ‘X’ is present is called as the referencing relation.
• The attribute ‘Y’ might be present in the same table or in some other table.
Notes.
6. Partial Key
• Partial key is a key using which all the records of the table can not be identified uniquely.
• However, a bunch of related tuples can be selected from the table using the partial key.
E1 Egils Mother
E1 Ozols Father
E2 Darts Father
E2 Forevers Son
Here, using partial key Emp_no, we can not identify a tuple uniquely but we can select a bunch of tuples from the table.
A primary key comprising of multiple attributes and not just a single attribute is called as a composite key.
8. Unique Key
• The European Card Number is unique for all the citizens (tuples) of EU (table).
• If it gets lost and another duplicate copy is issued, then the duplicate copy always has the same number as before.
• Thus, it is non-updatable.
• Few citizens may not have got their European cards, so for them its value is NULL.
9. Surrogate Key
Surrogate key is a key with the following properties-
Example.
Mobile Number of students in a class where every student owns a mobile phone.
Secondary key is required for the indexing purpose for better and faster searching.
© Yuriy Shamshin 27/46
ERD symbols on several notation styles
There are several notation systems, which are similar but vary in a few specifics.