0% found this document useful (0 votes)
4 views

Course Rm

The document outlines the stages of database design, including analysis, conceptual modeling, logical modeling, and implementation. It explains the relational model, emphasizing concepts such as attributes, domains, tuples, relations, keys, and foreign keys. Additionally, it provides examples to illustrate these concepts and their application in database schemas.

Uploaded by

ibnbiskra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Course Rm

The document outlines the stages of database design, including analysis, conceptual modeling, logical modeling, and implementation. It explains the relational model, emphasizing concepts such as attributes, domains, tuples, relations, keys, and foreign keys. Additionally, it provides examples to illustrate these concepts and their application in database schemas.

Uploaded by

ibnbiskra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Relational Model

Modeling a database
There are four stages in designing a database:

 Analysis of the existing situation and needs

 Creation of a conceptual model that allows all


important aspects of the problem to be represented

 Translation of the conceptual model into a logical


model (and standardization of this logical model)

 Implementation of a database in a DBMS, from the


logical model (and optimization)
Modeling a database
Conceptual
Model

Logical
Model

Physical
Model
Modeling a database

Analysis: It consists of studying the problem and recording in a


document, the clarification note, the needs, the choices, the constraints.

Conceptual modeling: It makes it possible to describe the problem


posed, in a non-formal way (generally graphic), by taking simplification
hypotheses. It is not a description of reality, but a simplified
representation of a reality.

Logical modeling: It allows you to describe a solution, taking a general


IT orientation (type of DBMS typically), formal, but independently of
specific implementation choices.

Implementation: It corresponds to the technical choices, in terms of the


chosen DBMS and their implementation (programming, optimization,
etc.).
Modeling a database
Various types of conceptual models

- ER: Entity-Relation
- UML: Unified Modelling Language
Modélisation d’une base de données
Entity/Relationship Model

Entity
Property
Occurrence
Id
Relationship or association
Cardinality
Relational Model

It views schema as a set of two-dimensional tables called


relations.
Relational Model

Among its objectives:


 Increasing the independence of programs with
respect to data representation.
 Provide a solid foundation for addressing data
consistency and redundancy issues.
 Enable the development of non-procedural
data manipulation languages based on solid
theories.
Relational Model

Basic Model Concepts


Attribute
An attribute designates a property or characteristic of a relation. It is
characterized by a unique name in this relation.
Example:
Reference, Description, Color are attributes of the PRODUCT relation.

Domain
The domain of an attribute corresponds to the set of values that this
attribute can take. This set can be finite or countable or it can be
infinite.

Example:
- Domain (colors) = {Blue, Red, Green, ...}
- Domaine (Names) = {Ali, Salah, Yasmine...}
Relational Model
Cartesian product of a set of domains

The Cartesian product of a set of domains D1, D2,


D3,....., Dn which we denote D1 x D2 x D3 x ..... x Dn
is the set of n-tuples or tuples (v1, v2, v3,....., vn) such
that vi Di for all i = 1, 2, 3,....., n.
Example: Consider the following three areas:
D1=(Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi,
Dimanche)
D2= (1, 2, 3,.....31)
D3= (Janvier, Février, Mars, Avril,
Mai,....Décembre)
Le modèle relationnel
Cartesian product of a set of domains

Then the Cartesian product is

