DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

25
Copyright © Genetic Computer School 2009 DBSQL 3-1 Chapter 3 Relational Database Model

Transcript of DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Page 1: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School 2009DBSQL 3-1

Chapter 3

Relational Database Model

Page 2: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-2

Chapter 3 Overview

Relational DatabaseRelational Data ModelKeysRelational IntegrityRelational AlgebraTuple and Domain Relational Calculus

Page 3: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-3

Relational Database

Relational database those entities will then be represented by tables or shall we say relation. Each attribute in an entity will serve as the column of each relation which can be specified later with some keys and constraints.

Page 4: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-4

Relational Data Model

Relational Model is composed of tables and its relationship with other tables. Generally it follows the concept of tabular representation of an entity.

Page 5: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-5

Cont’

Relation

Tuple

Domain

Degree

Cardinality

Is a table with flat files of rows and columns which has certain properties

Is a row of a relation and represents and instance of a relation

Is the set of allowable values for one or more columns

Is the number of attributes it contains

Is the number of tuples it contains

Page 6: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-6

Keys

Every relation can be identified using a key column or field. These keys are in different types depending on the degree of a column definition and existence.

Page 7: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-7

Type of Keys

Primary

Foreign

Super

Candidate

Alternate

It is a candidate key that uniquely identifies a relation

It is an attribute key of a relation and also a unique key from another table. This key is used in order to link two tables together.

It is a subset attribute of an entity that will uniquely identify a relation.

Is any set of one or more columns whose combined values are unique among all occurrences (i.e., tuple or row). Alternate keys of any table are simply those candidate keys which are not currently selected as the primary key.

Page 8: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-8

Relational Integrity

Domain Type Key

Page 9: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-9

Relational Algebra

Relational Algebra is a theoretical way of manipulating data in a relational database. This is usually associated with querying the entire database system. It includes operations that act on existing table to produce new table, similar to the way of addition and subtraction act on numbers to produce new numbers.

Page 10: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-10

Cont’

Page 11: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-11

Cont’

Relational Algebra

Relational Calculus

It is more operational, and it deals with operational plan used in manipulating the database.

It Lets user define what they want and how they want the data to be.

Page 12: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-12

Relational Algebra Operations

Set Operations Union Intersection Difference

Page 13: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-13

Cont’

Operations that remove parts of a relation

Selection Projection

Page 14: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-14

Cont’

Operations that combine tuple from two relations

Cartesian Product Join

Page 15: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-15

Relational Algebra - Examples

Selection

R = Select

ColumnName(condition) Relation

Name

Page 16: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-16

Cont’

Projection

= Project

= (ColumnName1, ColumnName2….ColumnNamen) Relation Name

Page 17: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-17

Cont’

Cartesian Product

The Cartesian product is defined by the concatenation of tuples between two relations. It is usually denoted by multiplication operation (R x S).

Page 18: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-18

Cont’

Union

This builds a relation consisting of all tuples appearing in either or both of two specified relations. The two relations must be union-compatible, which means that they must have the same number of attributes and these attributes must come from the same domain.

Page 19: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-19

Cont’

Difference

This operation builds a relation consisting of all tuples appearing the first but not the second of two specified relations.

Page 20: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-20

Cont’

Intersection

This builds a relation consisting of all tuples appearing in both of two specified relation. Again the two relations must be union-compatible.

Page 21: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-21

Join Operations

Join Operation

Natural Join

Theta Join

Equi join

Outer Join

Left-Outer Join Right-Outer Join

Full Outer Join

Page 22: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-22

Advantages and Limitations of Relational Algebra

Relational Algebra is useful specially in query optimization but there are areas in which it cannot be appliedRelational Algebra cannot modify a databaseRelational Algebra cannot perform arithmetic operations

Page 23: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-23

Tuple and Domain Relational Calculus

Tuple Relational Calculus

It is a form of relational calculus where it tries to find a predicate only if it is true. The common term given to this form is called tuple variable.

Notation

{E | L (E)}

Page 24: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-24

Cont’

Domain Relational Calculus

Domain relational Calculus uses variables that take values from domains instead of a relation’s tuple. If a domain formulae is composed of atoms F(d1, d2, …, d n) then it can be represented by the variable:

{d1, d2, …, d n | F (d1, d2, …, d n) }

Page 25: DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-25

End