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

Preview:

Citation preview

Copyright © Genetic Computer School 2009DBSQL 3-1

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

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.

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.

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

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.

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.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-8

Relational Integrity

Domain Type Key

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.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-10

Cont’

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.

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-12

Relational Algebra Operations

Set Operations Union Intersection Difference

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-13

Cont’

Operations that remove parts of a relation

Selection Projection

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-14

Cont’

Operations that combine tuple from two relations

Cartesian Product Join

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-15

Relational Algebra - Examples

Selection

R = Select

ColumnName(condition) Relation

Name

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-16

Cont’

Projection

= Project

= (ColumnName1, ColumnName2….ColumnNamen) Relation Name

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).

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.

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.

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.

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

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

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)}

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) }

Copyright © Genetic Computer School, Singapore 2009

DBSQL 3-25

End

Recommended