44
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah | [email protected] | http://www.sitinur151.wordpress.com | | A2-3039 | ext:2561 | 012-7760562 | CHAPTER 3 The Relational Model

ITS232 Introduction To Database Management Systems

  • Upload
    briar

  • View
    61

  • Download
    1

Embed Size (px)

DESCRIPTION

ITS232 Introduction To Database Management Systems . Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah | [email protected] | http://www.sitinur151.wordpress.com | | A2-3039 | ext:2561 | 012-7760562 |. CHAPTER 3 - PowerPoint PPT Presentation

Citation preview

Page 1: ITS232 Introduction To Database Management Systems

ITS232Introduction To Database Management Systems

Siti Nurbaya IsmailFaculty of Computer Science & Mathematics,

Universiti Teknologi MARA (UiTM), Kedah| [email protected] | http://www.sitinur151.wordpress.com |

| A2-3039 | ext:2561 | 012-7760562 |

CHAPTER 3The Relational Model

Page 2: ITS232 Introduction To Database Management Systems

3.0 THE RELATIONAL MODEL 3.1 A Logical View Of Data 3.2 Keys 3.3 Integrity Rules Revisited 3.4 Data Dictionary And System Catalogue 3.5 Relationship Within The Relational Database 3.6 Data Redundancy Revisited 3.7 Indexes

Chapter 3: The Relational Data Model

Page 3: ITS232 Introduction To Database Management Systems

3

3.0 The Relational ModelA Glance Of The Big Concept

Page 4: ITS232 Introduction To Database Management Systems

4

3.0 The Relational Model3.1 A Logical View Of Data

• Relational model – Enables programmer to view data logically rather than physically

• Table – Has advantages of structural and data independence– Resembles a file from conceptual point of view– Easier to understand than its hierarchical and network database

Page 5: ITS232 Introduction To Database Management Systems

5

3.0 The Relational Model3.1 A Logical View Of Data: Table and Their Characteristics

• Table: – two-dimensional structure composed of rows and columns– Contains group of related entities = an entity set

• Terms entity set and table are often used interchangeably• Table also called a relation because the relational model’s creator, Codd,

used the term relation as a synonym for table• Think of a table as a persistent relation:

– A relation whose contents can be permanently saved for future use

Page 6: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.1 A Logical View Of Data: Table and Their Characteristics

Characteristics Of A Relational Table

1 Two dimensional structure :: rows & columns

2 Each table row (tuple) represent a single entity occurrence to the entity set

3 Each column represents and attribute and each column has a distinct name

4 Each row/column intersection represent a single data value

5 All value in a column must confirm to the same data format

6 Each column has a specific range of values know as attribute domain

7 The order of the rows and columns is immaterial to DBMS

8 Each table must have an attribute or a combination of attribute that uniquely identifies each row

Page 7: ITS232 Introduction To Database Management Systems

7columns>represents an attribute>each column has a distinct name

rows (tuple)>represents an entity (data Value)

keysprimary keyBIKE TABLE

IDbike IDmember biketype

101 10001 Orange P7

102 10001 Diamondback X-Link

103 10002 Kona Lava Dome

104 10003 Kona Nunu

105 10004 Kona Lava Dome

106 10004 Diamondback X-Link

107 10005 Kona Lava Dome

108 10006 Orange P7

foreign key

3.0 The Relational Model3.1 A Logical View Of Data: Table and Their Characteristics

Page 8: ITS232 Introduction To Database Management Systems

8

columns

rows (tuple)

keys

primary key

>represents an attribute>each column has a distinct name

>an entity

MEMBER TABLE

3.0 The Relational Model3.1 A Logical View Of Data: Table and Their Characteristics

Page 9: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.1 A Logical View Of Data: Table and Their Characteristics

Page 10: ITS232 Introduction To Database Management Systems

10

3.0 The Relational Model3.2 Keys: The Concepts

• Consists of one or more attributes that determine other attributes• Key’s role is based on determination

– If you know the value of attribute A, you can look up (determine) the value of attribute B

– A B

Page 11: ITS232 Introduction To Database Management Systems

11

3.0 The Relational Model3.2 Keys: Types

•an attribute (or a combination of attributes) that uniquely identifies any given entity (row) Primary Key

(PK)

•composed of more than one attribute Composite Key

•any attribute that is part of a key Key Attribute• any key that uniquely identifies each row

Superkey

• a superkey without redundancies

Candidate key

•artificial or identity key Surrogate Key

•an attribute whose values match primary key values in the related table Foreign key

(FK)

•Key used strictly for data retrieval purposes Secondary key

Page 12: ITS232 Introduction To Database Management Systems

12

