Rdbms Unit 3
Rdbms Unit 3
3
RELATIONAL DATAMODEL
RELATIONAL MODEL CONCEPT
Relational model can represent as a table with columns and rows. Each row is known as a
tuple. Each table of the column has a name or attribute.
Domain: It contains a set of atomic values that an attribute can take.
Attribute: It contains the name of a column in aparticular table. Each attribute Ai must
have a domain, dom(Ai)
Relational instance: In the relational database system, the relational instance is represented
bya finite set of tuples. Relation instances do not have duplicate tuples.C+t vs Java
Relational schema: A relational schema contains the name of the relation and name of al
columns or attributes.
Relational key: In the relational key, each row has one or more attributes. It can identif
the row in the relation uniquely.
Example: STUDENT Relation
NAME ROLL NO PHONE NO ADDRESS AGE
Ram 14795 7305758992 Noida 24
12839 9026288936 35
Shyam Delhi
Laxman 33289 8583287182 20
27857
Gurugram
Mahesh 7086819134 Ghaziabad 27
Ganesh 17282 9028 9i3988 Delhi 40
RELATIONAL DATA MODEL 41
In the given table, NAME, ROLL_NO, PHONE_NO, ADDRESS, and AGE are the
attributes.
The instance of schema STUDENT has 5 tuples.
t3 =<Laxman, 33289, 8583287182, Gurugram, 20>
Properties of Relations
Name of the relation is distinct from all other relations.
Each relation cell contains exactly one atomic (single) value
Each attribute contains a distinct name
Attribute domain has no significanc
tuple has no duplicate value
Order of tuple can have adifferent sequence.
RELATIONAL ALGEBRA
process to obtain
Relational algebra is a procedural query language, It gives astep by step
pèrform queries.
the result of the query. It uses operators to
Types of Relational operation
Relational Operation
Cartesian Rename
Set Set
Seiect Project Union oroduct operatton
Intersection Difference
operation operatiop operation
1. Select Operation
predicate.
The select operation selects tuples that satisfy a given
o It is denoted by sigma (o).
1. Notation: o p(r)
Where:
ois used for selection prediction
ris used for relation
use connectors like: AND OR and
PS Usedas a propositional logic formula which may
NOT.These relational can use as relational operators like =, #,2 ,,S
42
TE
AV
For example: LOAN
Relation 30,4M
(68I
Javatpoint
Handling in Java - AMOUNT
Exception
LOAN NO
BRANCH NAME L-17
J000
Downtown 2000
L-23
Redwood 1500
L-J5
Perryride 1500
L-14
Downtown 500
L-13
Mianus 900
L-1|
Roundhill 1300
L-16
Perryride
Input:
BRANCH_NAME="perryride" (LOAN)
1. o
Output: AMOUNT
BRANCH_NAME LOAN NO
L-15 1500
Perryride
L-16 1300
Perryride
2. Project Operation
This operation shows the list of those attributes that we wish to appear in the result.
Rest of the attributes are eliminated from the table.
It is denoted by I[.
1. Notation: [| A1, A, An (r)
Where
Al, A2, A3 is used as an attribute name of relation r.
Example: CUSTOMER RELATION
NAME STREET CITY
Jones Main Harrison
Smith North
Rye
Hays Main
Harrison
Curry North
Rye
Johnson Alma
Brooks
Brooklyn
Senator
Brooklyn
RELATIONAL DATA MODEL 43
Input:
(CUSTOMER)
LIINAME, CITY
Output:
CITY
NAME
Harrisorn
Jones
Smith
Rye
Harrison
Hays
Rye
Curry
Brooklyn
Johnson
Brooklyn
Brooks
CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
A-321
Mayes
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
44 DBW
Jones L-23
Smith L-15
Hayes L-14
Jackson L-93
Curry L-11
Smith L-17
Williams
Lindsay
Jackson
Curry
Williams
Mayes
4. Set Itersection
Suppose there are two tuples R and S. The set intersection operation contains all tuple
that are in both R & S.
S la
It is denoted by intersection n.
1. Notation:R NS
Example: Using the above DEPOSITOR table and BORROW table
Input:
1. [JCUSTOMER_NAME (BORROW) n CUSTOMER_ NAME(DEPOSITOR)
RELATIONAL DATA MODEL
45
Output:
CUSTOMER_NAME
Smith
Jones
5.SetDifference
Suppose there are two tuples R and S. Theset intersection operation contans all tuples
that are in R but not in S.
It isdenoted by intersection minus (-).
1.Notation: R - S
BORRoW table
Example: Using the above DEPOSITORtable and
Input:
CUSTOMER_NAME (DEPOSITOR)
LIICUSTOMER_NAME (BORROW) - |
Output:
CUSTOMER_NAME
Jackson
Hayes
Willians
Curry
6.Cartesian product
The Cartesian product is used to combine each row in one table with each row in the
other table. It is also known as a cross product.
o It is denoted by X.
1.Notation: EXD
Example:
EMPLOYEE
OPERATIONS
condition JOIN 46
operations. Operation
Rename 7.
103 EMPLOYEE
Example: DEPARTMENT
102 101
EMP_CODE Note: Example: The
A1.p(STUDENT1,
STUDENT) 3 I.
Output: Input:
Join 3 2 2 2 1 1EMP_ID
is rename EMPLOYEE
satisfied.
operation Apart C B DEPTNO
We
from operation
It can John John John Harry Harry Harry Smith Smith Smith
EMP_NAME
combines
is X
denoted these use DEPARTMENT
the is
common
used
related rename
by to
b4, rename
tuples operator B B B C C A A
AEMP_DEPT
operations
from the
to
output
Jack
Harry EMP_NAME different rename
Stephan Relational Sales
Marketing
relation. Legal DEPT_NAME
STUDENT C B A C B A C B A
DEPT_NO
relations,
algebra It
is
denoted
relation
if
and can
only Sales
Legal Marketing Sales
LegalMarketing Sales
DEPT_NAME
Legal Marketing
be to by
if STUDENTI. rho
used
a (p).
given
in DEMA
joi Joi
Example: Natural
Join: 1.
RELATIONALMODEL
DATA
I.|EMP Input: Types Result:
attribute
Common
names.
It A 103 102 101
1.0peration: 103 102 101 SALARY
is natural EMP_CODE EMP_CODE
denoted of
NAME, Let's Join
join
use by operations: (EMPLOYEE
SALARY is Natural
Join
the . the
above set
(EMPLOYEEEMPLOYEE of b
tuples Jack
Stephan
Harry EMP_NAME SALARY)
of Outer
Join Operation
Join
all
table combinations Outer
Join
Full Outer
RightJoin Outer
Left
Join
SALARY) SALARY
25000 30000 50000
and
SALARY
in
R SALARY
25000 30000 50000
table: and
Equi
Join
S
that
are
equal
on
their 47
OutEMPput:NAME DBWS
SALARY
StJackephan 50000
30000
Harry 25000
2. Outer Join: The outer join operation is an extension of the join operation. It is
deal with missing used t
information.
Example:
EMPLOYEE
EMP NAME STREET CITY
Ram Civil line Mumbai
Shyam Park street Kolkata
Ravi M.G. Street Delhi
Hari
Nehru nagar Hyderabad
FACT_WORKERS
EMP _NAME BRANCH SALARY
Ram
Infosys 10000
Shyam Wipro 20000
Kuber HCL
30000
Hari TCS
50000
Input:
1.(EMPLOYEE FACT_WORKERS)
Output:
EMP_NAME STREET CITY BRANCH
Ram Civil line
SALARY
Mumbai
Infosys 10000
Shyam Park street Kolkata Wipro 20000
Hari Nehru nagar Hyderabad TCS 50000
An outer join is basically of three types:
a. Left outer join
b. Right outer join
C. Full outer join
RELATIONAL DATA MODEL 49
join:
a. Left outer
the set of tuples of all combinations in Rand Sthat are equal on
Left outerjoin contains names.
their common attribute
tuples in S.
Inthe left outer join,tuples in R have no matching
bA.
It is denoted by
and FACT WORKERS table
Example: Using the above EMPLOYEE table
Input:
FACT_WORKERS
1 EMPLOYEE DA BRANCH SALARY
STREET CITY
EMP_NAME
Mumbai Infosys 10000
Civil line
Ram 20000
Park street Kolkata Wipro
Shyam TCS 50000
Nehru street Hyderabad
Hari NULL NULL
M.G. Street Delhi
Ravi
b. Right outer
join:
of all combinations in R and S that are equal
set of tuples
Right outer join containsthe
attribute names.
on their common tuples in R.
outer join, tuples in S have no matching
In right
It is denoted by b. and FACT_WORKERS
Relation
EMPLOYEE table
Example: Using the above
Input:
1.EMPLOYEE D FACT_WORKERS
PRODUCT_ID CITY
1
Delhi
2
Mumbai
3
Noida
Input:
1.CUSTOMER PRODUCT
Output:
CLASS ID NAME PRODUCT ID CITY
1 John 1
Delhi
2
Harry 2
Mumbai
3
Harry 3
Noida
INTEGRITY CONSTRAINTS
Integrity constraints are a set of rules. It is used to maintain the quality of
information.
Integrity constraints ensure that the data insertion, updating, and other processes have
to be performed in such a way that data integrity is not affected.
RELATIONAL DATA MODEL 51
Thus, integrity constraint is used to guard against accidental damage to the database
Constraint 100.3
Types of Integrity Int egrity Constraint
1. Domain constraints
values for an
constraints can be defined as the definition of a valid set of
Domain
attribute.
domain includes string, character, integer, time, date, currency, etc.
The data type of
the attribute must be available in the corresponding domain.
The value of
Example:
NAME SEMENSTER AGE
ID 17
Tom 1st
1000 2nd 24
1001 Johnson
Leonardo 5th 21
1002
3rd 19
1003 Kate gth A
1004 Morgan
integer attribute
Not allowed. Because AGE is an
2. Entity integrity constraints
primary key value can't be null.
The entity integrity constraint states that
identify individual rows in relation and
This is because the primary key yalue is used to those rows.
if the primary key has a null value, then we can't identify
o Atable can contain a null value other than the primary key field.
DA
52
Example: EMPLOYEE
Example:
20.1M
409
History of Java
NAME SEMAENSSTER
1st
AGE
17
100O Tom
Johnson 24
1001 Leonardo Sth 21
1002 19
LO03 Kate
1002 Morgan
all r o w m n u s t be umiaUe
Not allowed. BecaASe
RELATIONAL CALCULUS
In the non-procedural query
Relational calculus is a non-procedural query language. the end results.
language, the user isconcerned with the details of how to obtain
relational calculus tells what to do but never explains how to do.
The
calculus:
Types of Relational
Relational Calculus
Domaín Relational
Tuple Relational
calculus Calculus