Practical No:1 Horizontal Fragmentation: Institute of Distance & Open Learning
Practical No:1 Horizontal Fragmentation: Institute of Distance & Open Learning
PRACTICAL NO:1
HORIZONTAL FRAGMENTATION
2. Insert Records.
INSERT INTO EMP_01 VALUES(&ENO, '&ENAME', '&EADDR', '&EMAIL',
&ESALARY);
Enter value for eno: 1
Enter value for ename: NIKHIL
Enter value for eaddr: UDIT
Enter value for email: NIKHIL@MU.AC.IN
Enter value for esalary: 15000
old 1: INSERT INTO EMP_01 VALUES(&ENO, '&ENAME', '&EADDR', '&EMAIL',
&ESALARY)
new 1: INSERT INTO EMP_01 VALUES(1, 'NIKHIL', 'UDIT', 'NIKHIL@MU.AC.IN',
15000)
3. Check Records
5. Connect to Oracle2.
connect system/tiger@oracle2
connected.
ON ORACLE1
OUTPUT:
ON ORACLE 2
OUTPUT:
ON ORACLE 1
OUTPUT:
ON ORACLE 2
OUTPUT:
ON ORACLE 1
OUTPUT:
ON ORACLE 2
OUTPUT:
PRACTICAL NO: 2
VERTICAL FRAGMENTATION
2. Insert Records.
INSERT INTO EMP_01 VALUES(&ENO, '&ENAME', '&EADDR', '&EMAIL',
&ESALARY);
Enter value for eno: 1
Enter value for ename: NIKHIL
Enter value for eaddr: UDIT
Enter value for email: NIKHIL@MU.AC.IN
Enter value for esalary: 15000
old 1: INSERT INTO EMP_01 VALUES(&ENO, '&ENAME', '&EADDR', '&EMAIL',
&ESALARY)
new 1: INSERT INTO EMP_01 VALUES(1, 'NIKHIL', 'UDIT', 'NIKHIL@MU.AC.IN',
15000)
3. Check Records
5. Connect to Oracle2.
connect system/tiger@oracle2
connected.
ON ORACLE 1
OUTPUT:
ON ORACLE 2
OUTPUT:
ON ORACLE 1
OUTPUT:
ON ORACLE 2
OUTPUT:
ON ORACLE 1
SELECT ENAME, EMPB.EEMAIL@LINK1 FROM EMPA, EMPB@LINK1
WHERE
EMPA.ENO = EMPB.ENO@LINK1
AND
EMPA.ENO = &ENO
OUTPUT:
ON ORACLE 2
OUTPUT:
ON ORACLE 1
OUTPUT:
ON ORACLE 2
OUTPUT:
PRACTICAL NO: 3
CREATING REPLICA OF DATABASE
2. Insert Records.
INSERT INTO EMP_01 VALUES(&ENO, '&ENAME', '&EADDR', '&EMAIL',
&ESALARY);
Enter value for eno: 1
Enter value for ename: NIKHIL
Enter value for eaddr: UDIT
Enter value for email: NIKHIL@MU.AC.IN
Enter value for esalary: 15000
old 1: INSERT INTO EMP_01 VALUES(&ENO, '&ENAME', '&EADDR', '&EMAIL',
&ESALARY)
new 1: INSERT INTO EMP_01 VALUES(1, 'NIKHIL', 'UDIT', 'NIKHIL@MU.AC.IN',
15000)
3. Check Records
5. Connect to Oracle2.
connect system/tiger@oracle2
connected.
D. FIND THE EMPLOYEE NAME AND EMAIL WHERE EMPLOYEE NUMBER IS KNOWN
PRACTICAL NO: 4A
TEMPORAL DATABASE
2. INSERT RECORDS
OR
OR
PRACTICAL NO: 4B
TEMPORAL DATABASE
PRACTICAL NO 5
OBJECT ORIENTED DATABASE
2. Insert values:
nested table where each element in the table has 3 parts: an address and two phones*/
i. List all of the authors that have the same address as their publisher:
select aut.name
from Authors aut ,Publishers pub
where aut.addr=pub.addr;
Output:
NAME
----------------------------
Paulraj
ii. List all of the authors that have the same pin code as their publisher:
select aut.name
from Authors aut ,Publishers pub
where aut.addr.pincode=pub.addr.pincode;
Output:
NAME
----------------------------
Paulraj
Output:
no rows selected
iv. List the title of the book that has the most authors:
Select title
from books b, table(b.authors)
group by title
having count(*) =
(select max(count(*)) from books b, table(b.authors)
group by title);
Output:
TITLE
----------------------
DBMS
DSP
v. List the name of the publisher that has the most branches:
Select p.name
from publishers p, table(p.branches)
group by p.name having count(*)> =
all (select count(*)
from publishers p, table(p.branches)
group by name);
Output:
NAME
-----------------------
Pearson
ekta
joshi
wiley
select a.name
from authors a
where not exists( select b.title
from books b, table(b.authors)
where a.name = name);
Output:
no rows selected.
vii. Move all the branches that belong to the publisher 'tata' to the publisher ‘joshi'.
Output:
1 row created.
viii. List all authors who have published more than one book:
Output:
NAME
---------------------
Elmasri
Jerry
Rabiner
ix. List all books (title) where the same author appears more than once on the list of
authors (assuming that an integrity constraint requiring that the name of an
author is unique in a list of authors has not been specified).
select title
from authors a, books b, table(b.authors) v
where v.column_value = ref(a)
group by title having count(*) > 1
Output:
TITLE
----------------------
DBMS
DSP
PRACTICAL NO 6
ACTIVE DATABASES
5. Create Triggers.
1. Creating a trigger to insert new employee tuple and display the new total hours
from project table.
2. Creating a trigger to change the hours of existing employee and display the new total
hours from project table.
3. Create a trigger to change the project of existing employee & display the new total
hours from project.
PRACTICAL NO 7
XML DATABASES
Create a table called “employee” having dept_id as “number” datatype and employee_spec as
XML datatype (XMLType).
The employee_spec is a schema with attributes emp id, name, email, acc_no, managerEmail,
dateOf Joning .
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
To update an XML document, you can execute a standard SQL UPDATE statement. You need to
bind an XMLType instance, as follows:
PRACTICAL NO 8
DEDUCTIVE DATABASES
This object of this famous puzzle is to move N disks from the left peg to the right peg using the
center peg as an auxiliary holding peg. At no time can a larger disk be placed upon a smaller disk.
The following diagram depicts the starting setup for N=3 disks.
Here is a recursive Prolog program that solves the puzzle. It consists of two clauses.
move(1,X,Y,_) :-
write('Move top disk from '),
write(X),
write(' to '),
write(Y),
nl.
move(N,X,Y,Z) :-
N>1,
M is N-1,
move(M,X,Z,Y),
move(1,X,Y,_),
move(M,Z,Y,X).
The variables filled in by '_' (or any variables beginning with underscore) are 'don't-care' variables. Prolog
allows these variables to freely match any structure, but no variable binding results from this gratuitous
matching.
?- move(3,left,right,center).
Move top disk from left to right
Move top disk from left to center
Move top disk from right to center
yes
The first clause in the program describes the move of a single disk. The second clause declares how a
solution could be obtained, recursively. For example, a declarative reading of the second clause for N=3,
X=left, Y=right, and Z=center amounts to the following:
move(3,left,right,center) if
move(2,left,center,right) and ] *
move(1,left,right,center) and
move(2,center,right,left). ] **
This declarative reading of the clause is obviously correct. The procedural reading is closely related to the
declarative interpretation of the recursive clause. The procedural interpretation would go something like
this:
move(2,left,center,right) if ] *
move(1,left,right,center) and
move(1,left,center,right) and
move(1,right,center,left).
move(2,center,right,left) if ] **
move(1,center,left,right) and
move(1,center,right,left) and
move(1,left,right,center).
Now substitute the bodies of these last two implications for the heads and one can "see" the solution that
the prolog goal generates.
move(3,left,right,center) if
move(1,left,right,center) and
move(1,left,center,right) and *
move(1,right,center,left) and
---------------------------
move(1,left,right,center) and
---------------------------
move(1,center,left,right) and
move(1,center,right,left) and **
move(1,left,right,center).
A procedural reading for this last big implication should be obvious. This example illustrates well three
major operations of Prolog:
2) the body of the rule (with variables appropriately bound) becomes a new sequence of goals,
repeatedly,
until
3) some base goal or condition is satisfied, or some simple action is taken (like printing something).
Source Code:
move(1,X,Y,_):-
write('Move top disk from '),
write(X),
write(' to '),
write(Y),
nl.
move(N,X,Y,Z):-
N>1,
M is N-1,
move(M,X,Z,Y),
move(1,X,Y,_),
move(M,Z,Y,X).
Output:
Two predicate definitions that calculate the factorial function are in file 2_2.pl, which the reader
can view by clicking on the 'Code' link at the bottom of this page. The first of these definitions is:
factorial(0,1).
factorial(N,F) :-
N>0,
N1 is N-1,
factorial(N1,F1),
F is N * F1.
This program consists of two clauses. The first clause is a unit clause, having no body. The
second is a rule, because it does have a body. The body of the second clause is on the right side of
the ':-' which can be read as "if". The body consists of literals separated by commas ',' each of
which can be read as "and". The head of a clause is the whole clause if the clause is a unit clause,
otherwise the head of a clause is the part appearing to the left of the colon in ':-'. A declarative
reading of the first (unit) clause says that "the factorial of 0 is 1" and the second clause declares
that "the factorial of N is F if N>0 and N1 is N-1 and the factorial of N1 is F1 and F is N*F1".
The Prolog goal to calculate the factorial of the number 3 responds with a value for W, the goal
variable:
?- factorial(3,W).
W=6
Consider the following clause tree constructed for the literal 'factorial(3,W)'. As explained in the
previous section, the clause tree does not contain any free variables, but instead has instances
(values) of variables. Each branching under a node is determined by a clause in the original
program, using relevant instances of the variables; the node is determined by some instance of the
head of a clause and the body literals of the clause determine the children of the node in the clause
tree.
Fig. 2.2
Fig. 2.2
All of the arithmetic leaves are true by evaluation (under the intended interpretation), and the
lowest link in the tree corresponds to the very first clause of the program for factorial. That first
clause could be written
factorial(0,1) :- true.
and, in fact, ?- true is a Prolog goal that always succeeds (true is built-in). For the sake of brevity,
we have not drawn 'true' leaves under the true arithmetic literals.
The program clause tree provides a meaning of the program for the goal at the root of the tree.
That is, 'factorial(3,6)' is a consequence of the Prolog program, because there is a clause tree
rooted at 'factorial(3,6)' all of whose leaves are true. The literal 'factorial(5,2)' is, on the other
hand, not a consequence of the program because there is no clause tree rooted at 'factorial(5,2)'
having all true leaves. Thus the meaning of the program for the literal 'factorial(5,2)' is that it is
false. In fact,
?- factorial(3,6).
yes
?- factorial(5,2).
no
as expected. Clause trees are so-called AND-trees, since, in order for the root to be a consequence
of the program, each of its subtrees must also be rooted at literals which are themselves
consequences of the program. We will have more to say about clause trees later. We have
indicated that clause trees provide a meaning or semantics for programs. We will see another
approach to program semantics in Chapter 6. Clause trees do provide an intuitive, as well as a
correct, approach to program semantics.
Factorial
Source Code:
factorial(0,1).
factorial(N,F):-
N>0,
N1 is N-1,
factorial(N1,F1),
F is N*F1.
Output:
C. Map colorings
A famous problem in mathematics concerns coloring adjacent planar regions. Like cartographic
maps, it is required that, whatever colors are actually used, no two adjacent regions may not have
the same color. Two regions are considered adjacent provided they share some boundary line
segment. Consider the following map.
We have given numerical names to the regions. To represent which regions are adjacent, consider
also the following graph.
Here we have erased the original boundaries and have instead drawn an arc between the names of
two regions, provided they were adjacent in the original drawing. In fact, the adjacency graph will
convey all of the original adjacency information. A Prolog representation for the adjacency
information could be represented by the following unit clauses, or facts.
adjacent(1,2). adjacent(2,1).
adjacent(1,3). adjacent(3,1).
adjacent(1,4). adjacent(4,1).
adjacent(1,5). adjacent(5,1).
adjacent(2,3). adjacent(3,2).
adjacent(2,4). adjacent(4,2).
adjacent(3,4). adjacent(4,3).
adjacent(4,5). adjacent(5,4).
If these clauses were loaded into Prolog, we could observe the following behavior for some goals.
?- adjacent(2,3).
yes
?- adjacent(5,3).
no
?- adjacent(3,R).
R=1;
R=2;
R=4;
no
One could declare colorings for the regions in Prolog also using unit clauses.
color(1,red,a). color(1,red,b).
color(2,blue,a). color(2,blue,b).
color(3,green,a). color(3,green,b).
color(4,yellow,a). color(4,blue,b).
color(5,blue,a). color(5,green,b).
Here we have encoded 'a' and 'b' colorings. We want to write a Prolog definition of a conflictive
coloring, meaning that two adjacent regions have the same color. For example, here is a Prolog
clause, or rule to that effect.
conflict(Coloring) :-
adjacent(X,Y),
color(X,Color,Coloring),
color(Y,Color,Coloring).
For example,
?- conflict(a).
no
?- conflict(b).
yes
?- conflict(Which).
Which = b
conflict(R1,R2,Coloring) :-
adjacent(R1,R2),
color(R1,Color,Coloring),
color(R2,Color,Coloring).
Prolog allows and distinguishes the two definitions of 'conflict'; one has one logical parameter
('conflict/1') and the other has three ('conflict/3'). Now we have
?- conflict(R1,R2,b).
R1 = 2 R2 = 4
?- conflict(R1,R2,b),color(R1,C,b).
R1 = 2 R2 = 4 C = blue
The last goal means that regions 2 and 4 are adjacent and both are blue. Grounded instances like
'conflict(2,4,b)' are said to be consequences of the Prolog program. One way to demonstrate such
a consequence is to draw a program clause tree having the consequence as the root of the tree, use
clauses of the program to branch the tree, and eventually produce a finite tree having all true
leaves
Map coloring
Source Code:
/*-------Facts------*/
adjacent(1,2).
adjacent(1,3).
adjacent(1,4).
adjacent(1,5).
adjacent(2,1).
adjacent(2,3).
adjacent(2,4).
adjacent(3,1).
adjacent(3,2).
adjacent(3,4).
adjacent(4,1).
adjacent(4,2).
adjacent(4,3).
adjacent(4,5).
adjacent(5,1).
adjacent(5,4).
color(1,red,a).
color(2,green,a).
color(3,red,a).
color(4,yellow,a).
color(5,green,a).
color(1,blue,b).
color(2,red,b).
color(3,pink,b).
color(4,blue,b).
color(5,green,b).
/*-----Rules-----*/
conflict(Coloring):-
adjacent(X,Y),
color(X,Color,Coloring),
color(Y,Color,Coloring).
conflict(R1,R2,Coloring):-
adjacent(R1,R2),
color(R1,Color,Coloring),
color(R2,Color,Coloring).
Output: