Adbms PDF
Adbms PDF
PRACTICAL NO:1
HORIZONTAL FRAGMENTATION
2. InsertRecords.
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: [email protected]
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', '[email protected]',
15000)
3.Check Records
5.Connect to Oracle2.
connect
system/tiger@oracle2
connected.
ON ORACLE1
OUTPUT:
ON ORACLE 2
OUTPUT:
ON ORACLE 1
ON ORACLE 2
OUTPUT:
ON ORACLE 2
OUTPUT:
PRACTICAL NO: 2
VERTICAL FRAGMENTATION
1.Create(Global conceptual schema)a table Emp_01.
create table Emp_01
(Eno number,
Enamevarchar(9),
Eaddrvarchar(15),
Eemailvarchar(15),
Esalarynumber);
2. InsertRecords.
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: [email protected]
Enter value for esalary: 15000
old1: INSERT INTO EMP_01 VALUES(&ENO, '&ENAME', '&EADDR', '&EMAIL',
&ESALARY)
new 1: INSERT INTO EMP_01 VALUES(1, 'NIKHIL', 'UDIT', '[email protected]',
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. InsertRecords.
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: [email protected]
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', '[email protected]',
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
3. CHECKINSERTED RECORDS
OR
OR
PRACTICAL NO: 4B
TEMPORAL DATABASE
1.
PRACTICAL NO5
OBJECT ORIENTED DATABASE
Types:AddrType,BranchType,AuthorType,AuthorListType,PublisherType
Tables:BranchTableType,authors
2. Insert values:
Table Name1:authors_01
Format : authors( name, addr:<pincode,street,city,state,no>)
a nestedtable where each element in the table has 3 parts: an address and two phones*/
Table Name3:
books Format title,year,published_by:
:
books( ref<Publishers>, authors:list of ref
Author)
/*Where published_by is a reference to elements of the table Publishers; authorsis a complex-valued
attribute, in this case a list of references to objects of the type author(managed by table ‘Author’.*/
i.List all of the authors that have the same address as their publisher:
select aut.name
from Authorsaut ,Publishers pub
where aut.addr=pub.addr;
Output:
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:
iv. List the title of the book thathas the most authors:
vii. Move all the branches that belong to the publisher '
tata' to the publisher ‘joshi'.
viii. List all authors who have published more than onebook:
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).
PRACTICAL NO 6
ACTIVE DATABASES
5.Create Triggers.
1.Creating a trigger to insert new employeetuple and display the new total hours
from project table.
2. Creating a trigger to change the hours of existing employee and displaythe 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
The employee_specis a schema with attributes emp id, name, email, acc_no, managerEmail,
dateOf Joning .
We create employee_spec like any other user-defined type.
To update an XML document, you can execute a standard SQL UPDATE statement. You need
to bind anXMLTypeinstance, as follows:
PRACTICAL NO 8
DEDUCTIVEDATABASES
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 cana 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 thesecond 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 bodyof 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:
Output:
Two predicate definitionsthat 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 ':-' whichcan 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 thecolon 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
headof 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 correspondsto 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 subtreesmust 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:
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 insteaddrawn 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
Output: