0% found this document useful (0 votes)
51 views27 pages

(SQL2) نظري 1 PDF

This document provides a summary of Lecture 1 of an Advanced Database course. It introduces the relational data model and some key concepts including: 1) The relational model represents data stored in relational databases as tables called relations with columns and rows. 2) Relations have attributes, keys, domains and integrity constraints. Primary keys uniquely identify each row and foreign keys link tables. 3) Functional dependencies specify relationships between attributes. Normalization is the process of structuring relations to minimize redundancy and dependency. The three normal forms - 1NF, 2NF, 3NF - were introduced.

Uploaded by

EM EL-sanosi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views27 pages

(SQL2) نظري 1 PDF

This document provides a summary of Lecture 1 of an Advanced Database course. It introduces the relational data model and some key concepts including: 1) The relational model represents data stored in relational databases as tables called relations with columns and rows. 2) Relations have attributes, keys, domains and integrity constraints. Primary keys uniquely identify each row and foreign keys link tables. 3) Functional dependencies specify relationships between attributes. Normalization is the process of structuring relations to minimize redundancy and dependency. The three normal forms - 1NF, 2NF, 3NF - were introduced.

Uploaded by

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

Misurata University

Faculty of Information Technology

Advanced Database

LECTURE 1
Relational Data Model

Instructor Aisha Lusta

8-Nov-22
What is a Data Model?
 A notation for describing data or information
 Description consists of 3 parts:
1) Structure of the data

2) Operations on the data


-Queries (Operations that retrieve
information)
-Modifications (Operations that change the
database)
3) Constraints on the data
-Limitations
8-Nov-22
The Relational Model
 Relational Model represents how data is stored in
Relational Databases.
 A relational database stores data in the form of
relations (tables).

 Column headers Field names

 Each row values of struct in the array

8-Nov-22
Basics of the Relational Model
1-4

 Represent data as a two-dimensional table


called a relation.

 `

8-Nov-22
Basics of the Relational Model
1-5

 Domain of the attribute Name={Matt, Troy, Sean,


Christy}
 The Degree of the relation is the number of its
attributes (4)
 The cardinality is the numbers of rows Tuples(4)

8-Nov-22
Keys of Relations
1-6

 A set of attributes that forms a key for a


relation, if:
we don’t allow two tuples in a relation
instance to have the same values in all the
attributes of the key

8-Nov-22
1-7

Candidate Key :
 A Candidate Key can be any column or a
combination of columns that can qualify as
unique key in database.
 There can be multiple Candidate Keys in one

table.
 Each Candidate Key can qualify as Primary
Key.
8-Nov-22
1-8

Primary key:
A Primary Key is a column or a combination of
columns that uniquely identify a ROW. Only one
Candidate Key can be Primary Key.

8-Nov-22
1-9 D# Dname Chairman City
11 Sales Ahmed Misurata
12 Account Ali Tripoli
22 Research Sara Tripoli
Department table

 D#, Dname are candidate keys.


 If we chose D# to represent the primary key
Dname would be the alternative key.

8-Nov-22
1-

 A Foreign Key: is a key used to link two tables


together.
 A Foreign Key: is a column (or collection of

columns) in one table that refers to the


PRIMARY KEY in another table.
 The table which containing foreign key is called
the child table.
 The table which containing the primary key is

called the referenced or parent table.


8-Nov-22
1-11

8-Nov-22
Integrity Rules
1-12

1- Entity integrity
exists when each primary key within a table has
a value that is unique.
 This ensures that each row is uniquely identified

by the primary key.


 One requirement for entity integrity is that a

primary key cannot have a null value

8-Nov-22
1-13

2- Reference integrity
Is the relational property that each foreign key value in a table
exists as a primary key in the referenced table.
COURSE
C# CCODE CREDITS
20 CS 701 3
25 CS 705 4
35 CS 503 3
36 MA 101 3
Department C# is the primary key

D# Dname City C#
10 Cs Misurata 20
12 Math Tripoli 36 C# is the foreign key 8-Nov-22
1-14

3- Domain integrity
Specify that all columns in a database must be
declared upon a defined domain. A domain is a set
values of the same value type.

Example: City in ( “Misurata”, “Tripoli)


(Age BETWEEN 18 AND 25)

8-Nov-22
Functional dependencies

 Functional dependencies (FDs) are used to specify


formal measures of the "goodness" of relational
designs.
 FDs and keys are used to define normal forms for
relations.
 FDs are constraints that are derived from the
meaning and interrelationships of the data
attributes.
 X Y holds if whenever two tuples have the same
value for X, they must have the same value for Y
8-Nov-22
Examples of FD constraints

 Social Security Number determines employee name


SSN  ENAME
 Project Number determines project name and
location
PNUMBER  {PNAME, PLOCATION}
 Employee SSN and project number determines the
hours per week that the employee works on the
project
{SSN, PNUMBER}  HOURS
8-Nov-22
Normalization
Normalization is a process that aims at achieving
better designed relational database schemas through
the use of semantic information given by.

– Functional Dependencies
– Primary Keys

8-Nov-22
The Normalization of Relations
8-Nov-22

Normalization: The process of decomposing


unsatisfactory "bad" relations by breaking up their
attributes into smaller relations
Normal form: Condition using keys and FDs of a
relation to certify whether a relation schema is in
particular normal form.

1. First Normal Form (1NF)


2. Second Normal Form (2NF)
3. Third Normal Form (3NF)
First Normal Form (1NF)
8-Nov-22

A relation schema is in 1NF if domains of attributes


include only atomic values and the value of an
attribute is a single value from the domain of that
attribute.
Disallows
• Composite attributes

• Set-valued attributes

• Nested relations; a cell of an individual tuple is a complex relation


Non-1NF Relation
8-Nov-22

Non atomic
values

Problem with this design:


Redundancy
Solution
21

 Createnew relation
 Columns = Key + multi-valued

8-Nov-22
Solution

8-Nov-
22 22
Second Normal Form (2NF)

A relation schema is in 2NF if it is in 1NF, and every


non-prime attribute is fully functionally dependent on
the primary key
(Disallows Partial Dependency)

8-Nov-22
1-24

Solution

8-Nov-22
Third Normal Form (3NF)
8-Nov-22

A relation schema is in 3NF if it is in 2NF, and no non-


prime attribute is transitive dependent on the
primary key.

SSN  ENAME is non transitive


SSN  DMRGSSN is transitive FD

25
Non 3NF Relation
26

Relations after decomposition

Solution

8-Nov-22
The End

8-Nov-22

You might also like