02 Dbmsmodels
02 Dbmsmodels
Relational Model
and
Database Integrity
DBMS Models and
Database Integrity
• Objectives -
– List & describe DBMS models
– Describe Relational model
– Explain Database Integrity & it’s key
definitions
– List & explain Relational operators
2
DBMS Models
• Hierarchical
• Network
• Relational
• Object Oriented
• Object Relational
3
Relational Model
• Relational Model
– Data is organized in terms of rows and columns
in a table
– Does not maintain physical relation (pre-
defined relation) between databases
– Terms
• Table/Relation
• Row/Tuple
• Column/Attribute
4
Relational Model
• Employee Table
EmpNo Ename Job Hiredate Mgr Sal Comm Deptno
5
Relational Model
• Database
Dept
Emp Incr
Bonus SalGrade
6
Relational Model
7
Relational Model
• Features
– Data independence
– Supports many-to-many relationships
– Operates on a set of data at a time rather than a
record at a time
– Simple, interactive query language
– An RDBMS has to satisfy the 12 rules (Codd’s
rules) to be accepted as a full-fledged RDBMS
8
Database Integrity
• Database Integrity refers to the wholeness and
correctness of the database
– Key Definitions
• Primary Key
• Foreign Key
– Integrity Rules
• Entity Integrity
• Referential Integrity
9
Key Definitions
• Primary Key
– Primary Key is a column or a set of columns in
a table which uniquely identifies a row in a
table
– One of the candidate keys is chosen as the
primary key
– There can be only one primary key per table
– Primary key may be a compound key
10
Key Definitions
• Foreign Key
– If a key in a given table has a reference to the
value of a primary key of some other relation
then it is called as a foreign key
– A table can have more than one foreign keys
11
Integrity Rules
• Entity Integrity Rule
– No primary key in the given table can be null
– No two rows have the same value for primary key
12
Relational Operators
• Relational Operators are
– Restrict (Select)
– Project
– (Cartesian) Product
– Join
– Union
– Intersection
– Difference
13
Relational Operators
• Restrict / Select
– Retrieves a set of rows from a relational table based on
the condition given (for the values in a column or set of
columns)
14
Emp Table
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMA 7698 20-FEB-81 1600 300 30
7521 WARD N
SALESMA 7698 22-FEB-81 1250 500 30
7566 JONES N
MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMA 7698 28-SEP-81 1250 1400 30
7698 BLAKE N
MANAGER 7839 01-MAY-81 2850 30
16
EMP Table
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMA 7698 20-FEB-81 1600 300 30
7521 WARD N
SALESMA 7698 22-FEB-81 1250 500 30
7566 JONES N
MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMA 7698 28-SEP-81 1250 1400 30
7698 BLAKE NMANAGER 7839 01-MAY-81 2850 30
17
Relational Operators
• (Cartesian) Product
– Produces a result table whose rows are a
concatenation of every row from one table with
every row from another table
– Though Cartesian product is not useful itself, it
is important as an intermediate step in
obtaining more meaningful result
18
EMP table DEPT table
EMPNO ENAME DEPTNO DEPTN DNAME LOC
7369 SMITH 20 O
10 ACCOUNTING NEW
7499 ALLEN 30 20 RESEARCH YORK
DALLAS
30 SALES CHICAGO
20
Result of JOIN combination of the (Cartesian) product, select
and projection operation
EMPNO ENAME DEPTNO DEPTNO DNAME LOC
21
Relational Operators
• Union
– Combines rows from one table with rows from another
table
– Duplicate rows are eliminated
– Tables must be union compatible
• Intersection
– Produces a result table with rows common to both
tables
22
Relational Operators
• Difference
– Produces a result table that contains rows that
occur in first table, but not in the second
23