3.0 The Relational Model3.2 Keys: Types

Examples:

IDmember name street city postcode telephone datejoined 10001 Syakirin 123 Desa Jaya Jengka 26400 09-575755 2/1/199810002 Islah 65 Kampung Pinang Melaka 78000 06-232321 3/4/199710003 Ihsan 5 Skudai Kiri Johor 81300 07-564233 12/31/2001

IDbike IDmember biketype101 10001 Orange P7102 10001 Diamondback X-Link103 10002 Kona Lava Dome104 10003 Kona Nunu

IDmember (PK in table member)IDmember (FK in table bikes)

Table name: member

Table name: bikes

IDbike (PK in table bikes)

Page 13: ITS232 Introduction To Database Management Systems

13

3.0 The Relational Model3.2 Keys: Nulls

• Nulls:– No data entry– Not permitted in primary key– Should be avoided in other attributes– Can represent

• An unknown attribute value• A known, but missing, attribute value• A “not applicable” condition

– Can create problems when functions such as COUNT, AVERAGE, and SUM are used

– Can create logical problems when relational tables are linked

Page 14: ITS232 Introduction To Database Management Systems

14

3.0 The Relational Model3.2 Keys: Nulls

Examples:

IDmember name street city postcode telephone datejoined 10001 Syakirin 123 Desa Jaya Jengka 26400 09-575755 2/1/199810002 Islah 00000000 3/4/199710003 Ihsan 5 Skudai Kiri Johor 81300 07-564233 12/31/2001

Table name: member

** null

Page 15: ITS232 Introduction To Database Management Systems

15

3.0 The Relational Model3.2 Keys: Controlled Redundancy

• Controlled redundancy:– Makes the relational database work– Tables within the database share common attributes that enable the

tables to be linked together– Multiple occurrences of values in a table are not redundant when they

are required to make the relationship work– Redundancy exists only when there is unnecessary duplication of

attribute values– The importance keys for maintain controlled redundancy are:

• Foreign key (FK)• Primary key (PK)

– Controlled Redundancy may lead to;• Referential integrity • FK contains a value that refers to an existing valid tuple (row) in

another relation

Page 16: ITS232 Introduction To Database Management Systems

16

3.0 The Relational Model3.2 Keys: Controlled Redundancy

Examples:

IDmember name street city postcode telephone datejoined 10001 Syakirin 123 Desa Jaya Jengka 26400 09-575755 2/1/199810002 Islah 65 Kampung Pinang Melaka 78000 06-232321 3/4/199710003 Ihsan 5 Skudai Kiri Johor 81300 07-564233 12/31/2001

IDbike IDmember biketype101 10001 Orange P7102 10001 Diamondback X-Link103 10002 Kona Lava Dome104 10003 Kona Nunu

IDmember(10001) determine biketype(Orange P7 & Diamonback X-Link)

Table name: member

Table name: bikes

** knowing IDmember in table member, means that you are able to look up (determine) what type of bikes that certain member have

Page 17: ITS232 Introduction To Database Management Systems

17

3.0 The Relational Model3.2 Keys: Controlled Redundancy

• knowing IDmember in table member, means that you are able to look up (determine) what type of bikes that certain member have

• There for, using the attributes of the member table, we can represent the statement “IDmember determines biketype” by writing– IDmember biketype

• In contrast, biketype is not determined by IDmember, because it is quite possible for several members to have Orange P7 bike types

Page 18: ITS232 Introduction To Database Management Systems

Entity Integrity Description

Requirement All primary key entries are unique, and no part of primary key may be null

Purpose Each row will have a unique identity, and foreign key can properly reference primary key values

Example No invoice can have duplicate number, nor it can be null. In short, all invoices are uniquely identified by their invoices number

3.0 The Relational Model3.3 Integrity Rules Revisited: Entity Integrity

Page 19: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.3 Integrity Rules Revisited: Referential Integrity

Referential Integrity

Description

Requirement A foreign key may have either a null entry-as long as it is not a parts of it table’s PK – or an entry that matches the PK value in a table to which it is related

Purpose It is possible for an attribute NOT to have corresponding value, but it will be impossible to have an invalid entry. The enforcement of the referential integrity rule make it is impossible to delete a row in one table whose PK has mandatory matching FK values in another table.

Example A customer might not yet have an assigned sales representative no, but it will be impossible to have an invalid sales representative no

Page 20: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.3 Integrity Rules Revisited: Integrity Rules

Page 21: ITS232 Introduction To Database Management Systems

21

3.0 The Relational Model3.4 Data Dictionary & System Catalog

• Data dictionary – Provides detailed accounting of all tables found within the

user/designer-created database– Contains (at least) all the attribute names and characteristics for each

