You are on page 1of 76

RELATIONAL DATA MODEL

DFC20123 – DATABASE DESIGN


EXPLAIN RELATIONAL DATABASES
2.1.1 DEFINE THE RELATIONAL DATABASES AND RDBMS
2.1.2 IDENTIFY SOME POPULAR RDBMS PACKAGES
2.1.3 DESCRIBE THE COMPONENTS OF A RELATIONAL DATABASE STRUCTURAL
TERMINOLOGY
2.1.4 IDENTIFY THE APPLICATION AREAS OF RBMS: AIRLINES, BANKING, UNIVERSITIES,
TELECOMMUNICATIONS ETC.
2.1.5 IDENTIFY THE PROPERTIES OF TABLES IN A RELATIONAL DATABASE
2.1.6 DESCRIBE THE CHARACTERISTICS OF RELATION SCHEME
2.1.7 DESCRIBE A RELATION INSTANCE
2.1.8 EXPLAIN RELATION KEYS: PRIMARY KEY, CANDIDATE KEY, AND FOREIGN KEY
2.1.9 EXPLAIN TWO IMPORTANT INTEGRITY RULES: ENTITY INTEGRITY & REFERENTIAL INTEGRITY
2.1.10 APPLY THE CONCEPTS OF RELATIONAL DATABASE USING AN APPROPRIATE DESKTOP DATABASE
BY
CREATING TABLES
2.1.1 RELATIONAL DATABASES AND RDBMS

RELATIONAL DATABASE RDBMS


• A relational database is a type of database • Relational Database Management System.
 that stores and provides access to data • The basis for SQL, and for all modern
points that are related to one another. database systems like MS SQL Server,
• Relational databases are based on the IBM DB2, Oracle, MySQL, and Microsoft
relational model, an intuitive, Access.
straightforward way of representing data in • A database management system (DBMS)
tables. that is based on the relational model as
• In a relational database, each row in the introduced by E. F. Codd.
table is a record with a unique ID called • RDBMS store data in the form of tables,
the key. The columns of the table hold with most commercial relational database
attributes of the data, and each record management systems using 
usually has a value for each attribute, Structured Query Language (SQL) to
making it easy to establish the relationships access the database.
among data points. • Provides a dependable method of storing
and retrieving large amounts of data while
offering a combination of system
performance and ease of implementation.
2.1.2 IDENTIFY SOME POPULAR RDBMS
PACKAGES
• A powerful database server that is • This operational database is • World’s most popular database • Developed by Microsoft is one of
made from MySQL developers. designed to deliver high that is open source and free. the most popular databases in the
performance, actionable insights, MySQL was acquired by Oracle world.
data availability, and reliability, as a part of Sun Microsystems • Initially launched in 1989 and
and it is supported across Linux, acquisition in 2009 written in C, C++, SQL Server is
Unix, and Windows operating now widely used among major
systems. companies.

SQL
MariaDB IBM DB2 MySQL
SERVER

• The origins of PostgreSQL date • MS Access still remains one of • A C-language library that • A general-purpose relational
back to 1986 as part of the the top 10 databases for local data implements a small, fast, self- database-as-a-service (DBaaS)
POSTGRES project at the storages. contained, high-reliability, full- based on the latest stable version
University of California at • Access is usually not used in featured, SQL database engine of Microsoft SQL Server
Berkeley and has more than 30 remote or centralized storage. It is Database Engine
years of active development on used for local small databases
the core platform. The current
version of PostgreSQL is 11.4 that
was released on 20 June 2019

PostgreSQ Microsoft
SQL Lite Azure SQL
L Access
2.1.3 DESCRIBE THE COMPONENTS OF A RELATIONAL
DATABASE STRUCTURAL TERMINOLOGY
COMPONENTS OF A RELATIONAL DATABASE

 a. Relation (Table)
 b. Tuple (Row of record)
 c. Cardinality of a Relation (Number of rows)
 d. Attribute (Column or field)
 e. Degree of a relation (Number of columns)
 f. Primary key (Unique identifier)
 g. Domain (Pool of values of specific attributes of relation)
Relation
RELATION
• A table (TABLE)
is the same as a record, which is the fundamental data component.
• Comprised of a set of fields that are the same in every table or record,
such as the name, address and product of the customer.

Tuple
• A tuple is a row of a relation

