Mister

Only available on StudyMode
  • Topic: Relational model, Relational algebra, Relation
  • Pages : 13 (1807 words )
  • Download(s) : 30
  • Published : April 8, 2013
Open Document
Text Preview
ITRW 311 Mr R Botes Building 6-105 (Office hours will still be given) romeo.botes@nwu.ac.za

DATABASES I

1

Chapter 4 The Relational Database Model
Textbook p116-121 Study Unit: 4

2

In this chapter, you will learn:
• What is meant by relational algebra? • How to manipulate database tables using relational set operators • How the DBMS supports the key relational operators: select, project and join. • The different types of joins. • How to write queries using relational algebra expressions.

3

Relational Algebra
• Relational algebra and relational calculus are the mathematical basis for ‘relational databases’. • Relational algebra……. – Defines theoretical way of manipulating table contents using relational operators – Use of relational algebra operators on existing tables (relations) produces new relations

• Codd defined eight relational operators:

4

Relational Algebra Operators
• SELECT • PROJECT

• UNION
• INTERSECT

• DIFFERENCE • DIVIDE • PRODUCT
• JOIN

5

Re-visiting Set Theory

6

SELECT
• Yields values for all rows found in a table • Can be used to list either all row values or it can yield only those row values that match a specified criterion • Yields a horizontal subset of a table

7

SELECT (continued)
• The SELECT operator denoted by σθ , is formally defined as: σθ (R) or σ (RELATION)

• where σθ (R) is the set of specified tuples of the relation R and θ is the predicate (or criterion) to extract the required tuples.

8

SELECT (continued)

9

SELECT (continued)

10

PROJECT
• Project
– Yields all values for selected attributes – Yields a vertical subset of a table

11

PROJECT (continued)
• The PROJECT operator, denoted by ∏, is formally defined as: ∏ a1…an (R) or ∏ (Relation)

• where the projection of the relation R, denoted by ∏ a1…an (R) is the set of specified attributes a1…an of the relation R.

12

PROJECT (continued)

13

Union
• Union:
– Combines all rows from two tables, excluding duplicate rows – Tables must have the same attribute characteristics

– When two or more tables share the same number of columns, i.e. have the same degree, and when they share the same (or compatible) domains, they are said to be union-compatible.

14

Union (continued)
• The UNION operator, denoted by ∪, is formally defined as: The union of relations R1(a1, a2,.... ,an) and R2(b1, b2,...., bn) denoted R1 ∪ R2 with degree n, is the relation R3(c1, c2,.... ,cn) where for each i (i =1,2..n), ai and bi must have compatible domains.

15

Union (continued)

16

Union (continued)

17

Union (continued)

18

Intersect
• Intersect:
– Yields only the rows that appear in both tables

– the tables must be union-compatible to give valid results.

19

Intersect (continued)
• The INTERSECT operator is formally defined as:
The intersect of relations R1(a1, a2,.... ,an) and R2(b1, b2,...., bn) denoted R1 ∩ R2 with degree n, is the relation R3(c1, c2,.... ,cn) that includes only those tuples of R1 that also appear in R2 where for each i (i =1,2..n), ai and bi must have compatible domains.

20

Intersect (continued)

21

Difference
• Difference
– Yields all rows in one table not found in the other table — that is, it subtracts one table from the other – The DIFFERENCE operator also requires that the two relations must be union-compatible.

22

Difference (continued)
• The DIFFERENCE operator is formally defined as: • The difference of relations R1(a1, a2,.... ,am) and R2(b1, b2,...., bm) denoted R1 - R2 with degree m, is the relation R3(c1, c2,.... ,cm) that includes all tuples that are in R1 but not in R2 where for each i (i =1,2..m), ai and bi must have compatible domains.

23

Difference (continued)

24

Cartesian product
• Cartesian product
• usually written as R1 X R2

• Yields all possible pairs of rows from two tables
• Also known as the product.

25

Cartesian...
tracking img