Chapter 3 - Data Relational Model
-
Upload
norzelan-saleh -
Category
Documents
-
view
235 -
download
0
Transcript of Chapter 3 - Data Relational Model
-
8/11/2019 Chapter 3 - Data Relational Model
1/42
CHAPTER 3 : DATA RELATIONAL MODEL
Prepared by : Norzelan bin Saleh
-
8/11/2019 Chapter 3 - Data Relational Model
2/42
-
8/11/2019 Chapter 3 - Data Relational Model
3/42
A database is a collection of information that is organized sothat it can easily be accessed, managed, and updated.
In one view, databases can be classified according to types of
content: bibliographic, full-text, numeric, and images.
What is Database?
-
8/11/2019 Chapter 3 - Data Relational Model
4/42
Table: two-dimensional structure composed of rows andcolumns
Components of database table are :Record (tuple) - is a sequence of attributes i.e. a row in the relationtable.
Attribute (field) - is a named column in the relation table.
Domain - The domain of an attribute defines the set of values which canapply to that attribute.
Degree - The degree of a relation refers to the number of attributes in
each tuple.Cardinality - This refers to the number of tuples in the relation
Components of Database Table
-
8/11/2019 Chapter 3 - Data Relational Model
5/42
-
8/11/2019 Chapter 3 - Data Relational Model
6/42
-
8/11/2019 Chapter 3 - Data Relational Model
7/42
Relation Schema: relation name + attribute names + domain
Relation name
Attribute name
Domains
Characteristic of Relation Scheme
-
8/11/2019 Chapter 3 - Data Relational Model
8/42
Consists of one or more attributes that determine otherattributes.
Keys
Primary Key - Primary key (PK) is an attribute (or acombination of attributes) that uniquely identifies any givenentity (row)
Superkey - Any key that uniquely identifies each row
Candidate key - A superkey without redundancies
Composite key - Composed of more than one attribute
Foreign key a field in a relational table that matches theprimary key column of another table. The foreign key can beused to cross-reference tables
-
8/11/2019 Chapter 3 - Data Relational Model
9/42
-
8/11/2019 Chapter 3 - Data Relational Model
10/42
-
8/11/2019 Chapter 3 - Data Relational Model
11/42
Entity Integrity
Referential Integrity - FK contains a value that refers to an existing validtuple (row) in another relation
Integrity Rules
-
8/11/2019 Chapter 3 - Data Relational Model
12/42
-
8/11/2019 Chapter 3 - Data Relational Model
13/42
Relational Model Relationship
-
8/11/2019 Chapter 3 - Data Relational Model
14/42
One entityrelated toanother ofthe sameentity type
Entities oftwo differenttypes relatedto each other
Entities of three
different typesrelated to eachother
-
8/11/2019 Chapter 3 - Data Relational Model
15/42
Each entity in the relationship will have exactly one relatedentity
One to Many Relationship
-
8/11/2019 Chapter 3 - Data Relational Model
16/42
-
8/11/2019 Chapter 3 - Data Relational Model
17/42
Entities on both sides of the relationship can have many relatedentities on the other side
Many to Many Relationship
-
8/11/2019 Chapter 3 - Data Relational Model
18/42
-
8/11/2019 Chapter 3 - Data Relational Model
19/42
Converting the M:N relationship into TWO 1:M relationships
Foreign keys reference the primary keys in the other
tables of which it has a relationship with
The database designer has 2 main options to definea composite tables primary key: either
use the combination of those foreign keys orcreate a new primary key.
-
8/11/2019 Chapter 3 - Data Relational Model
20/42
Self-referencing relationships are a special case of a normal
table relationship.
The only difference is that in this case, there is only one tableinvolved and it is on both sides of the relationship.
Example :One common example is an Employees table that contains informationabout the supervisor of each employee. Each supervisor is also anemployee and has his or her own supervisor. In this case, there is a one-to-many self-referencing relationship, as each employee has onesupervisor but each supervisor may have more than one employee.
Self Referencing Relationship
-
8/11/2019 Chapter 3 - Data Relational Model
21/42
-
8/11/2019 Chapter 3 - Data Relational Model
22/42
Relational algebra
Defines theoretical way of manipulating table contents using relationaloperators
Use of relational algebra operators on existing tables (relations)produces new relations
Relational Database Algebra
Restrict (select) Project
Join (outer, inner)Cartesian Product
-
8/11/2019 Chapter 3 - Data Relational Model
23/42
Yields values for all rows found in a table
Can be used to list either all row values or it can yield only those rowvalues that match a specified criterion
Yields a horizontal subset of a table
Select
-
8/11/2019 Chapter 3 - Data Relational Model
24/42
-
8/11/2019 Chapter 3 - Data Relational Model
25/42
Yields all values for selected attributes
Yields a vertical subset of a table
Project
-
8/11/2019 Chapter 3 - Data Relational Model
26/42
-
8/11/2019 Chapter 3 - Data Relational Model
27/42
Allows information to be combined from two or more tables
Real power behind the relational database, allowing the use of
independent tables linked by common attributes
Join
-
8/11/2019 Chapter 3 - Data Relational Model
28/42
-
8/11/2019 Chapter 3 - Data Relational Model
29/42
Outer join:
Matched pairs are retained and any unmatched values in other tableare left null
In outer join for tables CUSTOMER and AGENT, two scenarios arepossible:
Left outer joinYields all rows in CUSTOMER table, including those that do nothave a matching value in the AGENT table
Right outer join
Yields all rows in AGENT table, including those that do not havematching values in the CUSTOMER table
-
8/11/2019 Chapter 3 - Data Relational Model
30/42
-
8/11/2019 Chapter 3 - Data Relational Model
31/42
-
8/11/2019 Chapter 3 - Data Relational Model
32/42
Inner Join
An inner join (sometimes called a simple join) is a join of two or more
tables that returns only those rows that satisfy the join condition.
Traditional inner joins look for rows that match rows in the othertable(s), i.e. to join two tables based on values in one table being equalto values in another table
Also known as equality join, equijoin or natural join
Returns results only if records exist in both tables
-
8/11/2019 Chapter 3 - Data Relational Model
33/42
-
8/11/2019 Chapter 3 - Data Relational Model
34/42
Database Systems: Design, Implementation, &
Relational Algebra Operators (continued) Union:
Combines all rows from two tables, excluding duplicaterows
Tables must have the same attribute characteristics Intersect:
Yields only the rows that appear in both tables
-
8/11/2019 Chapter 3 - Data Relational Model
35/42
Database Systems: Design, Implementation, & Management, 7th
Edition, Rob & Coronel
Relational Algebra Operators(continued)
-
8/11/2019 Chapter 3 - Data Relational Model
36/42
Database Systems: Design, Implementation, & Management, 7th
Edition, Rob & Coronel
Relational Algebra Operators(continued)
-
8/11/2019 Chapter 3 - Data Relational Model
37/42
Database Systems: Design, Implementation, &
Relational Algebra Operators (continued) Difference
Yields all rows in one table not found in the othertable that is, it subtracts one table from theother
Product Yields all possible pairs of rows from two tables
Also known as the Cartesian product
-
8/11/2019 Chapter 3 - Data Relational Model
38/42
Database Systems: Design, Implementation, & Management, 7th
Edition, Rob & Coronel
Relational Algebra Operators
(continued)
-
8/11/2019 Chapter 3 - Data Relational Model
39/42
Database Systems: Design, Implementation, & Management, 7th
Edition, Rob & Coronel
Relational Algebra Operators(continued)
-
8/11/2019 Chapter 3 - Data Relational Model
40/42
Database Systems: Design, Implementation, & Management, 7th
Edition, Rob & Coronel
Relational Algebra Operators(continued)
-
8/11/2019 Chapter 3 - Data Relational Model
41/42
Database Systems: Design, Implementation, &
Relational Algebra Operators (continued)
DIVIDE requires the use of one single-columntable and one two-column table
-
8/11/2019 Chapter 3 - Data Relational Model
42/42
th
Relational Algebra Operators
(continued)