Record Based
Logical Model
Relational Model
ORACLE
Objectives
In this lesson, you will learn :
▪ What is Relational Data Model
▪ Steps for Creating an ER Diagram
▪ Relational Operators
▪ Mapping ER Diagrams to Tables
ORACLE
Relational data model
▪ Relational data structure:
➢ Each table in a database has a unique table name
➢ The row (or record) in the table is called a tuple
➢ The column (or field) is called an attribute
➢ Every column in a table must have a unique name
➢ The number of tuples is called the cardinality of the table
➢ The number of attributes is called the degree of the table
➢ A column or combination of columns that uniquely identifies each
row in the table is called the primary key of the table
➢ A table where every row is different from all other rows is called a
relation
➢ A domain is a collection of values from which one or more
attributes (columns) draw their actual values
ORACLE
Relational Data Model
▪ The following diagram describes the data structure of an RDBMS
Tuple
T_CODE NAME AGE SEMESTER
I1001 Nancy Mathews 27 I
I1002 Catherine 38 II
I1003 Mac Thams 50 IV
I1004 Joe Nelson 35 III
ORACLE
Relational Data Model
▪ The following diagram describes the data structure of an RDBMS
Attributes
T_CODE NAME AGE SEMESTER
I1001 Nancy Mathews 27 I
I1002 Catherine 38 II
I1003 Mac Thams 50 IV
I1004 Joe Nelson 35 III
ORACLE
Relational Data Model
▪ The following diagram describes the data structure of an RDBMS
Primary Key
T_CODE NAME AGE SEMESTER
I1001 Nancy Mathews 27 I
I1002 Catherine 38 II
I1003 Mac Thams 50 IV
I1004 Joe Nelson 35 III
Relation
ORACLE
Relational Data Model
▪ The following diagram describes the data structure of an RDBMS
DOMAIN DOMAIN DOMAIN DOMAIN
T_CODE NAME AGE SEMESTER
T_CODE NAME AGE SEMESTER
I1001 Nancy Mathews 27 I
I1002 Catherine 38 II
I1003 Mac Thams 50 IV
I1004 Joe Nelson 35 III
ORACLE
Relational Data Model
▪ Representing missing information:
➢ In RDBMS, missing or unknown information is represented as a
NULL value in a table.
➢ NULL is not the same as space or zero
▪ Representing relationships in an RDBMS:
➢ A column in one table whose value matches the primary key in
some other table is called a foreign key
➢ A primary key and a foreign key create a parent-child relationship
between the tables that connect them
ORACLE
Relational Data Model
▪ The following diagram represents the parent-child relationship in a
relational model
Column A is a primary key of Table1, which is
Primary Key also present in Table2 as a foreign key.
Table 1 Table 2
Table 3 Foreign Key
Table3, which consists of columns, A, B, and F
can have a combination of columns (A and B)
as a foreign key.
Foreign Key
ORACLE
Steps for Creating an
ER Diagram
▪ The following steps should be followed while creating an ER diagram:
1. Identify the entities
2. Find the relationships
3. Identify the key attribute
4. Identify other important attributes
5. Draw a complete ER diagram
6. Review of ER diagram
ORACLE
Relational Operators
▪ Each operator takes one or two relations as its input and produces a
new relation as its output
▪ It is based on the principle of relational algebra
▪ The following operators have been defined as relational operators:
➢ RESTRICT
➢ PROJECT
➢ PRODUCT
➢ UNION
➢ INTERSECT
➢ DIFFERENCE
➢ JOIN
➢ DIVIDE
ORACLE
Relational Operators
▪ RESTRICT
➢ Each operator takes one or two relations as its input and produces
a result. The restrict operator extracts specified tuples or rows from
a given relation based on a condition, as shown in the following
diagram
Extracted Rows
ORACLE
Relational Operators
▪ RESTRICT
➢ The following table describes the columns of the STUDENT table
The condition is to extract only those tuples from the STUDENT
table where the age of the students is more than 25.
After applying the restriction, the highlighted tuples will be the
result.
ORACLE
Relational Operators
▪ PROJECT
➢ The project operator extracts specified attributes or columns from a
given relation, as shown in the following diagram
Extracted columns
ORACLE
Relational Operators
▪ The following table describes the columns of the STUDENT table
The condition is to extract only the name and age of all the students
ORACLE
Relational Operators
▪ PRODUCT
➢ The product operator joins two relations such that every tuple of
the first relation is matched with every tuple of the second relation
➢ To be product compatible, the two tables must have common
attributes
➢ The following diagram shows an example of the product operator
ORACLE
Relational Operators
▪ In the following diagram, the product operator creates the Cartesian
product between the TEACHER and the BATCH tables
TEACHER Table BATCH Table
T_CODE NAME BATCH_CODE T-CODE
I1001 Nancy B001 I1001
Mathews B002 I1002
I1002 Catherine
B003 I1003
I1003 Mac Thames
PRODUCT
T_CODE NAME BATCH_CODE T-CODE
I1001 Nancy Mathews B001 I1001
I1001 Nancy Mathews B002 I1002
I1001 Nancy Mathews B003 I1003
I1002 Catherine B001 I1001
I1002 Catherine B002 I1002
I1002 Catherine B003 I1003
I1003 Mac B001 I1001
I1003 Mac B002 I1002
I1003 Mac B003 I1003
ORACLE
Relational Operators
▪ UNION
➢ The union operator builds a relation from tuples appearing in either
or both of the specified relations
➢ The following diagram represents the mathematical representation
of the union operator
ORACLE
Relational Operators
▪ UNION
➢ Consider the tables, A and B, as shown in the following diagram
UNION
ORACLE
Relational Operators
▪ INTERSECT
➢ The intersect operator builds a relation consisting of tuples that
appear in both the relations
➢ The following diagram represents the mathematical representation
of the intersect operator
ORACLE
Relational Operators
▪ INTERSECT
➢ Consider the tables, A and B, as shown in the following diagram
INTERSECT
ORACLE
Relational Operators
▪ DIFFERENCE
➢ The difference operator builds a relation of tuples appearing in the
first but not in the second of the two specified relations
➢ The following diagram represents the mathematical representation
of the difference operator
ORACLE
Relational Operators
▪ DIFFERENCE
➢ The difference the following set of tables illustrates operation on
tables, A and B
DIFFERENCE
ORACLE
Relational Operators
▪ JOIN
➢ The join operator:
✓ Builds a relation that consists of all the possible combinations
of tuples, one from each relation that satisfies the specified
condition
✓ Requires a common attribute
➢ The following diagram shows how the join operator works
ORACLE
Relational Operators
▪ JOIN
➢ The following set of tables illustrates the join operation on tables, X
and Y
X JOIN Y
ORACLE
Relational Operators
▪ DIVIDE
➢ The divide operator :
✓ Builds a relation that consists of values of an attribute of one
relation that matches all the values in the other relation.
✓ Is the opposite of the product operation
➢ The following diagram shows how the divide operator works
ORACLE
Relational Operators
▪ DIVIDE
➢ The following set of tables illustrates the divide operation on the
STUDENT table
DIVIDE
ORACLE
Conceptual Model
▪ The conceptual model reflects entities and their relationships based on
the data-processing needs of an organization
▪ The ER Diagram represents the Conceptual Model
ORACLE
Conceptual Model
▪ The conceptual model can be mapped to a relational, hierarchical, or
network model
▪ Data analysis is the first step in designing a conceptual model
▪ Data analysis involves identifying entities, their attributes, and
relationships between entities based on the data collected
▪ After you complete data analysis, you draw the entity-relationship diagram
that gives a detailed overview of the database design
ORACLE
Mapping ER Diagrams to Tables
▪ The following components play an important part while mapping an ER
diagram to table:
➢ Regular entities
➢ Attributes
➢ Relationships
➢ Weak entities
➢ Subtypes and super types
ORACLE
Mapping ER Diagrams to Tables
▪ Regular entities :
➢ They can exist alone, independent of any other entity.
➢ They are the “building blocks” of the database
➢ Each regular entity maps to a table
➢ For example, STUDENT and BOOKS are two separate entities in
the following ER diagram
STUDENT ISSUE BOOKS
S
ORACLE
Mapping ER Diagrams to Tables
▪ Attributes:
▪ Each property or attribute shown in the ER diagram maps to an
attribute in the appropriate table
▪ In the following ER diagram, STUDENT and BOOKS individually
has different attributes
Entity becomes the table and
the attributes of the entity
become columns of the table.
ORACLE
Mapping ER Diagrams to Tables
▪ Relationships:
▪ There are the following types of relationships:
➢ One-to-One
➢ One-to-Many
➢ Many-to-Many
ORACLE
Mapping ER Diagrams to Tables
▪ One-to-one relationship:
➢ One instance of an entity can relate to only one instance of the
related entity
For example:
If frequent queries require
data from the two tables, then
it is better to merge the two
tables to improve query
performance.
ORACLE
Mapping ER Diagrams to Tables
▪ One-to-many relationship:
➢ One instance of an entity can relate to more than one instance of
the related entity
For example:
Mapped to the Mapped to
DEPARTMENT the
table EMPLOYEE
table
ORACLE
Mapping ER Diagrams to Tables
▪ Many-to-many relationship:
Many instances of an entity can relate to more than one instance of
the related entity
For example:
Mapped to the Mapped to the
Mapped to
STUDENT BOOKS table
the
table
ISSUES
table
The primary keys, ROLL_NO and CODE of
the STUDENT and BOOKS table will act as
the foreign keys in the ISSUE table.
ORACLE
Mapping ER Diagrams to Tables
▪ Weak entity:
➢ It is an entity whose existence depends on some other entity
For example:
The EMPLOYEEADDRESS
entity can be mapped to a
separate table.
ORACLE
Mapping ER Diagrams to Tables
▪ Subtypes and super types:
➢ A subtype is a subset of another entity
➢ A subtype is always dependent on super type for its existence
➢ The primary key of the super type creates a link between the super
type and subtypes
ORACLE
Mapping ER Diagrams to Tables
For example :
Each subtype and
super type maps to a
Super type separate table.
Subtypes
ORACLE
Summary
▪ In this session, you learned that:
➢ The conceptual model reflects entities and their relationships. Data
analysis helps determine entities and relationships. The conceptual
model is independent of the system where it is to be implemented
➢ Regular entities are not dependent. They can exist in isolation,
independent of any other entity
➢ Each entity maps to a table. Each attribute in an ER diagram maps
to a column in a table
➢ Entities with common attributes should be merged. Attributes may
acquire further attributes and become entities
➢ The mapping of relationships depends on the type of relationship.
Each type of relationship maps to tables in a different manner in
the relational database management system
ORACLE
Summary
▪ In one-to-one relationship, one instance of an entity can relate to only
one instance of the related entity
▪ In one-to-many relationship, one instance of an entity can relate to more
than one instance of the related entity
▪ Many-to-many relationships map to tables. One-to-one relationships are
not very common and may map to foreign keys in tables
▪ A weak entity is an entity whose existence depends on some other
entity
▪ A subtype is a subset of another entity. A subtype is always dependent
on super type for its existence
▪ The primary key of the super type is the foreign key of the subtype. It
creates a link between the two
ORACLE