0% found this document useful (0 votes)
42 views34 pages

Chapter2. The Databases Concepts

The document discusses key concepts of databases including: 1. Tables are made up of rows and columns with data types. Primary keys uniquely identify each row while foreign keys link tables. 2. Schemas define a table's structure of columns and constraints while content is the stored data. 3. Database examples show how tables can be related through primary and foreign keys to represent real world entities and their relationships. Modifications must uphold integrity constraints.

Uploaded by

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

Chapter2. The Databases Concepts

The document discusses key concepts of databases including: 1. Tables are made up of rows and columns with data types. Primary keys uniquely identify each row while foreign keys link tables. 2. Schemas define a table's structure of columns and constraints while content is the stored data. 3. Database examples show how tables can be related through primary and foreign keys to represent real world entities and their relationships. Modifications must uphold integrity constraints.

Uploaded by

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

Chapter2.

THE DATABASES CONCEPTS

Prepared by: Dr Ikram Mohamed Moalla


Presented By: ……………………………
CRN:…………………….

AlBaha University
2019-2020

1
2. The Databases Concepts
2. Concepts of Databases
Contenu

2.1 Tables, rows and columns


2.2 null Value
2.3 Identifiers and foreign keys
2.4 schema and Content
2.5 Database Example
2.6 Changes and constraints
2.7 Internal Redundancy
2.8 The physical constructions

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

mandatory column optional column

4
2. The Databases Concepts
2.2 Null value

The absence of a value is indicated by a special marker says Null value.


Usually represented by <null> or nothing.

Problem: several possible interpretations


1. Relevant but non-existent information for the entity
2. irrelevant information for this entity
3. existing but currently unknown information

Recommendation: Avoid if possible the optional columns.

5
2. The Databases Concepts
2.3 Identifiers and foreign keys

An identifier is a group of columns in a table T such that it can not, be


more than one line in T which has specific values for these columns at
any time.
The value of the identifier used to specify a line of T.

A foreign key is a group of columns in a table S as it exists at any time,


in a table T, a line whose identifier has the value (s) one (s) of this
group.
The foreign key value is used to reference a row in the table T.

6
2. The Databases Concepts
2.3 Identifiers and foreign keys

CLIENT
NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT

identifier

ORDER

NORD NCLI DATORD

in Schema
foreign key
in the data

7
2. The Databases Concepts
2.3 Identifiers and foreign keys

An identifier defines a unique constraint.

A table can have multiple identifiers. We choose one of them as a


primary key. The others are secondary's keys.

The primary identifier is made by mandatory columns.

It is possible to declare a table without identifier; but this is not


recommended.

8
2. The Databases Concepts
2.3 Identifiers and foreign keys

A foreign key defines a referential constraint.

A foreign key references the primary key of the target table.

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

NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT


schema

data

10
2. The Databases Concepts
2.4 Schema et contenu

The schema of a table defines its structure. It specifies in particular:


1. The name of the table,
2. for each column, name, type, whether it is mandatory or not,
3. The primary key (list of columns)
4. The secondary identifiers (list of columns)
5. The foreign keys (list of table columns and target).

The contents of a table is formed of a set of lines in accordance with the


schema.

The contents of a table is subject to frequent changes. The schema of a


table may change but less frequently.

11
2. The Databases Concepts
2.5 Database Example

NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT

ORDER PRODUCT
NORD NCLI DATORD NPRO LABEL PRICE QSTOC

DETAIL

NORD NPRO QORD

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

It is admitted three integrity constraints:


     1. Mandatory column
     2. unique constraint
     3. referential constraint.

There are three basic operations of modifications:


     1. insert a row
     2. delete a row
     3. modify a column value in a row.

Principle: a change will be made only if the outcome does not


violate any integrity constraint.

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

NAME as a mandatory column

insert a row in the table CLIENT NAME value must be non-null

delete a row from the table


CLIENT

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

{NORD} identifier of ORDER

the value of NORD must not be already used


Insert a row in ORDER
in the ORDER

delete a row from


ORDERE

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

{NCLI} foreign key from ORDER to CLIENT

The value NCLI must be present in the


Insert a row in ORDER
column NCLI of the row of CLIENT.

delete a row from


ORDERE
e
ib l
o ss
l p rs
referential integrity must be satisfied after the vera avio
delete a row from CLIENT se beh
operation

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

Behavior {NCLI} foreign key from ORDER to CLIENT

refused operation
1. mode no action

Row deleted but also dependent rows of ORDER


2. mode cascade
delete a row from
CLIENT (if NCLI of ORDER is optional) the column NCLI
3. mode set null of the dependent rows of ORDER is set to null

(if default for NCLI of ORDER ) the column NCLI


4. mode set default of the dependent rows of ORDER takes the
default value

19
2. The Databases Concepts
2.7 Internal redundancy

Table listing the books in a library:

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?

The answer to these questions is based on a new form of


integrity constraint: functional dependency

24
2. The Databases Concepts
2.7 Internal redundancy
Functional dependency concept
BOOK
BOOK
NUMBER TITLE AUTHOR ISBN PUR_DAT EMPL

ISBN  TITRE, AUTEUR


if two rows have the same value of ISBN,
then they also have the same values of TITLE and AUTHOR

We will say that :


• there is a functional dependency from ISBN to TITLE and AUTHOR
• ISBN determines or is a determinant of TITLE and AUTHOR
• AUTHOR and TITLE depend on, or are determined by ISBN

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.

NUMBER  TITLE, AUTHOR, ISBN, DATE_ PUR, EMPL

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

A functional dependency whose determinant is not an identifier is


called abnormal

ISBN is a determinant in books but is not an identifier. It therefore


causes internal redundancy.

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

1. A table that contains abnormal functional dependence is called non-standard


table.
2. without abnormal functional dependence, a table is said to be normalized
3. normalizing a table is to break a table so as to remove its abnormal
dependencies
4. It is essential that all tables in a database are normalized
5. It is possible that a table which contains an abnormal functional dependencies
has no redundancy . It would be only a statistical accident!

29
2. The Databases Concepts
2.8 Physical structures

The tables are stored on the computer disk.


If they are very large, data access and modification may take considerable
time.

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

The physical structures ensure good performance in the operations of


reading and modification.

Two main mechanisms:


• indexes
• storage spaces

30
2. The Databases Concepts
2.8 The physical structures - Indexes

Index (in a book)

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

Index (in a database)

Index on the column LOCALITY


NCLI NAME ADRESS LOCALITY (CAT) ACCOUNT

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

Index (in a database)

Access to a line via an identifier usually takes 10 to 20 milliseconds.

We define generally an index on the columns that constitute an identifier (for


faster access and verification before inserting a row).

We define an index on the columns that constitute a foreign key (to speed up
access and verification before removing a row).

We define an index on the columns that constitute a selection condition


frequently used.

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

You might also like