DB 01
DB 01
Introduction to modelling
Mohamad AOUDE
17 novembre 2024
• Student
• Course
• Department
Attributes :
Characteristics of an entity of interest.
Relationships :
• A student can enroll in one or more courses.
Identifiers :
A special attribute used to identify a specific instance of an entity
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.
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.
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.
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.
1. Entities
2. Attributes
3. Identifiers
1. Relationships
2. Name
3. Cardinality (One, Many)
4. Participation (Mandatory, Optional)
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
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.
One-to-Many Many-to-Many
Author (1) – writes –>Book (*) Actor (M) – stars in –>Movie (N)
One-to-Many Many-to-Many
Author (1) –*– Book Actor –*– Movie
Chen’s Notation
UML Notation
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.
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.
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.
Conclusion :
• Logical Entity-Relationship Diagrams (ERDs) provide detailed information for
database implementation.
• They include entity attributes, data types, and constraints.
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
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.
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.
Primary Keys :
• A primary key is a unique identifier for an entity. It cannot be null.
Example of a primary key :
• Author ID
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.
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.
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).
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 (*)
• 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)
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.