0% found this document useful (0 votes)
9 views65 pages

DB 01

The document provides an introduction to the Entity-Relationship Model (ERM) and its significance in designing relational databases. It covers key components such as entities, attributes, and relationships, as well as various notations used to represent ER diagrams. Additionally, it discusses the advantages of relational database design and the process of creating ER diagrams to communicate data structures effectively.

Uploaded by

komeil0serhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views65 pages

DB 01

The document provides an introduction to the Entity-Relationship Model (ERM) and its significance in designing relational databases. It covers key components such as entities, attributes, and relationships, as well as various notations used to represent ER diagrams. Additionally, it discusses the advantages of relational database design and the process of creating ER diagrams to communicate data structures effectively.

Uploaded by

komeil0serhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Database

Introduction to modelling
Mohamad AOUDE
17 novembre 2024

Mohamad AOUDE 1/63


Table of contents
Placeholder

Mohamad AOUDE 2/63


Slide 1 : Entity-Relationship Model
Placeholder

What is the Entity-Relationship Model (ERM) ?


• ERM is a conceptual data model that describes the data structure of a problem
domain in terms of entities and relationships.
• ERM is used to design relational databases.

Mohamad AOUDE 3/63


Slide 2 : Why ERM is Important
Placeholder

ERM is important because it helps us to :


• Better understand the data requirements of our application.
• Design a database that is efficient and easy to maintain.
• Communicate our database design to others.

Mohamad AOUDE 4/63


Slide 3 : Example of an ERM
Placeholder
Consider a college database. The following ERM describes the data structure of this
database :
Entities :
The identifiable abstract object of interest (in Programming, we call Class)

• Student

• Course
• Department

Attributes :
Characteristics of an entity of interest.

• Students : FirstName, StudentID, Major.

• Employees : ID, SSN, ContactInfo, Department, Supervisor.


Mohamad AOUDE 5/63
Slide 3 : Example of an ERM
Placeholder

Relationships :
• A student can enroll in one or more courses.

• A course can be taught by one or more professors.

• A professor works for one department.

Identifiers :
A special attribute used to identify a specific instance of an entity

• May be natural (your DBMS doesn’t need to create it) : SSN


• May be artificial (your DBMS needs to create it) : EmployeeID

• Students : FirstName, StudentID, Major.

• Employees : ID, SSN, ContactInfo, Department, Supervisor.


Mohamad AOUDE 6/63
• Companies : LegalName, Location, Category, Rank.
Slide 4 : ERM Notations
Placeholder

The following are some common ERM notations :


• Entities are represented by rectangles.
• Relationships are represented by diamonds.
• Cardinality is represented by lines connecting entities and relationships.

Mohamad AOUDE 7/63


Slide 5 : ERM Model Components
Placeholder

The following are the main components of an ERM :


• Entities : Entities are the main objects in an ERM. They represent things that exist
in the real world, such as students, courses, and departments.
• Attributes : Attributes are the properties of entities. For example, the attributes of
a Student entity might include student ID, name, and major.
• Relationships : Relationships represent the associations between entities. For
example, the Enroll relationship represents the association between the Student
and Course entities.

Mohamad AOUDE 8/63


Slide 6 : Conceptual Design
Placeholder

The conceptual design is the first phase of database design. In this phase, we use an
ERM to describe the data requirements of our application without regard to any
specific database implementation.

Entities and Relationships :


Entities are things or objects in the real world with independent existence and can be
differentiated from other entities. Entities are normally nouns. Relationships are associations
between entities. They are normally verbs.

Mohamad AOUDE 9/63


Slide 7 : Advantages of Relational Database Design
Placeholder

Relational database design offers a number of advantages, including :


• Efficiency : Relational databases are efficient at storing and retrieving data.
• Flexibility : Relational databases are flexible and can be easily modified to meet
changing needs.
• Data integrity : Relational databases can help to ensure the integrity of data.

Mohamad AOUDE 10/63


Slide 8 : Summary
Placeholder

We have learned about the Entity-Relationship Model (ERM). We have seen how ERM is
used to design relational databases. We have also discussed the advantages of
relational database design.

Mohamad AOUDE 11/63


Example - Description
Placeholder

