0% found this document useful (0 votes)
3 views

Chapter 3

Chapters 3 and 4 of 'Database Systems: Design Implementation and Management' cover the relational database model, detailing its structure, including tables, keys, and data integrity. Key concepts include the organization of data into relations, the importance of primary and foreign keys, and the rules for maintaining data integrity. The chapters emphasize the significance of understanding relationships, data redundancy, and indexing in relational databases.

Uploaded by

h49zd4kxps
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Chapter 3

Chapters 3 and 4 of 'Database Systems: Design Implementation and Management' cover the relational database model, detailing its structure, including tables, keys, and data integrity. Key concepts include the organization of data into relations, the importance of primary and foreign keys, and the rules for maintaining data integrity. The chapters emphasize the significance of understanding relationships, data redundancy, and indexing in relational databases.

Uploaded by

h49zd4kxps
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

DATABASE SYSTEMS

DESIGN IMPLEMENTATION AND MANAGEMENT

INTERNATIONAL EDITION

ROB • CORONEL • CROCKETT

Chapter 3 and 4
The Relational Database Model
1
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

And so the fun begins

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 2
In this chapter, you will learn:
DATABASE SYSTEMS: Design Implementation and Management (Rob,
Coronel & Crockett 9781844807321)
2

A. That the relational database model takes a logical view of data.


1. The relational model’s basic components are relations implemented
through tables in a relational DBMS
2. How relations are organized in tables composed of rows and columns

B. The different types of keys and what they are used for
C. How to set rules to ensure the integrity of the data
D. About the data dictionary, and the system catalog
E. The different types of relationships within a relational database
F. How data redundancy is handled in the relational database
G. Why indexing is important
H. Codd’s 12 relational database rules
3
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Relational data structure

• A relation is a table with columns and rows


• An attribute is a named column of a relation
• Record – logically connected set of one or more
fields that describe a person, place or thing
• A domain is the set of allowable values for one
or more attributes

4
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Characteristics of a relational table


1. A table is perceived as a two dimensional
structure composed of rows and columns
2. Each row (tuple) represents a single entity and
must be distinct
3. Each table column represents an attribute, and
each column has a distinct name
4. Each cell should contain an atomic value –
single cell value
Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 5
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Characteristics of a relational table


5. All values in a column must conform to the same
data format
6. Each column has a specific range of values
known as the attribute domain
7. The order of the rows and columns is
immaterial to the DBMS
8. Each table must have an attribute that
uniquely identifies each row
Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 6
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

2 dimension structure ?

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 7
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

2 dimension structure ?

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 8
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Each table row represents a single


entity occurrence within the entity set

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 9
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Each table column represent an


attribute, and each column has a
distinct name

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 10
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Each table column represent an


attribute, and each column has a
distinct name

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 11
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Each intersection of a row and column


represents a single data value

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 12
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

All values in a column must conform to


the same data format

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 13
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Each table must have an attribute or


combination of attributes that uniquely
identifies each row

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 14
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

The order of the rows and columns is


immaterial to the DBMS

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 15
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 16
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Is This a Relational Database?

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 17
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 18
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Relational schema
Coronel & Crockett 9781844807321)

• A textual representation of database tables, where


each table is described by its name followed by a list
of its attributes in parenthesis
– R = {a1 , a2 , a3 …. an}
– Student (Stud_Num, FirstName, Surname, Age)

Student

Stud_Num FirstName Surname Age

19
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Cardinality and Degree

• The cardinality of a relation is the number of its


rows
• The degree of a relation is the number of its
attributes/columns

20
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 21
DATABASE
NorthwindSYSTEMS: Design Implementation
Traders databaseand Management
has (Rob,
a CATEGORIES table. 2
Coronel & Crockett 9781844807321)
How many cardinalities?
How many degrees of relation?

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 22
DATABASE
NorthwindSYSTEMS: Design Implementation
Traders databaseand Management
has (Rob,
a CATEGORIES table. 2
Coronel & Crockett 9781844807321)
How many cardinalities?
How many degrees of relation?

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 23
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