table in the system– Contains metadata—data about data– Sometimes described as “the database designer’s database” because

it records the design decisions about tables and their structures

Page 22: ITS232 Introduction To Database Management Systems

22

3.0 The Relational Model3.4 A Sample Of Data Dictionary

Page 23: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.4 A Sample Of Data Dictionary

Page 24: ITS232 Introduction To Database Management Systems

24

3.0 The Relational Model3.4 Data Dictionary And System Catalog

• System catalog – Contains metadata– Detailed system data dictionary that describes all objects within the

database– Terms “system catalog” and “data dictionary” are often used

interchangeably– Can be queried just like any user/designer-created table

Page 25: ITS232 Introduction To Database Management Systems

25

3.0 The Relational Model3.5 Relationship Within Relational Database

• Relationship is a logical interaction among the entities in a relational database.

• Operate in both directions• There are 3 basic relationship in a database;

(1:1)

one-to-one should be rare in

any relational database

(1:M)

one-to-many relational

modeling ideal should be norm in

any relational database design

(M:N)

many-to-many cannot be

implemented as such in the relational model

m:n relationships can be changed into two 1:m relationships

Page 26: ITS232 Introduction To Database Management Systems

26

3.0 The Relational Model3.5 Relationship Within Relational Database: one-to-many (1:M)

• Relational database norm• Found in any database environment

Page 27: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: one-to-many (1:M)

Page 28: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: one-to-many (1:M)

Page 29: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: one-to-many (1:M)

Page 30: ITS232 Introduction To Database Management Systems

30

3.0 The Relational Model3.5 Relationship Within Relational Database: one-to-one (1:1)

• One entity can be related to only one other entity, and vice versa• Sometimes means that entity components were not defined properly• Could indicate that two entities actually belong in the same table• As rare as 1:1 relationships should be, certain conditions absolutely

require their use

Page 31: ITS232 Introduction To Database Management Systems

31

3.0 The Relational Model3.5 Relationship Within Relational Database: many-to-many (M:N)

• Can be implemented by breaking it up to produce a set of 1:m relationships

• Can avoid problems inherent to m:n relationship by creating a composite entity or bridge entity

Page 32: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: many-to-many (M:N)

Page 33: ITS232 Introduction To Database Management Systems

33

3.0 The Relational Model3.5 Relationship Within Relational Database: many-to-many (M:N)

• Implementation of a composite entity• Yields required m:n to 1:m conversion• Composite entity table must contain at least the primary keys of original

tables• Linking table contains multiple occurrences of the foreign key values• Additional attributes may be assigned as needed

Page 34: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: many-to-many (M:N)

Page 35: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: many-to-many (M:N)

Page 36: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: many-to-many (M:N)

Page 37: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.5 Relationship Within Relational Database: many-to-many (M:N)

Page 38: ITS232 Introduction To Database Management Systems

38

3.0 The Relational Model3.6 Data Redundancy Revisited

• Data redundancy leads to data anomalies– Such anomalies can destroy the effectiveness of the database

• Foreign keys– Control data redundancies by using common attributes shared by

tables– Crucial to exercising data redundancy control

• Sometimes, data redundancy is necessary

Page 39: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.6 Data Redundancy Revisited

Page 40: ITS232 Introduction To Database Management Systems

40

3.0 The Relational Model3.7 Indexes

• Arrangement used to logically access rows in a table• Index key

– Index’s reference point– Points to data location identified by the key

• Unique index– Index in which the index key can have only one pointer value (row)

associated with it• Each index is associated with only one table

Page 41: ITS232 Introduction To Database Management Systems

3.0 The Relational Model3.7 Indexes

Page 42: ITS232 Introduction To Database Management Systems

42

3.0 The Relational Model3.7 Summary

• Tables are basic building blocks of a relational database• Keys are central to the use of relational tables• Keys define functional dependencies

– Superkey– Candidate key– Primary key– Secondary key– Foreign key

Page 43: ITS232 Introduction To Database Management Systems

43

3.0 The Relational Model3.7 Summary

• Each table row must have a primary key which uniquely identifies all attributes

• Tables can be linked by common attributes. Thus, the primary key of one table can appear as the foreign key in another table to which it is linked

• The relational model supports relational algebra functions: SELECT, PROJECT, JOIN, INTERSECT, UNION, DIFFERENCE, PRODUCT, and DIVIDE.

• Good design begins by identifying appropriate entities and attributes and the relationships among the entities. Those relationships (1:1, 1:M, and M:N) can be represented using ERDs.

Page 44: ITS232 Introduction To Database Management Systems

44

3.0 The Relational Model3.7 Summary