Company has several departments. Each department may have several locations.
Departments are identified by a name, D_no, and location. A manager controls a
particular department. Each department is associated with a number of projects.
Employees are identified by name, ID, address, date of birth, and date of joining. An
employee works in only one department but can work on several projects. The number
of hours worked by an employee on a single project is tracked. Each employee has
dependents. Dependents have attributes such as D_name, gender, and relationship.

Mohamad AOUDE 12/63


ER Diagram of Company
Placeholder

Entities and Attributes :


• Employee : Name, Id, Address, Gender, Dob, Doj (primary key)
• Department : D_no, Name, Location (primary key)
• Project : P_No, Name, Location (primary key)
• Dependent : D_name, Gender, Relationship

Mohamad AOUDE 13/63


Explanation of the Relationships
Placeholder

• Employees work in Departments (1 :M)


• Manager controls a Department (1 :1)
• Department has many Projects (1 :M)
• Employee works on project (M :N)
• Employee has dependents (1 :M)

Mohamad AOUDE 14/63


Relationships in the ER Diagram
Placeholder
Relationships in the ER diagram are as follows :
• Employees work in Departments : Many employees work in one department, but
one employee cannot work in many departments.
• Manager controls a Department : Employees work under the manager of the
department, and the manager records the date of joining of employees in the
department.
• Department has many Projects : One department has many projects, but one
project cannot come under many departments.
• Employee works on Project : One employee works on several projects, and the
number of hours worked by the employee on a single project is recorded.
• Employee has Dependents : Each employee has dependents, and each dependent
is dependent on only one employee.

Mohamad AOUDE 15/63


Relationships in the ER Diagram
Placeholder
The following ERD shows this database design :

Relationships
Mohamad AOUDE in the ER diagram are as follows : 16/63
Slide 9 : Implementation
Placeholder

The implementation phase is the final phase of database design. In this phase, we test,
deploy, and implement the database.

Mohamad AOUDE 17/63


Slide 10 : Entity-Relationship Model (ERM)
Placeholder

An ERM is a conceptual framework for understanding data elements and their


associations. It is based on two key components : entities and relationships.

Mohamad AOUDE 18/63


Slide 11 : Popular E-R Notations
Placeholder

There are three popular E-R notations :


1. Chen’s notation
2. Unified Modeling Language (UML) notation
3. Crow’s foot notation

Mohamad AOUDE 19/63


Design Elements — Chen ERD
Placeholder

Mohamad AOUDE 20/63


Design Elements — Crow’s Foot ERD
Placeholder

Mohamad AOUDE 21/63


ERD with Crow’s Foot
Placeholder

1. Entities
2. Attributes
3. Identifiers

Mohamad AOUDE 22/63


ERD with Crow’s Foot
Placeholder

1. Relationships
2. Name
3. Cardinality (One, Many)
4. Participation (Mandatory, Optional)

Mohamad AOUDE 23/63


ERD with Crow’s Foot
Placeholder

Mohamad AOUDE 24/63


ERD with Crow’s Foot
Placeholder
Let’s represent the simple case using Crow’s Foot notation.

Mohamad AOUDE 25/63


Slide 12 : Chen’s Notation
Placeholder

Chen’s notation is the most widely used E-R notation. It uses the following symbols :
• Rectangles to represent entities
• Ovals to represent attributes
• Diamonds to represent relationships
• Lines to connect entities and relationships
• Cardinality symbols to indicate the number of entities that can participate in a
relationship

Mohamad AOUDE 26/63


Slide 13 : UML Notation
Placeholder

UML notation is a general-purpose modeling language that can be used to model a


variety of systems, including databases. UML uses the following symbols to represent
E-R diagrams :
• Rectangles with entity names inside to represent entities
• Lines to represent relationships
• Attributes are listed within the rectangle.
• Cardinality symbols are numbers or asterisks.

Mohamad AOUDE 27/63


Slide 14 : Crow’s Foot Notation
Placeholder

Crow’s foot notation is a variation of Chen’s notation. It uses crow’s feet symbols on the
ends of relationship lines to indicate cardinality.

Mohamad AOUDE 28/63


Slide 15 : Business Rule
Placeholder

An example of a business rule is :

Business Rule Example :


One author can write multiple books, but each book is written by one author.

Mohamad AOUDE 29/63


