1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Database management systems Chapter 4 Relational model

47 234 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 47
Dung lượng 1,56 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 4 Relational model. The main contents of this chapter include all of the following Relational model concept, relational data model, relational database, relation schema, relational algebra, relational query languages,...

Trang 1

Chapter 4

Relational Model

Trang 2

Relational Model Concept

 Relational database: a set of relations

 Each relation resembles a table of values

 Relation: made up of 2 parts

Instance: a table, with rows and columns

Schema: specifies name of relation, plus name

and type of each column

 The terms commonly used User Model Programmer

Column Attribute Field

Table Relation File

Trang 3

Relational Data Model

The relational model uses a collection of

tables to represent both data and the relationships among those data

 Each relation resembles a table of values

 Tables are logical structures maintained

by the database manager

 Ex:

STUDENT (NO., NAME, DATE_OF_BIRTH, GENDER)

Relation Set of attributes

Trang 4

Relational Database

 Ex:

◦ A row is called tuple

◦ A column is called attribute

◦ The table is called relation.

Trang 5

Relational Database

 For each column of a table, there is a set

of possible values called its domain

 Domain is the set of valid values for an attribute

Trang 6

Relation Schema

 Relation Schema R, denoted by R(A1, A2,…, An), is made up of relation name R and a list of attributes A1, A2, …,An

 Each attribute Ai is the name of a role played by some domain D in the relation schema R

 D is called the domain of Ai and is denoted by dom(Ai)

 R is called the name of the relation

 The degree of a relation is the number of attributes n of its relation schema

Trang 8

Relational Data Model

 The relational model is a combination of three components:

Structural Part: the database as a collection

of relations

Integrity Part: maintained in the relational

model using primary and foreign keys

and relational calculus are the tools used to manipulate data in the database

Trang 9

Concept of Key

 An attribute or group of attributes, which

is used to identify a row in a relation

 Can be classified into 3 types:

◦ Super key

◦ Candidate key

◦ Primary key

Trang 11

Concept of Key

Candidate key:

◦ a minimal super key

◦ a minimal set of attributes whose values uniquely identify tuples in the corresponding relation

Trang 12

◦ employee salary, etc

 Super keys can be: employee ID, employee name, employee age, employee experience, etc

 Candidate keys can be: employee ID, employee name, employee age

 Primary key: employee ID

Trang 13

Concept of Key

Trang 14

Relational Query Languages

 A major strength of the relational model: supports simple, powerful querying of data

 Queries can be written intuitively, and the DBMS is responsible for efficient evaluation

 The SQL Query Language is developed

by IBM in the 1970s

Trang 16

◦ If PLAYER’s name’s used as the primary key

 cannot insert any data in the relation PLAYER without entering the name of the player

Trang 18

non-Relational Integrity

 Domain Integrity Constraint

◦ are based upon the semantics of the real world enterprise that is being described in the database relations

◦ are used in the relational model to define the characteristics of the columns of a table

Ex:

◦ The age of the person cannot have any letter from the alphabet The age should be a numerical value

Trang 19

Relational Integrity

 Referential Integrity

◦ a database must not contain any unmatched foreign key values

◦ not imply a foreign key cannot be null

◦ Either each foreign key value must match a primary key value in another relation or the foreign key value must be null

Trang 20

ER design to Relational

 Entity sets to tables

 EMPLOYEE (Emp_ID, Name, Age)

CREATE TABLE Employees

(Emp_ID CHAR(11), Name CHAR(20), Age INTEGER, PRIMARY KEY (Emp_ID)) EMPLOYEE

Emp_ID

Name

Age

Trang 21

Relational Algebra

Query languages: Allow manipulation and

retrieval of data from a database

 Relational model supports simple, powerful QLs:

◦ Strong formal foundation based on logic

◦ Allows for much optimization

 Query Languages != programming languages!

◦ QLs not intended to be used for complex calculations

◦ QLs support easy, efficient access to large data sets

Trang 22

Relational Algebra

Relational algebra

* Selection

* Projection

Trang 23

Selection

 Work on a single relation R

 Define a relation that contains only those tuples of R that satisfy the specified condition

Trang 24

Selection

 Ex:

 Selection operation is associative

Trang 25

Selection _ example

 List all students who get GPA mark > 8

Student Roll No Name GPA

Trang 26

Projection

 Define a relation that contains a vertical subject of R, extracting the values of specified attributes and elimination duplicates

 Syntax: pa1,a2, ,an( R)

Trang 27

 pName, salary ( STAFF)

 Give the name and Date of birth of the all the staff

 pName, Date of birth ( STAFF)

Trang 29

 Define a relation consisting of the set of all tuples that are in both R and S

 Expression: R S

 Ex:

Intersection

R  S = { t | tR  tS }

Trang 30

 Define a relation consisting of the tuples that arein relation R but not in S

 Expression: R - S

 Ex:

Intersection

R - S = { t | tR  tS }

Trang 31

◦ Expression: Original relation: R(A, B, C)

◦ Attribute A will be change into X

ρS(R)

ρX,B,C(R)

Trang 32

◦ E mp_Dep4  σDepNo=4 (STAFF))

◦ R  pFName, LName ( Emp_Dep4 )

ρFirstName, LastName(R)

Trang 33

Cartesian Product

Define a relation that is the concatenation

of every tuples of relation R with every tuples of relation S

The result of Cartesian product contains

all attributes from both relations R and S

 Expression: R x S

Trang 34

Cartesian Product

 Ex:

Trang 35

Cartesian Product

 Ex:

Trang 36

Cartesian Product

 Ex:

Trang 37

 3 types of join operation:

◦ Natural Join

◦ Equi Join

◦ Theta Join

Trang 38

Equi Join

 A special case of condition joins where the condition C contains only equality

 Expression:

Trang 39

Equi Join

Trang 40

◦ Enforce equality on all column attributes

◦ Eliminate one copy of common attribute

Trang 41

Natural Join

Trang 42

Theta Join

 A conditional join in which we impose condition other than equality condition

Trang 43

Outer Join

 In outer join, matched pairs are retained unmatched values in other tables are left null

 Full outer join

 Left outer join

 Right outer join

Trang 44

Outer Join

Trang 45

Outer Join

Trang 46

Outer Join

Trang 47

Outer Join

Ngày đăng: 15/05/2017, 10:33

TỪ KHÓA LIÊN QUAN