Professional Documents
Culture Documents
Design 1
Database Design
• The main objectives of database design are to produce
- logical model and
- physical model
according to a database model.
• The logical model concentrates on the required data to
be stored independently with how the data will be stored
or where it will be stored physically.
• The physical model involves translating the logical model
of the database onto physical media using hardware
resources and software systems such as database 2
management systems (DBMS).
Database Design Process
DBMS independent
Data
Requirements
Database Implementation 3
What is a Database?
• General definition
A database (DB) is any collection of related data.
• Restrictive definition
A DB is a logically coherent collection of data with some inherent
meaning relevant to some aspects of the real world.
Hierarchical DBMS
Network DBMS
8
Object-oriented DBMS
Relational DBMS (RDBMS)
• In a relational database, all data are organized in the form
of tables (rows, columns).
• The RDBMS model emerged in the 1970s and has become by
far the most widely used type of DBMS due to its simplicity.
Consistency of data
9
Examples of RDBMS
• Oracle : Developed by Oracle corporation. It is a relational
DBMS (object relational for its latest versions). Oracle is
regarded to be one of the safe DBMS and is largely used by
professionals.
12
Other types of DBs/DBMS (3/4)
Object-oriented DBMS : supports the modeling and creation of
data as objects.
• There is currently no widely agreed-upon standard for what
constitutes an ODBMS and no standard query language to
ODBMS.
• They still need to be refined to achieve greater
standardization.
13
Other types of DBs/DBMS(4/4)
• Non-Relational DBMS (No-SQL DBMS): Next Generation
Databases increasingly used in big data and real-time
web applications.
14
Relational Database Design Process
15
Relational Database Design Process
DBMS independent
Data
Requirements
Relational schemas
DBMS File organization and access path,
Physical Database Design based on the options offered by the
RDBMS
Relational Database 16
Implementation
Objective of logical design (1/2)
• Translate the conceptual model (E-R or Class diagram)
into a logical model that can be implemented on a chosen
DBMS.
Mapping
Class diagram
18
Relational Data Model
Database Design Process Example
Conceptual model
Logical model
19
Physical model
Data Models
• A data model is a collection of concepts for describing data.
• Each DBMS implements a certain data model.
• A schema is a description of a particular collection of data, using a
given data model.
• The Relational model of data is the most widely used model today.
Main concept: relation, basically a table with rows and
columns.
21
How about relationships?
• Relational modeling uses primary keys and foreign keys to maintain
relationships defined in conceptual diagrams (E-A / class diagrams).
• Primary keys (PK) are typically used to identify uniquely each relation.
R1 (PKR1, att1, att2, attn)
• Foreign keys (FK) are the primary key of another relation to which a class
has a relationship.
R2 (PKR2, att1, att2, attn, #FKR1)
We say that the foreign key FKR1 references the primary key PKR1 of
R1
• Keys may be :
‐ Simple : made of one attribute (PK= att1). 22
‐ Composite : made of more than one attribute (PK= att1, att2, …).
Simple vs composite key (1/2)
• Table Employee
24
• lastname, firstname can be considered as primary key only if we
are sure that we never have the same values over all tuples.
Relations : Some rules...
• Every relation has a unique name.
Mapping rules
26
Rule 1 : Mapping Classes
• Each class is represented by a relation
CUSTOMER : a class
CUSTOMER : a relation
PK
PK
Rule 2 : Mapping One-to-Many relationships
• primary key on the one side becomes a foreign key on the many side.
CUSTOMER
Customer ID PK
Customer Name
Customer Address
1 Mapping
submits
0..*
ORDER
FK
Order ID
ORDER date
Relational schema 28
CUSTOMER (Customer_ID, Customer_Name, Customer_Address)
ORDER (Order_ID, Order_date, #Customer_ID)
Exercise
• Determine the relational schema of the Car Rental database
from the following class diagram.
29
Exercise (solution)
• Determine the relational schema of the Car Rental database
from the following class diagram.
Employee
Employee ID
Employee Name
Employee Address Mapping
*
assigned
1..*
Task
Task ID Relational schema
Description
Task (Task_ID, Description) 31
Employee (Employee_ID, Employee_Name, Employee_Adress)
Assigned_Task (#Task_ID, #Employee_ID)
Exercise
• Determine the relational schema for teachers and courses
database from the following class diagram
32
Exercise (solution)
• Determine the relational schema for teachers and courses
database from the following class diagram
Company Employee
0..1 Employes 1..*
Company ID Employee ID Mapping
Company Name Employee Name
Employee Address
WorksFor
Salary
Relational schema 34
Employee (Employee_ID, Employee_Name, Employee_Adress, #Company_ID, Salary)
Company (Company_ID, Company Name)
Rule 4 : Mapping Association Class relationships
2. Association Class : Many-to-Many
• We create a relation for the association class with the primary keys of the
two relations as foreign keys and its own attributes.
• its primary key is composed by the two foreign keys.
ORDER_Line
Quantity
Relational schema
ORDER (Order_ID, Order_date) 35
PRODUCT (Product_ID, Unit_Price)
ORDER_LINE (#Order_ID, #Product_ID, Quantity)
Exercise
• Determine the relational schema for teachers and courses
database from the following class diagram
36
Exercise (solution)
• Determine the relational schema for teachers and courses
database from the following class diagram
1..* *
Employee
Employee
Employee ID
Employee ID Employee Name
Employee Name Employee Address
Employee Address
Rule 2 Rule 3
Relational schema
Relational schema 38
Team (Team_ID, Team Name)
Team (Team_ID, Team Name)
Employee (Employee_ID, …)
Employee (Employee_ID, … , #Team_ID)
Team_Employee(#Team_ID, #Employee_ID)
Rule 6 : Mapping Composition relationships
• The composition relationships are mapped as One-to-many relationships.
• The primary key of the composite relation is then added as a foreign key to
the part relation.
• The primary key of the part relation is thus a composite key.
Company Department
*
Company ID Dept ID
Company Name Dept Name
Relational schema
Company (Company_ID, Company Name)
Department (Dept_ID, #Company_ID, Dept Name) 39
Rule 7 : Mapping One-to-One relationships (1/4)
40
Rule 7 : Mapping One-to-One relationships (2/4)
41
Exercise
• Determine the relational schema of the following relationship
Employee Position
1..1 holds 1..1
Employee ID Position ID
Employee Name Position title
Employee Address
42
Exercise (Solution)
• Determine the relational schema of the following relationship
Employee Position
1..1 holds 1..1
Employee ID Position ID
Employee Name Position title
Employee Address
Employee Department
1..1 Manages 0..1
Employee ID Dept ID
Employee Name Dept Name
Employee Address
45
Exercise (Solution)
• Determine the relational schema of the following relationship
Employee Department
1..1 Manages 0..1
Employee ID Dept ID
Employee Name Dept Name
Employee Address
Customer Car
0..1 rents 0..1
Customer ID Car ID
Customer Name Car Description
Customer Address
48
Exercise (Solution)
• Determine the relational schema of the following relationship
Customer Car
0..1 rents 0..1
Customer ID Car ID
Customer Name Car Description
Customer Address
52
Exercise (Solution)
Relational schema
53
Relational schema : graphical representation
54
Mapping Inheritance relationship
• Consider a superclass Person having two subclasses
(child/concrete) classes Customer and Employee.
• Common attributes Person ID and name are represented in the
superclass Person.
• The subclass Customer has one specific attribute preferences
• The subclass Employee has one specific attribute salary
Mapping
2 relations
56
• Customer(Customer ID, Name, Preferences)
• Employee(Employee ID, Name, Salary)
2. Map Each Class To Its Own Relation
• With this approach a relation is created for each class
(superclass and subclasses).
• Each relation includes both the attributes of the subclass and
the inherited key attribute from the superclass Person.
Mapping
3 relations
• Person (Person ID, Name) 57
• Customer(#Person ID, Preferences)
• Employee(#Person ID, Salary)
3. Map Hierarchy To A Single Relation
• With this approach only the superclass Person is represented
by a relation.
• The specific attributes of each subclass are represented in the
relation mapping the super class Person.
• A new attribute PersonType is added in the relation Person
indicating whether the Person is a customer, an employee, or
perhaps other type.
Mapping
C : Customer
E : Employee
O : Other
58
1 relation
• Person (Person ID, PersonType:{C,E,O}, Name, Preferences, Salary)
Mapping Inheritance relationship
• As there are three solutions for mapping inheritance into a
relational database,
How to decide
which solution
consider?
59
Elements of choice (1/3)
1st solution : Map Each Subclass To Its Own Relation
• In particular it works if the superclass is defined as abstract
or all the instances of the superclass are represented by
the subclasses.
An abstract class is a non-instantiable class. It expresses
an abstract generalization, which does not match any
existing object in the world. its name is shown in italics
60
Elements of choice (2/3)
2nd solution : Map Each Class To Its Own Relation
• This solution is appropriate when some instances of the
superclass may exist and are not represented by any of the
subclasses. Or also if some other instances may belong to
different subclasses in the same time.
Relational schema
• COURSE (CourseID, Course_Name)
• SUBJECT (Subject_Code, Subject_Name,#Tcode)
• COURSE_SUBJECT (#CourseID, #Subject_Code, Subject_Type)
63
• Teacher (T_Code, Fname, Lname, Ext)
• OFFERING(OfferingID, StartDate, EndDate,#Subject_Code)
Relational schema : graphical representation
64