So cardinality is ?? and degree of ??

24
DATABASE
But theSYSTEMS: Design Implementation
PRODUCTS table and Management (Rob, 2
Coronel & Crockett 9781844807321)
has 95 products and
10 columns or attributes

So cardinality is ?? and degree of ??

25
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 26
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

B. Keys
• Keys consist of one or more attributes that determine other
attributes
• Candidate key is an attribute that determines all the other
attributes in the relation. Choose primary key from these
• A candidate key is a column, or set of columns, in a table that
can uniquely identify any database record without referring to
any other data. Each table may have one or more candidate
keys, but one candidate key is unique, and it is called the
primary key. This is usually the best among the candidate keys
to use for identification.

27
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Keys

• Primary key (PK) is an attribute that uniquely


identifies any given row
• Composite key is a key composed of more than
one attribute eg in a Dependent table, Employee
number and Department number might be a
composite key
• Foreign key (FK) is an attribute whose values
match primary key values in the related table
Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 28
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

B. Keys - Example

Foreign key
232 and 235
Occur twice
In PRODUCT
table
Primary key in VENDOR table 29
Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

B. Keys - Composite

Primary key in VENDOR table 30


Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

B. Keys and determination

• 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 eg Student number → Student name
– Functional dependence – Attribute B is functionally dependent
on attribute A, if each value in column A determines one and only
one value in column B e.g. unique

31
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

B. Keys – Avoid 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

32
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

B. Keys - Redundancy
• Controlled redundancy
– Tables within the database share primary/foreign keys 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, for
example the foreign key
– Redundancy exists only when there is duplication of
attribute values
– Having a foreign key means that you do not duplicate the
attributes in the table to which the foreign key links this
table. Therefore, it controls redundancy
33
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

B. Keys - Example

Foreign key
232 and 235
Occur twice
In PRODUCT
table
Primary key in VENDOR table 34
Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 35
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

C. Integrity
• Two types
1. Entity integrity
2. Referential integrity

1. Entity integrity
– Ensures that each row is uniquely identified by the primary
key.
– It means that a proper search for an existing row will
always be successful.
– The failure to find a match on a row search will always
mean that the row for which the search is conducted does
not exist in that table.

36
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
C1. Entity Integrity question
Coronel & Crockett 9781844807321)

– Question: Based on the database


shown in Figure 1, do the tables
exhibit entity integrity? Answer yes
or no and explain your answers.
– Answer: PLAN table does not
display entity integrity because one
Plan_Code value is Null.
Plan_Code is the primary key and
a primary key cannot be null.

37
DATABASE SYSTEMS: Design Implementation and Management (Rob,
C2. Referential Integrity
Coronel & Crockett 9781844807321)
2

– Referential integrity concerns how 2 tables reference each


other.
• This is through the foreign key (FK)
• FK can EITHER be null or must be a valid entry in the table to which
it is related
• E.g. it must reference an existing primary key value
– Purpose:
• It IS possible for an attribute NOT to have a corresponding value,
but it will be impossible to have an invalid entry
Example
• A customer may not yet have an assigned sales representative
(number)
• but it will be impossible to have an invalid sales representative
(number)

38
C2. Referential Integrity
DATABASE SYSTEMS: Design Implementation and Management (Rob,
Coronel & Crockett 9781844807321)
2

Integrity RulesEdition, - Example


Source: Database Systems: Design, Implementation, &
Management, International Rob, Coronel & Crockett

null

No nulls or duplicates in PKs Valid FKs

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 39
C2. Referential Integrity
DATABASE SYSTEMS: Design Implementation and Management (Rob,
Coronel & Crockett 9781844807321)
2
question
• Based on the database shown in
Figure 2, do the tables exhibit
referential integrity? Answer yes
or no and explain your answers.
Write NA (Not Applicable) if the
table does not have a foreign key.

40
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

D. The Data Dictionary and System Catalog

