Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

2. Relational Database Model

This document covers the relational database model, focusing on its logical view of data, key components such as entities and attributes, and the organization of data into tables. It discusses the importance of keys for data integrity, including primary and foreign keys, as well as relational operators for manipulating data. Additionally, it highlights the role of data dictionaries and system catalogs in managing database information and reducing redundancy.

Uploaded by

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

2. Relational Database Model

This document covers the relational database model, focusing on its logical view of data, key components such as entities and attributes, and the organization of data into tables. It discusses the importance of keys for data integrity, including primary and foreign keys, as well as relational operators for manipulating data. Additionally, it highlights the role of data dictionaries and system catalogs in managing database information and reducing redundancy.

Uploaded by

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

MICT713

Advanced Database
Management Systems
SNO Devine
Department of ICT & Mathematics
Presbyterian University, Ghana
The Relational Database
Model
Relational model concepts, Entities and Attributes,
Keys and Integrity issues, Data dictionary, and
System catalog
In this chapter, you will learn:
• That the relational database model takes a logical
view of data
• That the relational database model’s basic
components are entities and their attributes, and
relationships among entities
• How entities and their attributes are organized
into tables
• How various keys are defined and data integrity is
enforced for data consistency.

3
In this chapter, you will learn:
• About relational database operators, the data
dictionary, and the system catalog
• How data redundancy is handled in the relational
database model
• Why indexing is important

4
Logical View of Data

• Relational Database
• Designer focuses on logical representation
rather than physical
• Use of table advantageous
• Structural and data independence
• Related records stored in independent tables
• Logical simplicity
• Allows for more effective design strategies

5
Logical View of Data (con’t.)
• Entities and Attributes
• Entity is anything about which data is collected
and stored.
• It can be seen as any object in a system (real world)
that we want to model and store information about.
• Entities are usually recognizable concepts, either
concrete or abstract, such as person, places, things, or
events which have relevance to the database. Some
specific examples of entities are Employee, Student,
etc. An entity is analogous to a table in the relational
model.
• The convention is to use singular names when
identifying entities.
6
Logical View of Data (con’t.)
• Entities and Attributes
• Attributes are characteristics of the entity.
• An Attribute is an item of information which is
stored about an entity. For example, the entity
‘Employee’ could have attributes such as staff
id, surname, other name, date of birth, etc.
• An attribute can only appear in one entity,
unless it is the key attribute in another entity.
• In a traditional filing system an attribute
equates to a field in a record.

7
Logical View of Data (con’t.)
• Tables
• called relations in the relational model
• also described as entity type, a collection of
entities with general characteristics.
• Comprised of rows and columns
• Holds related entities or entity set
• Entity set is/are a collection of entities with common
characteristics (rows)
• Each row is an occurrence or an instance of the entity.
As such a row is referred to as an entity occurrence. For
example, in the student entity, the information about
each individual student’s detail is an entity occurrence.
Each entity occurrence is also unique and distinct.
• In the file system a table is a file whilst row also
referred to as a record
8
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
row
• Column values all have same data format
• Each column has range of values called attribute domain
• Order of the rows and columns is immaterial to the
DBMS

9
Relation/Entity Type Column (attribute) value

Tuple/

Entity set/ Records


Row/
Entity
occurrence

Tuples/
10
Relational terminology

Relational term SQL equivalent

relation, base relvar table

derived relvar view, query result, result set

tuple row

attribute Column

11
Exercise
• A new database system is to be designed at you’re
an institution.
1. Identify an institution of your choice
2. Make a list of at least 5 entities that are of
importance to that system.
3. Also list possible attributes for any three of the
entities you have chosen.

NOTE: Remember that the convention for naming an entity is to use a


singular name

12
Data types
• The relational model
• provides avenue for diverse description or
identification of data.
• does not dictate what types are to be supported by
any DBMS that implements the relational DBM.
• Thus, each DBMS recognizes its own set
of datatypes.
• Data types:
• is a description of the kind of data in a table column.
• Numeric – set of numbers e.g. int, bigInt, float, decimal,
number
• Character – set of characters/String e.g. Char, Varchar, Text
• Date – set of date and time e.g. Date, Time, TimeStamp
• Logical – set of logical values such as Yes/No, True/False
13
Keys
• A key is a data item that is used to uniquely
identify individual occurrences, instances
or an entity type.
• It can be viewed as an entity identifier.
• You can sort and quickly retrieve information
from a database by choosing one or more fields
(i.e. attributes) to act as keys.
• For instance, in a student's table you could use
the index number or a combination of the last
name and first name fields (or perhaps last
name, first name and birth dates to ensure you
identify each student uniquely) as a key field.
• Key attribute is an attribute that is part of a key. 14
Keys (con’t.)
• Superkey
• Set of one or more attributes that uniquely identifies
each entity
• Example: (any of the following may be a superkey)
• STU_NUM
• STU_NUM, STU_LNAME
• STU_NUM,STU_LNAME, STU_INIT redundant

