Top Banner
Chapter 2 The Relational Database Model
37

The relational database model chapter 2

Dec 13, 2014

Download

Data & Analytics

sonabir

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The relational database model  chapter 2

Chapter 2

The Relational Database Model

Page 2: The relational database model  chapter 2

2

Logical View of DataRelational Database

Designer focuses on logical representation rather than physicalUse of table advantageous

Structural and data independenceRelated records stored in independent tablesLogical simplicity

Allows for more effective design strategies

Page 3: The relational database model  chapter 2

3

Logical View of Data (con’t.)

Entities and Attributes Entity is a person, place, event, or thing about which data is collectedAttributes are characteristics of the entity

TablesHolds related entities or entity setAlso called relationsComprised of rows and columns

Page 4: The relational database model  chapter 2

4

Table Characteristics• Two-dimensional structure with rows and

columns• Rows (tuples) represent single entity• Columns represent attributes• Row/column intersection represents single

value• Tables must have an attribute to uniquely

identify each rowPrimary key: attribute and a combination of combined attributes that uniquely identify any given entity (row)

Page 5: The relational database model  chapter 2

5

Table Characteristics (con’t.)

• Column values all have same data format

Data types: Number Character Date Logical

• Each column has range of values called attribute domain

• Order of the rows and columns is immaterial to the DBMS

Page 6: The relational database model  chapter 2

6

Rowentity

Column (attribute)Entity set value

Page 7: The relational database model  chapter 2

7

Page 8: The relational database model  chapter 2

8

Integrity RulesEntity integrity

Requirement (Ensures all entities are unique): all primary key entries are unique; no null valueEach entity has unique key

Referential integrityForeign key must match primary key valuesMakes it impossible to delete row whose primary key has mandatory matching foreign key values in another table

Page 9: The relational database model  chapter 2

9

Relational Database Operators

Relational algebra defines the theoretical way of manipulating table contents using the eight relational operators, or relational algebra determines table manipulationsKey operators

SELECTPROJECTJOIN

Page 10: The relational database model  chapter 2

10

Relational Database Operators

Other operatorsINTERSECTUNIONDIFFERENCEPRODUCTDIVIDE

Page 11: The relational database model  chapter 2

11

UNION

Tables must have the same attribute characters (column and domains must be identical)

That is called these tables are UNION compatible

Combines all rows Example:

Page 12: The relational database model  chapter 2

12

Union

Figure 2.5

Page 13: The relational database model  chapter 2

13

Intersect

Tables must be UNION compatible

Yield rows appear in both tables

Example:

Page 14: The relational database model  chapter 2

14

Yields rows that appear in both tables

Intersect

Figure 2.6

Page 15: The relational database model  chapter 2

15

Difference

Tables must be UNION compatible

Find rows in table that are not found in the other table.

Example:

Page 16: The relational database model  chapter 2

16

Yields rows not found in other tables

Difference

Figure 2.7

Page 17: The relational database model  chapter 2

17

Product

Yields all possible pairs of rows from two tables

Example:

Page 18: The relational database model  chapter 2

18

Product

Figure 2.8

Page 19: The relational database model  chapter 2

19

Select Yields values for all rows

found in a table. Select can be used to either

list all or list partial rows values that match a specified criterion.

Example:

Page 20: The relational database model  chapter 2

20

Select

Page 21: The relational database model  chapter 2

21

Project

Project yields a vertical subset of a table with selected attributes

Example:

Page 22: The relational database model  chapter 2

22

Project

Figure 2.10

Page 23: The relational database model  chapter 2

23

Join Combine information from

multiple tables Natural join process

Product Select Project

Example:

Page 24: The relational database model  chapter 2

24

Join

Figure 2.11

Figure 2.14

Page 25: The relational database model  chapter 2

25

Links tables by selecting rows with common values in common attribute(s)Three-stage process

Product creates one tableSelect yields appropriate rowsProject yields single copy of each attribute to eliminate duplicate columns

Natural Join Process

Page 26: The relational database model  chapter 2

26

Product Process in Join

Page 27: The relational database model  chapter 2

27

Page 28: The relational database model  chapter 2

28

Select Process in Join

Page 29: The relational database model  chapter 2

29

Project Process in Join

Page 30: The relational database model  chapter 2

30

Other Joins

EquiJOINLinks tables based on equality condition that compares specified columns of tables Does not eliminate duplicate columns Join criteria must be explicitly defined

Page 31: The relational database model  chapter 2

31

Other Joins

EquiJOIN that compares specified columns of each table using operator other than equality one

Theta JOINAny other comparison operator is used, it is generally called a theta JOIN

Page 32: The relational database model  chapter 2

32

Other JoinsOuter JOIN

Matched pairs are retained Unmatched values in other tables left nullRight and left outer JOINExample:

Page 33: The relational database model  chapter 2

33

Page 34: The relational database model  chapter 2

34

Page 35: The relational database model  chapter 2

35

Divide

Use of one single-column table and one two-column table

Find the values associate with A and B Table

Example:

Page 36: The relational database model  chapter 2

36

Requires user of single-column table and two-column table

Divide

Figure 2.17

Page 37: The relational database model  chapter 2

37

Data Dictionary and System Catalog

Data dictionaryProvides detailed account of all tables found within databaseMetadataAttribute names and characteristicsAll members of database design and implementation teams use the same table, attributes and characteristicsDBMS internally store data dictionary and additional information containing relationship types, entity and

referential integrity check and enforcement. Database designer’s database

System catalogDetailed data dictionary; current relational database software provides only a system catalogData dictionary can be derived fromStores database characteristics and contents