• Data dictionary
– Provides detailed accounting of all tables found within
the database
– Contains (at least) all the attribute names and
characteristics for each table in the system
– Hence, it contains metadata—data about data

41
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

D. A Sample Data Dictionary

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 42
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

D. The Data Dictionary and System Catalog


• System catalogue
– Is a detailed system data dictionary
• describes all objects within the database
• including data about table names, the table’s creator & creation date
• number of columns in each table, the data type of each column
• index filenames, index creators
• authorized users and access privileges
– Generally the DBMS only provides a system catalogue from
which the database designer can construct his/her data
dictionary

43
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

G. Indexes
• Arrangement used to logically access rows in a table like
finding a book in the library or a topic in a book

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 44
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Index

• An index is composed of an index key and a set of


pointers
– Index key is an index’s reference point. Eg the primary key
– Pointers are identifiers, eg numbers that point to the data location
identified by the key

• A unique index is one in which the index key can


have only one pointer value (row) associated with
it

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 45
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

E. Relationships within the Relational


Database

E1. 1:* relationship


– Relational modeling ideal
– Should be the norm in any relational database design

E2. 1:1 relationship


– Should be rare in any relational database design

E3. *:* relationships


– Cannot be implemented as such in the relational model
– *:* relationships can be changed into two 1:* relationships

46
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

E1. The 1:* Relationship

• Relational database norm


• Found in any database environment

47
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

E1. The 1:* Relationship

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 48
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

E2. The 1:1 Relationship


• 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

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 49
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

E2. The 1:1 Relationship

50
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

E3. The *:* Relationship

• Can be implemented by breaking it up to produce


a set of 1:* relationships
• Can avoid problems inherent to *:* relationship
by creating a composite entity or bridge entity

51
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

E3. The *:* Relationship

52
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

H. Codd’s Relational Database Rules

• In 1985, E F Codd published a list of 12 rules to


define a relational database system
• The reason was the concern that many vendors
were marketing products as “relational” even
though those products did not meet minimum
relational standards

53
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 54
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Dr. Codd's 12 Relational Database Rules
1) Information – All data must be stored in tables
2) Guaranteed Access – Access every value using Table + Column + Key
3) Systematic treatment of nulls – Nulls must be represented and treated in a
systematic way, independent of data type.
4) Dynamic on-line catalogue based on the relational model – The metadata
must be stored and managed as ordinary data, that is, in tables within the database.
Such data must be available to authorized users, using the standard database
relational language.
5) Comprehensive data sublanguage – The relational database may support many
languages. However it must support one well-defined declarative language with
support for data definition, view definition, data manipulation (interactive and by
program), integrity constraints, authorization and transaction management (begin,
commit and rollback)
6) View updating – Any view that is theoretically updatable must be updatable
through the system 55
Dr. Codd's 12 Relational Database Rules2
DATABASE SYSTEMS: Design Implementation and Management (Rob,
Coronel & Crockett 9781844807321)
7) High-level insert, update and delete – The database must support set-level
inserts, updates and deletes
8) Physical data independence – Application programs and ad hoc facilities are
logically unaffected when physical access methods and storage structures are
changed
9) Logical data independence – Application programs and ad hoc facilities are
logically unaffected when changes are made to the table structures that preserve
the original table values (changing order of column or inserting columns)
10) Integrity independence – All relational integrity constraints must be definable
in the relational language and stored in the system catalog, not at the application
level
11) Distribution independence – The end users and application programs are
unaware and unaffected by the data location (distributed vs local databases)
12) Non-subversion – If the system supports low-level access to the data, there
must not be a way to bypass the integrity rules of the database
Rule Zero – All preceding rules are based on the notion that in order for a
database to be considered relational, it must use its relational facilities exclusively
to Database
manage the Design,
Systems: database.
Implementation, & Management, International Edition, Rob, Coronel & Crockett 56
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)

Database Systems: Design, Implementation, & Management, International Edition, Rob, Coronel & Crockett 57

You might also like