Slide 16 : Business Rule in Each Notation
Placeholder

Notation Business Rule


Chen’s notation Author (1) – writes –>Book (*)
UML notation Author (1) –*– Book
Crow’s foot notation Author (1) –writes– Book (*)

Mohamad AOUDE 30/63


Slide 17 : Chen’s Notation
Placeholder

One-to-Many Many-to-Many
Author (1) – writes –>Book (*) Actor (M) – stars in –>Movie (N)

Mohamad AOUDE 31/63


Slide 18 : UML Notation
Placeholder

One-to-Many Many-to-Many
Author (1) –*– Book Actor –*– Movie

Mohamad AOUDE 32/63


Slide 19 : One-to-One
Placeholder

Chen’s Notation

User (1) – has –>Profile (1)

UML Notation

User –1„1– Profile

Mohamad AOUDE 33/63


Slide 20 : UML Notation Components
Placeholder

Entity A rectangle with the entity name inside.


Relationship A line connecting two entities.
Attribute A listed within the entity rectangle.
Multiplicity A notation on the relationship line indicating the number of
entities that can participate in the relationship.
Primary Key An attribute that is a unique identifier in an entity. Labeled as
PK in UML.
Foreign Key An attribute that is a primary key in another table. Labeled as
FK in UML.

Mohamad AOUDE 34/63


Slide 21 : Multiplicity
Placeholder

Participation Cardinality
Mandatory : Indicated as 1. To-one : The maximum number of ins-
tances in one entity that can relate to an
instance in the other entity is one.
Optional : Indicated as 0. To-many : The maximum number of
instances in one entity that can relate to
an instance in the other entity is many.

Mohamad AOUDE 35/63


Slide 22 : Attributes
Placeholder

Single-valued attribute A simple attribute that can have a single


value.
Composite attribute An attribute that can have a hierarchy
of attributes.
Multi-valued attribute An attribute that can have a set of va-
lues in an entity.

Mohamad AOUDE 36/63


Conclusion
Placeholder

UML notation is a powerful tool for database design. It is widely used in computing and
software engineering, and it provides details that can help to communicate the
business rules of a database.

Mohamad AOUDE 37/63


Entity Relationship Diagram
Placeholder

We represent Entity Relationship Models using ERD (Entity Relationship Diagram)


• Represent Entities (and attributes / identifiers)
• Represent Relationships (and cardinality / participation)
• Provide a high level picture of what the database is organized

Mohamad AOUDE 38/63


Slide 1 : Introduction to Entity-Relationship (ER)
Diagrams
Placeholder

What are ER Diagrams ?


• ER diagrams are graphical representations of entities, attributes, and relationships
in a database.
• They are used to design and document databases and communicate the data
structure to stakeholders.

Mohamad AOUDE 39/63


Slide 2 : Benefits of ER Diagrams
Placeholder

Benefits of ER Diagrams :
• They ensure consistent and logical database design.
• They help identify and correct errors in the design.
• They facilitate communication of the database structure to stakeholders.
• They can be used to generate the database schema.

Mohamad AOUDE 40/63


Slide 3 : Creating an ER Diagram
Placeholder

Steps for Creating an ER Diagram :


1. Identify the entities in the database (e.g., customers, products, orders).
2. Identify the attributes of each entity (e.g., customer name, product price, order
quantity).
3. Identify the relationships between the entities (e.g., a customer placing an order
for a product).
4. Draw the ER diagram using appropriate symbols.

Mohamad AOUDE 41/63


Slide 4 : Example ER Diagram
Placeholder

Example ER Diagram for a Bookstore Database :


• Customer (1,*) –places order for–>Order (*)
• Order (1) –contains–>Order Item (*)
• Order Item (1) –refers to–>Book (1)
• Book (1) –is written by–>Author (*)

Mohamad AOUDE 42/63


