0% found this document useful (0 votes)
4 views15 pages

Rdbms Unit 3

The document provides an overview of the relational data model, detailing its components such as relations, attributes, and keys, as well as the properties of relations. It also explains relational algebra operations including selection, projection, union, intersection, difference, and joins, along with examples. Additionally, it discusses integrity constraints that ensure data quality and integrity within a relational database system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

Rdbms Unit 3

The document provides an overview of the relational data model, detailing its components such as relations, attributes, and keys, as well as the properties of relations. It also explains relational algebra operations including selection, projection, union, intersection, difference, and joins, along with examples. Additionally, it discusses integrity constraints that ensure data quality and integrity within a relational database system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

DATA G

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

3. Union Operation that


are two tuples R and S. The union operation contains all the tuples
Suppose there
inR& S.
are either in R orSor both
tuples. It is denoted by U.
It eliminates the duplicate
1. Notation: RUS
following condition:
A union operation must hold the
of the same number.
Rand S must have the attribute
automatically.
Duplicate tuples are eliminated
Example:
DEPOSITOR RELATION

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

BORROW RELATION LOANNO


CUSTOMER NAME L-17

Jones L-23
Smith L-15

Hayes L-14
Jackson L-93

Curry L-11
Smith L-17
Williams

Input: CUSTOMER_NAME (DEPOSITOR)


CUSTOMER_NAME (BORROW) UI|
1.||
Output:
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones

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

Output: STREET CITY


SALARY
EMP NAME BRANCH Mumbai
10000 Civil line
Ram Infosys Kolkata
20000 Park street
Shyam Wipro Nehru street Hyderabad
TCS 50000
Hari NULL
30000 NULL
Kuber HCL

c. Full outer join:


right join except that it contains all rows from both tables.
rull outer joinis like a left or in S and tuples in S that have
have no matching tuples
ul Outer join, tuplesin R thatcommon attribute name.
1o matching tuples in R in their
o It is denoted by M.
WORKERStable
Example: Using the above EMPLOYEE table and FACT
50 DBMS
Input:
1.EMPLOYEE D FACT_WORKERS
Output: CITY
BRANCH SALARY
EMP NAME STREET
Infosys 10000
Mumbai
Ram Civil line
Wipro 20000
Kolkata
Park street
Shyam Hyderabad TCS 50000
Hari Nehru street
M.G. Street Delhi NULL NULL
Ravi
NULL HCL 30000
Kuber NULL
based
Equi join: It is also known as an inner join. It is the most common join. It is
3. comparison operator(=).
matched data as per the equality condition. The equijoin uses the
Example:
CUSTOMER RELATION
NAME
CLASS_ID
1 John
2 Harry
3 Jackson
PRODUCT

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

Entity Integrity Referential Key Constraint


Domain Integrity Constraint
Constraint
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

EMP ID EMP _NAME SALARY


123 Jack 30000
142 Harry 60000
164 John 20000
Jackson 27000

Not allowed as primary key can't contain a NULL value

3. Referential Integrity Constraints


Areferential integrity constraint is specified between two tables.
In the Referential integrity constraints, if a foreign key in
Key of Table 2, then every value of the Foreign Key inTable 1 refers to the Primar
available in Table 2. Table 1 must be null or h
Example:
(Table 1)

EMP_NAME NAME AGE D_No


Foreign key
Jack
20 11
Harry 40 24
John 27 18
Devi!
Not allowed as D_No 18 is
38 not defined as a
43 key of table 2 and in Primary
D_ No is a foreign table
key
1,
defined
Relationships
Primary Key (Table 2)
-D_No D_Location
Mumbai
24
Delhi
13
Noida
4. Key constraints
o Keys are the
entity set that is used to identify an
An entity set can have entity within its entity set
multiple keys, but out of which one key will be
primary key can contain a unique
uniquely.
and null value in the relational table. the primary key. A
RELATIONAL DATAMODEL
53

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

1. Tuple Relational Calculus (TRC) the tuples in a relation. In TRC,


calculus is specified to select
o The tuple relational relation.
filtering variable uses the tuples of a
or more tuples.
o The result of the relation can have one
Notation:
1.{T|P (T)} or {T|Condition (T)}
Where
Tis the resulting tuples
P(T) is the condition used to fetch T.
Exception Handling in Java - Javatpoint
54

Wor exanmplei -datahase'


|Atho)ANDTticle AUTHOR relation, It
electsthe luplesfum the returns atuple wi,
0UTPUhis
'name' fom quey
Author who has witlen an article
database'
on
Existential
be quatifed, In TRC, we can us
TRC (uple relation calcuus) cAn
Universal QuantificA (V)
For exumple:
R|Te Atbon(Anticle-latabase' AND R.name-Tname)
1| previous one.
result as the
Output: This query will yield the same
(DRC)
2. Domaln RelatlonalCaleulun
Domain relational calculus. In dorm:
The second lorm of relation is known as domainof attributes.
relational cnlculus, filtering variable uses the
logi
Domain relational calculus uNes the sanc operators as tuple calculus. It uses
conncctivcN A(and), V (or) and (not),
It useN Exintential() and Univernal Quantifiers (V) to bind thevariable.
Notatlon:

1.(al, a2, n3, .., an |P (al, a2, a3, ... an)}


Where
al, a2 are attributeN
P stands for formula built by inner attributes
For examnple:
1.(<articlc,page, subject>| Ejavatpoint Asubject ='database'}
Output:This query will yicldthe article, page, and subject from the relational javatpoint,
where the subject is a database.

You might also like