Cardinality
• The number of tuples its contains.
• Example : If Branch relation have 5 number of tuples, the cardinality of
Branch relation is 5.
Attribute
• Named column of relation.
Degree
RELATION (TABLE)
• The degree of relation is the number of attributes it contains.
• Example : Student relation that have four attributes, so the degree is four.

Primary Key
• Is an attributes that uniquely identify each rows.

Domain
• Set of possible values for an attribute.
• Each simple attribute of entity is associated with value set (domain of
values).
• It specify the sets value that may be assigned to that attribute for each
individual entity.
• Example : Given an attribute named Gender, the domains are MALE and
FEMALE
2.1.4 IDENTIFY THE APPLICATION AREAS OF
RDBMS

• For customer information, accounts, and loans, and banking

Banking transactions.

• For reservations and schedule information. Airlines were among

Airlines the first to use databases in a geographically distributed manner –


terminals situated around the world accessed the central database
system through phone lines and other data networks.

• For keeping records of calls made, generating monthly bills,

Telecommunication maintaining balances on prepaid calling cards, and storing


information about the communication networks.

• For student information, course registrations, and grades

Universities
2.1.5 PROPERTIES OF TABLES IN A
RELATIONAL DATABASE

Data is presented as a collection of


Each relation is depicted as a table.
relations

Each row ("tuple") represents a single


Columns are attributes that belong to
entity (ex. In a student table, John
the entity modeled by the table (ex. In a
Smith, 14 Oak St, 9002342,
student table, you could have name,
Accounting, would represent one
address, student ID, major, etc.).
student entity).

Every table has a set of attributes that taken


together as a "key" (technically, a "superkey")
uniquely identifies each entity (Ex. In the
student table, “student ID” would uniquely
identify each student – no two students would
have the same student ID).
2.1.6 CHARACTERISTICS OF RELATION
SCHEME
 WHAT IS RELATION SCHEME?
 A named of relation define by a set of attributes and domains name pairs.

Relation Name
Relation name is distinct from all other relation names in relational
schema.
Cannot have two Student relation in the database

Attribute Name
Each attribute has a distinct name
Order of attributes has no significance
Order or tuples has no significance, theoretically

Domains

Values of an attribute are all from the same domain


RELATION SCHEME
RELATIONAL DATABASE SCHEMA
RELATIONAL DATABASE SCHEMA

 The relational database schema also can be represented as


follow :
 The primary key is underlined.
2.1.7 DESCRIBE A RELATION INSTANCE

 A tuple at a specific moment of time


 Example : Branch (BranchNo, Street, City, PostalCode)
 The relation instance for Branch is :
(B005, 55 Jln Dobi, Johor Bahru, 80100)
(B006, 55 Jalan Perai, Kota Tinggi, 80000)
 The relation instance change when tuple is updated, deleted
or inserted.
GROUP ACTIVITY

 Create a relational database schema for Politeknik Mersing


2.1.8 RELATION KEYS
2.1.8 RELATION KEYS

 PRIMARY KEY
 A column or group of columns in a table which helps us to
uniquely identifies every row in that table is called a
primary key.
 The same value can't appear more than once in the table.
 Rules for defining Primary key:
 Two rows can't have the same primary key value
 It must for every row to have a primary key value.
 The primary key field cannot be null.
 The value in a primary key column can never be modified or updated if
any foreign key refers to that primary key.
PRIMARY KEY

Example : In the following example, StudID is a Primary Key.


2.1.8 RELATION KEYS

 CANDIDATE KEY
 A super key with no repeated attribute is called candidate key.
 The Primary key should be selected from the candidate keys.
 Every table must have at least a single candidate key.
 Properties of Candidate key:
 It must contain unique values
 Candidate key may have multiple attributes
 Must not contain null values
 It should contain minimum fields to ensure uniqueness
 Uniquely identify each record in a table
CANDIDATE KEY
2.1.8 RELATION KEYS

FOREIGN KEY
 A foreign key is a column which is added to create a relationship with
another table.
 Foreign keys help us to maintain data integrity and also allows
navigation between two different instances of an entity.
 Every relationship in the model needs to be supported by a foreign
key.
FOREIGN KEY

FOREIGN KEY

In this example, we have two table, teach and department in a school.


Adding the foreign key in Deptcode to the Teacher name, we can create a
relationship between the two tables.
2.1.8 RELATION KEYS