Slide 1 : UML Conceptual Design - City Book Library
Database
Placeholder
Entities :
• Book
• Author
• Publisher
• Member
• Library Branch
Relationships :
• A book is written by one or many authors.
• An author can write one or many books.
• A book is published by one publisher.
• A publisher can publish one or many books.
• A member can borrow one or many books from one or many library branches.
Mohamad AOUDE branch can lend one or many books to one or many members.
• A library 43/63
Slide 2 : Logical Design
Placeholder
Logical Design Components :
• The logical design of an Entity-Relationship Diagram (ERD) is more detailed than
the conceptual design.
• It includes entity attributes, data types of attributes, and constraints on attributes.
Example of a logical design :
• Entity : Book
• Attributes :
— Book ID (primary key)
— Title
— Author (foreign key)
— Publisher (foreign key)
— Publication date
— Genre
— Number of pages
Mohamad AOUDE 44/63
Slide 3 : Logical Design
Placeholder

Logical Design Components :


• Data types :
— Book ID : Integer
— Title : String
— Author : Integer
— Publisher : Integer
— Publication date : Date
— Genre : String
— Number of pages : Integer
• Constraints :
— Book ID must be unique.
— Author and Publisher foreign keys must reference valid author and publisher IDs,
respectively.

Mohamad AOUDE 45/63


Slide 4 : Conclusion
Placeholder

Conclusion :
• Logical Entity-Relationship Diagrams (ERDs) provide detailed information for
database implementation.
• They include entity attributes, data types, and constraints.

Mohamad AOUDE 46/63


Slide 1 : Author’s Contact Information
Placeholder

Entity-Relationship Diagram (ERD) :


• Author (1) –has–>ContactInfo (*)
Attributes :
• Author ID (PK)
• Name
• ContactInfo (multivalued attribute)
Multiplicity :
• Author (1) : An author can have one or more contact information.
• ContactInfo (*) : A contact information can belong to one and only one author.

Mohamad AOUDE 47/63


Slide 2 : Multivalued Attributes
Placeholder

Multivalued Attributes :
• A multivalued attribute is an attribute that can have more than one value for an
entity. It is represented with curly braces in an ERD.
Examples of multivalued attributes :
• Contact information (phone number, email address, etc.)
• Skills
• Interests
• Addresses

Mohamad AOUDE 48/63


Slide 3 : Derived Attributes
Placeholder

Derived Attributes :
• A derived attribute is an attribute that is computed from other existing attributes.
It is not included in the relation schema but can be calculated when needed.
Example of a derived attribute :
• Age : Calculated from the birth date.

Mohamad AOUDE 49/63


Slide 4 : Multiplicity
Placeholder

Multiplicity :
• Multiplicity is the number of entities that can participate in a relationship. It is
represented by two digits :
— The first digit is the minimum number of entities that can participate in the
relationship.
— The second digit is the maximum number of entities that can participate in the
relationship.
Examples of multiplicity :
• (1,1) : One-to-one relationship.
• (1,N) : One-to-many relationship.
• (M,N) : Many-to-many relationship.

Mohamad AOUDE 50/63


Slide 5 : Primary Keys
Placeholder

Primary Keys :
• A primary key is a unique identifier for an entity. It cannot be null.
Example of a primary key :
• Author ID

Mohamad AOUDE 51/63


Slide 6 : Foreign Keys
Placeholder

Foreign Keys :
• A foreign key is an attribute in a table that references the primary key in another
table. It is used to enforce referential integrity.
Example of a foreign key :
• ContactInfoID in the Author table is a foreign key that references the
ContactInfoID primary key in the ContactInfo table.

Mohamad AOUDE 52/63


Slide 7 : Referential Integrity
Placeholder

Referential Integrity :
• Referential integrity ensures that the foreign key in a table matches the primary
key in the referenced table.
Example :
• The ContactInfoID foreign key in the Author table ensures that every author
record references a valid contact information record.

Mohamad AOUDE 53/63


Slide 1 : College Database Conceptual Design
Placeholder

Entity-Relationship Diagram (ERD) :


• Student (1,*) –enrolls in–>ClassSection (*)
• Teacher (1,*) –teaches–>ClassSection (*)
• ClassSection (1) –is assigned to–>Room (1)
• Course (1,*) –is taught by–>Teacher (*)
• Course (1,*) –is enrolled in by–>Student (*)

Mohamad AOUDE 54/63


