Chapter2. The Databases Concepts
Chapter2. The Databases Concepts
AlBaha University
2019-2020
1
2. The Databases Concepts
2. Concepts of Databases
Contenu
2
2. The Databases Concepts
2.1 Tables, rows and columns
CLIENT
NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT
3
2. The Databases Concepts
2.1 Tables, rows and columns
CLIENT
NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT schema
row
data
4
2. The Databases Concepts
2.2 Null value
5
2. The Databases Concepts
2.3 Identifiers and foreign keys
6
2. The Databases Concepts
2.3 Identifiers and foreign keys
CLIENT
NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT
identifier
ORDER
in Schema
foreign key
in the data
7
2. The Databases Concepts
2.3 Identifiers and foreign keys
8
2. The Databases Concepts
2.3 Identifiers and foreign keys
A foreign key and the identifier of any reference have the same
composition: same number of columns and the columns of the same
type taken in pairs.
9
2. The Databases Concepts
2.4 Schema and content
data
10
2. The Databases Concepts
2.4 Schema et contenu
11
2. The Databases Concepts
2.5 Database Example
ORDER PRODUCT
NORD NCLI DATORD NPRO LABEL PRICE QSTOC
DETAIL
12
2. The Databases Concepts
2.5 Database Example
CLIENT PRODUCT
NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT NPRO LABEL PRICE QSTOC
DETAIL
NORD NPRO QORD
ORDER
NORD NCLI DATORD
13
2. The Databases Concepts
2.5 Database Example
schema variants
CLIENT
NCLI
NOM
ADRESSE COMMANDE PRODUIT
LOCALITE NCOM DETAIL NPRO
CAT[0-1] DATECOM NCOM LIBELLE
COMPTE NCLI NPRO PRIX
id: NCLI id: NCOM QCOM QSTOCK
ref: NCLI id: NCOM id: NPRO
NPRO
ref: NCOM
ref: NPRO
14
2. The Databases Concepts
2.6 Modifications and integrity constraints
15
2. The Databases Concepts
2.6 Modifications and constraints - Mandatory Column
ORDER CLIENT
NORD NCLI
NCLI NAME
DATECOM ADRESS
id: NORD id: NCLI
ref: NCLI
Changing the value of NAME of the table CLIENT the new value of the NAME must be non-null
16
2. The Databases Concepts
2.6 Modifications and constraints - Identifier
ORDER CLIENT
NORD NCLI
NCLI NAME
DATECOM ADRESS
id: NORD id: NCLI
ref: NCLI
Modify the value of NORD The new value of NORD must not already be
From ORDER present in the ORDER
17
2. The Databases Concepts
2.6 Modifications and constraints - Foreign Key
ORDER CLIENT
NORD NCLI
NCLI NAME
DATECOM ADRESS
id: NORD id: NCLI
ref: NCLI
Modify the value NCLI in the new value of NCLI must be present in the
the ORDER column NCLI for a row of CLIENT.
18
2. The Databases Concepts
6 Modifications and constraints - Foreign Key
ORDER CLIENT
NORD NCLI
NCLI NAME
DATECOM ADRESS
id: NORD id: NCLI
ref: NCLI
refused operation
1. mode no action
19
2. The Databases Concepts
2.7 Internal redundancy
BOOK
BOOK
NUMBER TITLE AUTHOR ISBN PUR_DAT EMPL
20
2. The Databases Concepts
2.7 Internal redundancy
The AUTHOR and the TITLE are repeated as many times as there are
identical books.
BOOK
NUMBER TITLE AUTHOR ISBN PUR_DAT EMPL
This table violates the principle databases: every notion is recorded only once.
21
2. The Databases Concepts
2.7 Internal redundancy
BOOK
BOOK
NUMBER TITLE AUTHOR ISBN PUR_DAT EMPL
Difficulties
• waste of space
• If you change the value of a title, it must overtake this change in all similar
lines
• if we remove the only copy of a book, we lose the information about the
author and title
• are we sure that the title and author are spelled exactly the same way for all
copies of a book?
22
2. The Databases Concepts
2.7 Internal redundancy
Suggestion
Gather the common data (ISBN, TITLE, AUTHOR) in a specific table
BOOK
Book
ISBN TITLE AUTHOR
Exemplary
NUMBER ISBN PUR_DAT EMPL
23
2. The Databases Concepts
2.7 Internal redundancy
Two questions
1. How to detect situations of redundancy?
2. How to correct them?
24
2. The Databases Concepts
2.7 Internal redundancy
Functional dependency concept
BOOK
BOOK
NUMBER TITLE AUTHOR ISBN PUR_DAT EMPL
25
2. The Databases Concepts
2.7 Internal redundancy
Functional dependency concept
two observations
1. an identifier determines all columns of the table
2. if a column group determines each column of the table, it constitute
an identifier of this table.
26
2. The Databases Concepts
2.7 Internal redundancy
How to detect situations of redundancy?
Reply
There is internal redundancy when there is a determinant that is not a
table identifier
27
2. The Databases Concepts
2.7 Internal redundancy
How to detect situations of redundancy?
Reply
By breaking down the table T into two fragments:
T1 (determinant, determined)
T2 (determinant, residue)
T2.determinant foreign key to T1
BOOK
ISBN TITLE AUTHOR
Exemplary
NUMBER ISBN PUR_DAT EMPL
28
2. The Databases Concepts
2.7 Internal redundancy
latest remarks
29
2. The Databases Concepts
2.8 Physical structures
Exemple:
Reading a table of 2,500,000 rows of 400 bytes takes almost a minute in the
best of times and one hour otherwise
30
2. The Databases Concepts
2.8 The physical structures - Indexes
B
base de données active 167 the terms of the letter B
base de données temporelles 153, 170
between 67
C
cardinalité d’attribut 182
cardinalité d’un role 187
catalogue 147, 169
cellules 280
Chen 29, 205
chimpanzé 364
circuit de dépendances 312, 392
classe d’objets 201 The terme of « clé étrangère »
classe fonctionnelle 184, 185, 242, 245
page numbers that contain this term
clé étrangère 34, 44, 77, 81, 156
close 145
coalescing 155
COBOL 18, 143
Codd 27
codomaine 351
colonne 32, 35, 44
31
2. The Databases Concepts
2.8 The physical structures - Indexes
01
02
03
04
05
Bruxelles 11
06
Genève 03 07
Lille 12 08
Namur 01 06 14 15 09
Paris 16 10
Poitiers 02 07 09 11
12
Toulouse 04 05 08 10 13
13
14
15
16
line numbers which
LOCALITY = 'Toulouse'
Each line has a unique number;
LOCALITY values, sorted
access to a given line number is very fast
alphabetically
32
2. The Databases Concepts
2.8 The physical structures - Indexes
We define an index on the columns that constitute a foreign key (to speed up
access and verification before removing a row).
33
2. The Databases Concepts
2.8 The physical structures - Indexes
A physical schema
an index is defined on the identifying
columns{NORD, NPRO}
an index
(Or passkey)
storage space
34
2. The Databases Concepts