ALTERNATE KEY
 All the keys which are not primary key are called an alternate key. It is a
candidate key which is currently not the primary key. However, A table may
have single or multiple choices for the primary key.
 Example: In this table.
 StudID, Roll No, Email are qualified to become a primary key. But since
StudID is the primary key, Roll No, Email becomes the alternative key.
COMPONENT OF RELATIONAL SCHEMA
GROUP ACTIVITY
2.1.9 EXPLAIN TWO IMPORTANT INTERGRITY
RULES
INTEGRITY
REFERENTIAL INTERGRITY
REFERENTIAL INTERGRITY
2.1.10 APPLY THE CONCEPTS OF RELATIONAL DATABASE USING
AN APPROPRIATE DESKTOP DATABASE BY CREATING TABLES

A relational database stores data in tables (relation), which are organized into
columns (attributes). Each column stores one datatype (integer, real number, string,
date etc.) and each row (tuple) represents an instance of the table. 
EXPLAIN OPERATORS OF RELATIONAL
ALGEBRA
2.2.1 DESCRIBE THE RELATIONAL ALGEBRA
2.2.2 IDENTIFY THE FUNDAMENTAL OPERATORS USED TO RETRIEVE INFORMATION
FROM A RELATIONAL DATABASE2.2.3 DESCRIBE THE PURPOSE AND INPUT OF EACH
OF THE OPERATORS AND EXPRESSION
2.2.4 WRITE THE EXPRESSIONS BY USING THE OPERATORS BASED ON RELATIONAL
TABLES GIVEN
2.2.5 ILLUSTRATE THE EXPRESSION OUTPUT
2.2.6 DEFINE THE TRADITIONAL SET OF OPERATORS FOR RELATIONAL TABLES: A.
UNION B. INTERSECTION C. DIFFERENCE
2.2.7 DEFINE UNION COMPATIBILITY
2.2.8 ILLUSTRATE THE UNION, INTERSECT, AND DIFFERENCE SET OPERATORS BASED
ON TABLES GIVEN
2.2.1 DESCRIBE THE RELATIONAL
ALGEBRA
 A collection of operators that
 Are defined on relations
 Produce relations as results
 Can be combined to form complex expressions

 Operators:
 To retrieve information : Restrict, Project, Join, Cross
Product
 Traditional set theory: Union, Intersection, Difference
RELATIONAL ALGEBRA
 Symbolic notation to represent the operators:
 SELECT σ (sigma)
 PROJECT  (pi)
 PRODUCT  (times)

  JOIN ⋈
(bow-tie)
 UNION  (cup)
 INTERSECTION  (cap)
 DIFFERENCE - (minus)
2.2.2 IDENTIFY THE FUNDAMENTAL OPERATORS USED TO
RETRIEVE INFORMATION FROM A RELATIONAL DATABASE

SELECT
 The selection or  operation selects rows from a table that satisfy a condition
 The SELECT operation can be viewed as a horizontal filter of the relation.

 It partitions the input relation into two sets of tuples(rows):


those tuples(rows) that satisfies the condition are select, those do not satisfy the
condition are discarded.
SELECT USAGE
 The symbolic operators are used as with the verbal ones. So, to find all
employees in department 1:
SELECT depno = 1 (employee)
becomes: σ depno = 1 (employee)

 Conditions can be combined together using ^ (AND) and v (OR). For


example, all employees in department 1 called `Smith':
SELECT depno = 1 ^ surname = `Smith‘ (employee)
becomes: σ depno = 1 ^ surname = `Smith‘ (employee)
SELECT EXAMPLE
SELECT EXAMPLE
SELECT EXAMPLE
 Example :

Retrieve the Id, Name, Suburd of student who’s name is Mary or


students who live in Bundoora
SELECT & PROJECT
PROJECT

 The PROJECT or  operation selects a list of columns from a table


 Selects some columns of the relation and discards the other
column.

 The PROJECT operation can be viewed as the vertical filter of the


relation.
PROJECT EXAMPLE
PROJECT EXAMPLE
PROJECT EXAMPLE

 Retrieve the name of the subjects and department which is


responsible for the subject
JOIN
 JOIN is used to combine related tuples from two relations:
 In its simplest form the JOIN operator is just the cross product of the
two relations.
 As the join becomes more complex, tuples are removed within the
cross product to make the result of the join more meaningful.
 JOIN allows you to evaluate a join condition between the attributes
of the relations on which the join is undertaken.
 Can be divided into two types :
 Inner Join
 Outer Join
INNER JOIN

 The most used operator in the relational algebra.


 In an inner join, only those tuples that satisfy the matching
criteria are included, while the rest are excluded. 
 Two main versions of the inner join:
 "natural" join: takes attribute names into account;
 "theta" join.
NATURAL JOIN

 A `natural join' will remove the duplicate attribute(s).


 In most systems a natural join will require that the
