20
1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed the EER model and its reduction to tables. Present learning: We shall explore the following topics: - Relational model. - Relation schema and instances.

1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Embed Size (px)

Citation preview

Page 1: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

1

Session 3

Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“Recap : In the previous learning sequences, we

discussed the EER model and its reduction to tables.

Present learning: We shall explore the following topics:

- Relational model. - Relation schema and instances.

Page 2: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

2

Relational Model

Page 3: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

3

Example of a RelationExample of a Relation

Page 4: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Basic Structure (1)Basic Structure (1)

Formally, given sets D1, D2, …. Dn a relation r is a subset of D1 x D2 x … x Dn

Thus a relation is a set of n-tuples (a1, a2, …, an) where each ai Di

Example: ifcustomer-name = {Jones, Smith, Curry,

Lindsay}customer-street = {Main, North, Park}customer-city = {Harrison, Rye, Pittsfield}

Page 5: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Basic Structure (2)Basic Structure (2)

Then r = { (Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield)}

is a relation over customer-name x customer-street x customer-city

Page 6: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Basic Structure (3)Basic Structure (3)

Each attribute of a relation has a name

The set of allowed values for each attribute is called the domain of the attribute

Attribute values are (normally) required to be atomic, that is, indivisible E.g. multivalued attribute values are not atomic E.g. composite attribute values are not atomic

Page 7: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Basic Structure (4)Basic Structure (4)

The special value null is a member of every domain

The null value causes complications in the definition of many operations we shall ignore the effect of null values in our main

presentation and consider their effect later

Page 8: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Relation SchemaRelation Schema

A1, A2, …, An are attributes

R = (A1, A2, …, An ) is a relation schemaE.g. Customer-schema = (customer-name, customer-street, customer-city)

r(R) is a relation on the relation schema R E.g. customer (Customer-schema)

Page 9: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Relation InstanceRelation Instance

The current values (relation instance) of a relation are specified by a table

An element t of r is a tuple, represented by a row in a table

Page 10: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Relation InstanceRelation Instance

Customer-id

Customer-name

Customer-street

Customer-city

192-83 Ahmed 23 Alma St. Jbeha

182-74 Kasim 12 Main St. Sweleh

677-600 Rana 7 Park Ave. Marka

321-140 Susan 57 North St.

Jabal

710-569 Tarik 33 Alma St. Jbeha

210-872 Ali 88 East St. Gardens

CUSTOMER table

Data-item name

Data-item value

Tuples(Records)

Page 11: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Relations are UnorderedRelations are Unordered Order of tuples is irrelevant (tuples may be

stored in an arbitrary order) E.g. account relation with unordered tuples

Page 12: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

DatabaseDatabase

A database consists of multiple relations

Information about an enterprise is broken up into parts, with each relation storing one part of the information. For example:

account :stores information about accounts

depositor : stores information about which

customer owns which account customer : stores information about customers

Page 13: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

DatabaseDatabase

Storing all information as a single relation such as bank (account-number, balance, customer-name, ..)

results in

repetition of information (e.g. two customers own an account)

the need for null values (e.g. represent a customer without an account)

Page 14: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

The The customer customer RelationRelation

Page 15: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

The The depositor depositor RelationRelation

Page 16: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

E-R Diagram for the E-R Diagram for the Banking EnterpriseBanking Enterprise

Page 17: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Schema Diagram for the Schema Diagram for the Banking EnterpriseBanking Enterprise

Page 18: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

Relational Schema for the Relational Schema for the Banking EnterpriseBanking Enterprise

branch (branch-name, branch-city, assets)

customer (customer-name, customer-street, customer-only)

account (account-number, branch-name, balance)

loan (loan-number, branch-name, amount)

depositor (customer-name, account-number)

borrower (customer-name, loan-number)

Page 19: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

19

Reduction of an E-R Schema to Tables

Summary: In this learning sequence, we discussed

the relational model with its schema and instances.

Page 20: 1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed

20

END