D1 x D2 x D3= {(Lundi, 1, Janvier),


(Lundi, 2, Janvier), (Lundi, 3, Janvier),
....... (Lundi, 31, Janvier), (Lundi, 1,
Février), ....... (Lundi, 31, Février),
.......
(Lundi, 31, Décembre), (Mardi, 1,
Janvier), ....... (Dimanche, 1,
Décembre), ....... (Dimanche, 31,
Décembre)
Relational Model

Relation
A relation is defined by a list of attributes A1, A2, A3,....,
An having respectively domain D1, D2, D3,....., Dn.
We note it R(A1, A2, A3,....., An) where R is the name of
the relation.
It is composed of a set of tuples (a1, a2, a3,....., an) or ai
Di i = 1, 2, 3,....., n, this set constituting a subset of
the Cartesian product: D1 x D2 x D3 x..... x Dn.
Relational Model

Tuple of a relation
A tuple of a relation simply designates a row in the table
representing this relation. An attribute would rather
designate a column in the same table.
Relational Model

Cardinality of a relation
The cardinality of a relation is the number of tuples in this
relation. The cardinality of a relation R will therefore be an
integer and is denoted:|R|.

Degree of a relation

It is the number of columns (domains) in a relation.


R D1 × D2 × ... × Dn
n is the degree of the relation,
Relational Model

Example:
Domains:
LNAME = { Zaoui, Badaoui }
FNAME = { Ali, Nora, Larbi }
BIRTHDATE = {Date between 1/1/1990 and
31/12/2020}
SPORT = { judo, tennis, foot }

Relation STUDENT
Student LNAME × FNAME × BIRTHDATE
STUDENT ={(Zaoui, Ali,1/1/1992), (Badaoui, Nora ,
2/2/1994) }
Relational Model

INSCRIPTION Relation
INSCRIPTION LNMAE × SPORT
INSCRIPTION={(Zaoui, judo),
(Zaoui, foot),(Badaoui, tennis)}
To easily visualize the content of a relation we use the tabular
representation.
Each line corresponds to a vector
Each column corresponds to a domain
Relational Model

Example
INSCRIPTION LNAME × SPORT

LNAME SPORT

Zaoui Judo

Zaoui Foot

Badoui Tennis
Relational Model

Diagram of a relation

The schema of a relation is defined by:


- the name of the relation
- the list of its attributes

We note: R (A1, A2, ... , An)

Example:

- STUDENT (LNAME, FNAME, BIRTH)


- Product (Reference, designation, color)
Relational Model

Consider relation
CATALOG_PRICE (Product_Code, Designation , Supplier ,
Price).
This relation is defined by its attributes which are:
Product_Code, Designation, Supplier and
Price.
Its name is: CATALOG_PRICE.
Relational Model

A table representation of this relation where the columns correspond


to the attributes and the rows to the tuples of the relationship would
be:

Product_Code Designation Supplier Price


P0001 Pen Ayanis 15,00
P0002 Book Manar 500,00
P0003 Papers Ayanis 450,00
P0004 Notebook Ayanis 150,00
P0005 Rule Manar 50,00
P0006 Scissor Manar 80,00
Relational Model

Schema of a database

The schema of a database is defined by:


- The set of schema of relation that compose it,
- The DB diagram shows how the data is organized in the
database.
Relational Model

Key of a relation
One of the integrity constraints of a schema is the uniqueness of
identification of the tuples of a relation. This unique identification is
ensured by the notion of relation key.
- A key can be composed of a single attribute or a list of attributes
that characterizes a tuple (tuple) of the relationship in a unique way.
- A relation can have several keys. A key with a minimum of attributes
will be chosen as the primary key, the other possible keys are called
candidate keys.
- By convention, the primary key of a relation is underlined in a
relation schema.
Relational Model

Primary key: One or more attributes of a relation


allowing tuples (records) to be completely differentiated.
That is, a primary key is one or more attributes that
uniquely identify records.

Candidate Key: One or more attributes that qualify as a


unique key in a relation.
relational schema

Relational Model

Example

Consider the following relational schema:


Person (num_per, last name, first name, email)
Book (ISBN, title)
Candidate key: num_per and email
Primary key: num_per (since email can be NULL)
And for BOOK?
Relational Model

Comparison between primary key and candidate key

Primary key Candidate key


There can be only one primary key in There can be more than one key
the entire relation in a relation
No attribute of a key can contain a The attribute of a candidate
NULL value key can have a NULL value
A primary key is a candidate key It is not mandatory that each
candidate key be a primary
key
Relational Model

The key of a relation has the following properties:

Uniqueness: it identifies a single tuple of the relation

Minimal composition: No attribute of the key can be


eliminated without destroying the uniqueness property.
Relational Model

Composite key

Another type of key is called composite key which is a


combination of two or more attributes in a table that can
be used to uniquely identify each row in the table.

Example 1
PRODUCT (NProd, prod_name, price)
NProd → prod_name
NProd → price
Therefore NProd is a key
Relational Model

Example 2
Consider the following relation:
Pursache(Num_customer, prod_num, pursache_date, Qty)
Suggest a primary key for this relation.

Num_customer Prod_num Pusache_date Qty


C1 P1 D1 23
C1 P2 D1 56
C2 P7 D5 65
C1 P2 D4 5
Relational Model

Foreign key

A foreign key is a set of one or more columns in a relation that


references a primary key in another relation. All values in foreign
keys appear in another relation as values of a key.

 This is a referential integrity constraint.


 By convention, the foreign key of a relation is preceded (or
followed) by the # symbol in a relation schema.
Relational Model

Example

Consider the following relationship schemas:


Customer (CNum, CName, CAddr) Designates the set of customers.
Order (CmdNum, OrderDate, #CNum) Designates the set of orders.

The CNum attribute in the Order relation (table) is a foreign key.


It takes its values from the value domain of the CNum attribute found in the
Customer relation schema.
An order is always ordered by a Customer existing in the database.
Relational Model

An attribute can be both a primary and a foreign key:

- Film (FilmNum, title, year),


- Actor(ActorNum, FName, LName),
- Casting (#FilmNum, #ActorNum, Character).

You might also like