attributes have the same name to identify the attribute(s)
to be used in the join. This may require a renaming
mechanism.
 If you do use natural joins make sure that the relations do
not have two attributes with the same name by accident.
NATURAL JOIN EXAMPLE

• The tuples in the resulting


relation are obtained by
combining tuples in the operands
with equal values on the common
attributes.
• The common attributes often
form a key of one of the operands
(remember: references are
realized by means of foreign
keys, and we join in order to
follow references)
NATURAL JOIN EXAMPLE
THETA JOIN EXAMPLE

 Theta join combines tuples from different relations provided


they satisfy the theta condition. The join condition is denoted
by the symbol θ.

R1 ⋈θ R2

 Take the product R1 Χ R2. Then apply θ to the result.


 As for θ can be any boolean-valued condition.
OUTER JOIN
 Notice that much of the data is lost when applying a join to two
relations.
 In some cases, this lost data might hold useful information.
 An outer join retains the information that would have been lost
from the tables, replacing missing data with nulls.
 There are three forms of the outer join, depending on which data
is to be kept:
 LEFT OUTER JOIN - keep data from the left-hand table
 RIGHT OUTER JOIN - keep data from the right-hand table
 FULL OUTER JOIN - keep data from both tables
OUTER JOIN EXAMPLE
OUTER JOIN EXAMPLE
CROSS PRODUCT
 The PRODUCT operation combines tuples of one relation
with all the tuples of the other relation
CROSS PRODUCT EXAMPLE
CROSS PRODUCT EXAMPLE
2.2.3 DESCRIBE THE PURPOSE AND INPUT
EACH OF THE OPERATORS AND EXPRESSION.

 provides a formal foundation for relational model operations.


 and perhaps more important, it is used as a basis for implementing and
optimizing queries in the query processing and optimization modules that are
integral parts of relational database management systems (RDBMSs)
 some of its concepts are incorporated into the SQL standard query language for
RDBMSs.
 the set of relational algebra operations {σ, π, ∪, ρ, –,X} is a complete set; that is,
any of the other original relational algebra operations can be expressed as a
sequence of operations from this set.
2.2.4 WRITE THE EXPRESSION BY USING THE
OPERATORS BASED ON RELATIONAL TABLES GIVEN.
 EXAMPLE

1.

2.

3.
SOLUTION
1.

2.

3.
2.2.5 ILLUSTRATES THE EXPRESSION OUTPUT
 EXAMPLE

Figure out which relational algebra operations were used to obtain each of the
following tables.

a. b.
SOLUTION
2.2.6 DEFINE THE TRADITIONAL SET OF OPERATORS
FOR RELATIONAL ALGEBRA TABLES

UNION

 The UNION operation combines two union compatible


relations into a single relation via set union of sets of tuples.
 Notation: r1∪r2

Venn Diagram
UNION
UNION EXAMPLE
INTERSECTION

 The INTERSECTION operation combines two union compatible relations


into a single relation via set intersection of sets of tuples.
 Notation: r1∩r2

Venn Diagram
INTERSECTION
INTERSECTION EXAMPLE
DIFFERENCE

 The DIFFERENCE operation finds the set of tuples that exist in one relation but
do not occur in the other union compatible relation
 Notation: r1 \ r2

Venn Diagram
DIFFERENCE
DIFFERENCE EXAMPLE
2.2.7 DEFINE UNION COMPATIBILITY

 Two relations are union compatible if:


 They have the same number of attributes
 Each domain of each attribute in either relation has a
compatible domain in the other relation
2.2.8 ILLUSTRATE THE UNION, INTERSECT AND
DIFFERENCE SET OPERATORS BASED ON TABLE GIVEN

UNION
INTERSECT
DIFFERENCE / MINUS

You might also like