DFC20203
DATABASE DESIGN
CHAPTER 2: RELATIONAL DATA MODEL
2.1 Explain relational databases
2.2 Explain operators of relational algebra
CLO
1. Apply fundamental of DBMS, relational data model and normalization
concepts in database development process. (C3, PLO2)
2. Show a well-structured database using the database query to
manipulate a database with an appropriate commercial Database
Management System (DBMS) in solving an organization’s
requirements. (P2, PLO3)
CHAPTER 2:
RELATIONAL DATA MODEL
2.1 Explain relational data-
bases
What is relational database?
A relational database is a collective set of multiple data sets
organized by tables, records and columns.
It establish a well-defined relationship between database tables.
Tables communicate and share information, which facilitates data
search ability, organization and reporting.
Relational database use Structured Query Language (SQL),
which is a standard user application that provides an easy
programming interface for database interaction.
Relational database is derived from the mathematical function
concept of mapping data sets and was developed by
Edgar F. Codd.
Example of relational database:
What is RDBMS?
RDBMS – Relational Database Management System.
RDBMS is a database management system based on relational
model defined by E.F. Codd.
The data in an RDBMS is stored in database objects which are
called as tables.
This table is basically a collection of related data entries and it
consists of numerous columns and rows.
Most RDBMS use SQL as database query language.
The most popular RDBMS are MS SQL Server, DB2, Oracle and
MySQL.
http://www.databasedir.com/what-is-rdbms/
https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm
Example of table:
Carlos Coronel, Steven Morris (2016), Database Systems: Design, Implementation & Management (12th edition),
Course Technology Ptr(US). (page 75)
Example of RDBMS: MySQL
Example of RDBMS: MS Access
Application areas of RDBMS
Airlines
Banking
Universities
Telecommunications
Others?
Components of Relational
database
1) Relation (table)
2) Tuple (row / record)
3) Attribute (column / field)
4) Cardinality (number of rows)
5) Degree (number of columns)
6) Key (Primary key ,
candidate key, foreign key)
7) Domain (a set of values
allowed in an attribute)
Characteristics of a relational
table
Carlos Coronel, Steven Morris (2016), Database Systems: Design, Implementation & Management (12th edition),
Course Technology Ptr(US). (page 74)
Relation scheme
• A relation schema is essentially a list of column
names with their data types. For example:
• Students (name : string, ICNo : string,
street : string, city : string)
• Relation schema can be thought of as the basic
information describing a table or relation.
• Relation scheme consists of:
a) Relation name
b) Attribute name
c) Domains (attribute type)
Example of relation scheme
department (dept_name: char, building: char, budget: integer)
Abraham, S., Korth, H. F., and & S. Sudarshan, (2012), Database System Concepts (Sixth Edition), McGraw Hill Higher Edu-
cation, USA. (page 43)
Relation instance
Relational Keys
Relational Keys
Relational Keys
Relational Keys
Relational integrity
Relational integrity constraint is used to
ensure accuracy and consistency of data in a
relational database.
Two types of relational integrity:
Entity integrity
Referential integrity
Relational integrity
Relational integrity
For Motivation…
Demo:
How to create database and tables using
Microsoft Access.
CHAPTER 2:
RELATIONAL DATA MODEL
2.2 Explain operators of rela-
tional algebra
Relational algebra
The Relational Algebra was introduced by E. F. Codd
in 1972.
It consists of a set of operations on relations.
Defines theoretical way of manipulating table contents using relational
operators.
Use of relational algebra operators on existing relations produces new
relations.
Why study relational algebra?
Real databases use SQL, so why study relational algebra?
Relational algebra is at the core of SQL.
The first thing a DBMS does with an SQL query is
convert it into RA (or something very similar).
query execution planning and query
optimization are based on RA.
Relational Algebra
Operation to select specific • Example:
rows/ tuples/ records. – σ salary < 200(Emp)
Consider this table: Emp
– σ salary < 200 and nr >= 7
(Emp)
• General form:
σ <selection condition>(R)
Exercise:
Based on the library database shown in previous slide, write
relational algebra statement for the following questions:
1. Display all columns in table Publisher.
2. Display all records from table Book.
3. Show the list of books publish by Minerva Press.
(Book)
4. Show which member live in Kuching. (Borrower)
5. Show the list of books borrowed by member with ID
123. (Book Loan)
CARTESIAN PRODUCT / CROSS PRODUCT
(x)
enr ename dept dnr dname
1 Bill A A Marketing
2 Sarah C B Sales
3 John A C Legal
JOIN (⋈)
• Allows us to combine information from two or
more tables.
• A refinement of the PRODUCT operation.
• By using EMPLOYEE and DEPARTMENT table,
let see how to combine those tables by using JOIN.
• Example:
– EMPLOYEE ⋈ dept=dnr DEPARTMENT
JOIN (⋈)
•This is also known as INNER JOIN.
A join where the <condition> is the
match (=) of the primary and foreign
keys.
R ⋈ <R.primary_key = S.foreign_key> S
Outer Joins
An outer join extends the result of a simple join.
An outer join returns all rows that satisfy the join condition and
also returns some or all of those rows from one table for which
no rows from the other satisfy the join condition.
There are three kinds of outer joins −
LEFT OUTER JOIN, RIGHT OUTER JOIN AND
FULL OUTER JOIN.
https://docs.oracle.com/cd/B19306_01/server.102/b14200/queries006.htm
Left Outer Joins
All the tuples from the Left relation, R, are included in the
resulting relation.
If there are tuples in R without any matching tuple in the
Right relation S, then the S-attributes of the resulting
relation are made NULL.
Left Outer Joins
Right Outer Join
All the tuples from the Right relation, S, are included in the
resulting relation.
If there are tuples in S without any matching tuple in R, then
the R-attributes of resulting relation are made NULL.
Full Outer Join
All the tuples from both participating relations are included in the resulting
relation.
If there are no matching tuples for both relations, their
respective unmatched attributes are made NULL.
https://www.tutorialspoint.com/dbms/database_joins.htm
SUMMARY
RELATIONAL DATABASE AND RDBMS DEFINITION.
COMPONENTS OF RELATIONAL TABLE.
PROPERTIES OF RELATIONAL DATABASE.
RELATION SCHEME
RELATION KEYS
INTEGRITY RULES
RELATIONAL ALGEBRA OPERATORS
UNION COMPATIBILITY