Slide 2 : UML Conceptual Design - College Database
Placeholder
Entities :
• Student
• Class Section
• Room
• Teacher
• Course
Relationships :
• One student enrolls in one or many class sections.
• One class section is assigned to a specific room.
• One professor may teach zero or many class sections.
• One class section must be taught by one professor.
• A course has one or many class sections.
• One class section belongs to a specific course.
Mohamad AOUDE 55/63
Mohamad AOUDE 56/63
Slide 1 : Example : Banking Database Business Rules
Placeholder
Customer
• Attributes :
— Customer ID (primary key)
— Name
— Address
— Phone number
• Multiplicity :
— A customer can have at least two accounts.
Account
• Attributes :
— Account ID (primary key)
— Customer ID (foreign key)
— Type (e.g., savings, checking)
— Balance
• Multiplicity :
Mohamad
—AOUDE
An account can belong to only one customer. 57/63
Slide 2 : Explanation
Placeholder

Explanation :
• The banking database business rules describe the relationships between the
different entities in the database.
• For example, the rule "A customer can have at least two accounts" implies a
many-to-one relationship between Customer and Account entities.
• Identifiers are used to uniquely identify records in each entity (e.g., Customer ID
for customers).

Mohamad AOUDE 58/63


Slide 3 : Example ER Diagram
Placeholder

Example ER Diagram :
• Customer (1,*) –has–>Account (*)
• Account (1) –belongs to–>Customer (1)
• Transaction (1) –is associated with–>Account (1)
• Account (1) –may have several–>Transaction (*)
• Branch (1) –makes–>Transaction (*)
• Transaction (1) –is made at–>Branch (1)
• Employee (1) –works at–>Branch (1)
• Branch (1) –employs–>Employee (*)

Mohamad AOUDE 59/63


Mohamad AOUDE 59/63
Mohamad AOUDE 59/63
Slide 1 : Business Rules Represented in the
CustomerOrder ERD
Placeholder

• One customer can place multiple orders. (1 :M cardinality between Customer and
Order)
• Each order is associated with only one customer. (M :1 cardinality between Order
and Customer)
• Customer stores CustomerID, name of customer, Phone, and email as attributes.
(Customer entity attributes)
• Order has OrderID, date of order, and total amount as attributes. (Order entity
attributes)
• Each order can include multiple products, and each product can be part of
multiple orders. (M :N cardinality between Order and Product)
• Product has ProductID, name of product, and price. (Product entity attributes)
• Each product belongs to a specific category, and a category can have multiple
products.
Mohamad AOUDE (1 :M cardinality between Product and Category) 60/63
Slide 2 : Inferred Business Rules from the
CustomerOrder ERD
Placeholder

• Each customer must have a unique CustomerID. (Customer entity primary key)
• Each order must have a unique OrderID. (Order entity primary key)
• Each product must have a unique ProductID. (Product entity primary key)
• Each category must have a unique CategoryID. (Category entity primary key)
• The CustomerID attribute in the Order entity is a foreign key that references the
CustomerID primary key in the Customer entity. This ensures that each order is
associated with a valid customer.
• The ProductID attribute in the Order entity is a foreign key that references the
ProductID primary key in the Product entity. This ensures that each order contains
valid products.
• The ProductID attribute in the Product entity is a foreign key that references the
CategoryID primary key in the Category entity. This ensures that each product
belongs
Mohamad AOUDEto a valid category. 61/63
Reduction to Relation Schemas
Placeholder

Once the ER diagram is created, it can be converted into a relational schema, which is a
set of tables with appropriate attributes and foreign key relationships, to implement
the database in a relational database system. The schemas below use the ER diagrams
from earlier in this lesson.
• Translate ERD for banking database in relation schemas :
• Customer (CustomerID, CustomerName, Address, Phone)
• Account (AccountNo, AccountType, Balance, CustomerID)
• Transaction (TransID, Date, Amount, AccountNo, BranchID)
• Branch (BranchID, BranchName, Location)
• Employee (EmployeeID, EmployeeName, Position, BranchID)

Mohamad AOUDE 62/63


Slide 3 : Conclusion
Placeholder

Conclusion :
• ER diagrams and cardinality constraints are valuable tools for database design.
• Understanding the business rules represented in the ERD and the cardinality
constraints between the different entities ensures that the database is designed
to meet user needs.
• The CustomerOrder ERD serves as a conceptual model, and further details can be
added for implementation.

Mohamad AOUDE 63/63

You might also like