• Candidate key
• Minimal superkey (without redundancies)
• Example: STU_NUM
• Primary key
• Candidate key to uniquely identify all other attributes in
a given row
• Is, therefore, one or more attributes that uniquely
identifies a record.
20
Keys (con’t.)
• Foreign key: an attribute whose values match
the primary key in the related table. (Example
in the previous figure 2.2)
• Values must match primary key in another table

• Secondary key
• Used only for data retrieval
• Example, in a CUSTOMER table, the CUS_ID which
the primary key may be known for easy record
retrieval. So other details for easy referencing like
CUS_LNAME and CUS_PHONENO can be used to
locate other details about the customer.

21
22
Keys (con’t.)
• A Primary Key (PK)
• can be further described based on its composition and
characteristics.
• can be made up of one attribute or several attributes.
• A PK can be described as a
• Simple Key – formed by ONLY one unique attribute.
• E.g. Index Number, Course Code, Passport Number, Voter ID
Number
• Compound Key – combination of foreign keys
• E.g. Index Number and Course Code, Passport Number and Seat
Number, Voter ID Number and Candidate Number
• Composite Key – made up of foreign keys and other non-
unique attribute(s)
• Index Number and Surname, Movie Number and Seat Number
23
Keys (con’t.)
• Entity integrity
• Within a table, the primary key must be unique
• No ‘null’ value in key:
• can be unknown value, missing or not applicable

• Referential integrity (RI)


• Table exhibits RI if a foreign key contains a value,
which refers to an existing row in another table.
Example, referential integrity maintained between
PRODUCT and VENDER tables.

27
Figure 2.2
28
29
Integrity Rules
• Entity integrity
• Requirement (Ensures all entities are unique): all
primary key entries are unique; no null value
• Each entity has unique key
• Referential integrity
• Foreign key must match primary key values
• Makes it impossible to delete row whose primary key
has mandatory matching foreign key values in another
table

30
No null entries

31
Relational Database Operators
• Relational algebra defines the theoretical way of
manipulating table contents using the eight
relational operators, or relational algebra
determines table manipulations
• Key operators
• SELECT
• PROJECT
• JOIN
• Other operators
• INTERSECT
• UNION
• DIFFERENCE
• PRODUCT
• DIVIDE

32
UNION
 Tables must have the same attribute
characters (column and domains must
be identical)
 That is these tables are UNION-
compatible
 Combines all rows
 Example:

33
UNION

Figure 2.5

34
INTERSECT
 Tables must be UNION-compatible
 Yield rows that appear/occur in both tables
 Example:

Yields rows that appear in both tables

35
DIFFERENCE
 Tables must be UNION-compatible
 Find rows in one table that are not
found in the other table.
 Example:

Yields rows not found in other tables

Figure 2.7

36
PRODUCT
 Yields all possible pairs of rows from
two tables
 Also called the Cartesian product,
yields a list composed of row in one
table * each row in other table
 Example:

37
PRODUCT

Figure 2.8

38
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:

39
SELECT

40
PROJECT
 Project yields a vertical subset of a
table, i.e. all values for selected
attributes
 Example:

41
PROJECT

Figure 2.10
42
JOIN
 Combine information from multiple tables
 Real power behind RDBM, allowing use of
independent tables linked by common attributes
 Natural join process
 Product
 Select
 Project
 Example:

43
JOIN

Figure 2.11

Figure 2.14

44
Natural JOIN Process
• Links tables by selecting rows with common
values in common attribute(s)
• Three-stage process
• Product creates one table
• Select yields appropriate rows
• Project yields single copy of each attribute to eliminate
duplicate columns

45
PRODUCT Process in JOIN

46
47
SELECT Process in JOIN

48
PROJECT Process in JOIN

49
Data Dictionary and System Catalog
• Data dictionary
• Provides detailed account of all tables found within
database
• Metadata(data about data)
• Attribute names and characteristics
• All members of database design and implementation
teams use the same table, attributes and characteristics
• DBMS internally store data dictionary and additional
information containing relationship types, entity and
referential integrity check and enforcement, index
types and components. The additional information is
generated during the database design implementation
stage.
• Database designer’s database
50
51
Data Dictionary and System Catalog
• System catalog
• Detailed data dictionary; current relational database
software provides only a system catalog
• Data dictionary can be derived from

• System-created database, whose tables can be queried;


database documents allowing RDBMS check for and
eliminate homonyms (same name for different attributes)
and synonyms (different names for same attribute)
• Good attribute naming conventions facilitate relationship setting

• Stores database characteristics and contents


• Tables can be queried just like any other tables
• Automatically produces database documentation

52
Data Redundancy Revisited
• Foreign keys can reduce redundancy
• Some redundancy is desirable
• controlled redundancy
• Speed
• Information requirements

53

You might also like