Advance Database Lab

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 105

EX.

NO:1
DATE :
TO IMPLEMENT DDL AND DML COMMANDS IN RDBMS
AIM:
To execute and verify the DDL and DML commands in rdbms.
DDL (DATA DEFINITION LANGUAGE)

 CREATE
 ALTER
 DROP
 TRUNCATE
 COMMENT
 RENAME
DML (DATA MANIPULATION LANGUAGE)

 SELECT
 INSERT
 DELETE
 UPDATE

SQL COMMANDS DESCRIPTIONS

1. COMMAND NAME: CREATE

COMMAND DESCRIPTION: CREATE command is used to create objects

in the database.

2. COMMAND NAME: DROP

COMMAND DESCRIPTION: DROP command is used to delete the object

from the database.


3. COMMAND NAME: TRUNCATE

COMMAND DESCRIPTION: TRUNCATE command is used to remove

all the records from the table

4. COMMAND NAME: ALTER

COMMAND DESCRIPTION: ALTER command is used to alter the structure

of database

5. COMMAND NAME: RENAME

COMMAND DESCRIPTION: RENAME command is used to rename the

objects.

6. COMMAND NAME: INSERT

COMMAND DESCRIPTION: INSERT command is used to Insert objects

in the database.

7. COMMAND NAME: SELECT

COMMAND DESCRIPTION: SELECT command is used to SELECT the


object from the database.

8. COMMAND NAME: UPDATE

COMMAND DESCRIPTION: UPDATE command is used to UPDATE


the records from the table
9. COMMAND NAME: DELETE

COMMAND DESCRIPTION: DELETE command is used to DELETE the


Records form the table
PROCEDURE
STEP 1: Start
STEP 2: Create the table with its essential attributes
STEP 3: Insert the record into table
STEP 4: Update the existing records into the table
STEP 5: Delete the records in to the table
STEP 6: Execute different Commands and extract information from the table.
STEP 7: Stop
TABLE 01:
QUERY: 01
Q1. Write a query to create a table books with ISDN, Author name, topics, stocks,
price.
Syntax for creating a table:
SQL: CREATE <OBJ.TYPE> <OBJ.NAME> (COLUMN NAME.1
<DATATYPE> (SIZE), COLUMN NAME.1 <DATATYPE> (SIZE)
……………………………);
SQL>Create Table books (ISBN alphanumeric, Author name Varchar(50),
Topics Varchar(50), stocks Numbers(10), price Numbers(10));
Table created.
QUERY: 02
Q2. Write a query to display the column name and datatype of the table employee.
Syntax for describe the table:
SQL: DESC <TABLE NAME>;
SQL> DESC books;
Name Null? Type
----------------------------- -------- -------------
ISBN Alphanumeric(10)
Author name Varchar(50)
topics Varchar(50)
stocks Number(10)
price Number(10)

QUERY: 03

Q3. Write a query to insert the records in to books.

Syntax for Insert Records in to a table:

SQL :> INSERT INTO <TABLE NAME> VALUES< VAL1, ‘VAL2’,…..);

Sql>Insert Into books Values(ISBN1345,’PETERSON’,’COMPUTER


NETWORKS’,30,44);

1 Row Created.

Sql>Insert Into books Values(ISBN1346,’HENRY’,’HTML BOOK’,10,50);

1 Row Created.

Sql>Insert Into books Values(ISBN1347,’MORRIS MANO’,’DSP’,15,70);

1 Row Created.

Sql>Insert Into books Values(ISBN1348,’WILLAM STALLING’,


’CRPTOGRAPHY’, 20, 100);
1 Row Created.

Sql>Insert Into books Values(ISBN1349,’GOPINATH’, ’EMBEDDED


SYSTEMS’, 30, 120);

1 Row Created.

QUERY: 04

Q4. Write a query to display the records from books.

Syntax for select Records from the table:

SQL> SELECT * FROM <TABLE NAME>;

SQL> SELECT * FROM books;

ISBN Author name topics stocks price


----------------- ----------------------- ------------------ --------------- ---------------
ISBN1345 PETERSON COMPUTER 30 44
NETWORKS
ISBN1346 HENRY HTML BOOK 10 50

ISBN1347 MORRIS MANO DSP 15 70

ISBN1348 WILLIAM CRYPTO 20 100


STALLINGS -GRAPHY

ISBN1349 GOPINATH EMBEDDED 30 120

TABLE 02:
SQL>Create Table bookstore (store number Number(10), city Varchar(50),
State Varchar(50), PINcode Number(10), Inventory values Number(10));
Table created.
SQL> DESC bookstores;
Name Null? Type
----------------------------- -------- -------------
storenumber Number(10)
city Varchar(50)
State Varchar(50)
PINcode Number(10)
Inventoryvalues Number(10)

Sql>Insert Into bookstore Values(123,’chennai’,’TamilNadu’,25000,100);

1 Row Created.

Sql>Insert Into bookstore Values(122,’Maduai’,’TamilNadu’,28000,113);

1 Row Created.

Sql>Insert Into bookstore Values(133,’chitoor’,’Andra’,65000,111);

1 Row Created.

Sql>Insert Into bookstore Values(141,’vellore’,’TamilNadu’,88000,125);

1 Row Created.

Sql>Insert Into bookstore Values(155,’Arni’,’TamilNadu’,90000,145);

1 Row Created.
SQL> SELECT * FROM bookstore;

Store city State PINcode Inventory


number values
----------------- ----------------------- ------------------ --------------- ---------------
123 Chennai TamilNadu 25000 100

122 Madurai TamilNadu 28000 113

133 Chitoor Andra 65000 111

141 Vellore TamilNadu 88000 125

155 Arni TamilNadu 90000 145

TABLE 03:
SQL>Create Table stock (store number Number(10), ISBN alphanumeric(10),
Quantity Number(10));
Table created.
SQL> DESC bookstores;
Name Null? Type
----------------------------- -------- -------------
storenumber Number(10)
ISBN Alphanumeric(10)
Quantity Number(10)

Sql>Insert Into Stock Values(123,ISBN1345,4);

1 Row Created.
Sql>Insert Into Stock Values(122,ISBN1346,10);

1 Row Created.

Sql>Insert Into Stock Values(133,ISBN1347,15);

1 Row Created.

Sql>Insert Into Stock Values(141,ISBN1348,5);

1 Row Created.

Sql>Insert Into Stock Values(155,ISBN1349,10);

1 Row Created.

SQL> SELECT * FROM stock;

Store ISBN Quantity


number
----------------- ----------------------- ------------------
123 ISBN1345 4

122 ISBN1346 10

133 ISBN1347 15

141 ISBN1348 5

155 ISBN1349 10

Query 05:
Q5:Write the query for finding price in books between 15 and 55.

SQL>SELECT< COLUMN NAME> FROM <TABLE NAME>

WHERE <COLUMN NAME> <FROM RANGE> AND <TO RANGE>;


SQL>Select topic from books where price between 15 and 55;
topics price
------------------ ---------------
COMPUTER 44
NETWORKS

HTML BOOK 50

QUERY: 06

Q6. Write a query to update the records from bookstore.

Syntax for update Records from the table:

SQL> UPDATE <<TABLE NAME> SET <COLUMNANE>=<VALUE>


WHERE <COLUMN NAME=<VALUE>;

SQL> UPDATE bookstore SET PINcode=48000 WHERE storenumber=122;

1 row updated.

SQL> SELECT * FROM bookstore;

Store city State PINcode Inventory


number values
----------------- ----------------------- ------------------ --------------- ---------------
123 Chennai TamilNadu 25000 100

122 Madurai TamilNadu 48000 113

133 Chitoor Andra 65000 111

141 Vellore TamilNadu 88000 125

155 Arni TamilNadu 90000 145


Query:07

Q7:Write query to count the books .

Syntax to count books from the table:

SQL>SELECT COUNT FROM TABLE NAME;

SQL>SELECT COUNT FROM books;

RESULT:

Thus DDL and DML has been created, executed and verified successfully.
Ex.no: OBJECT ORIENTED DATABASE

Date:

Aim:
To dsign an Enhanced Entity Relationship (EER) Model for university database by using Matisse
Enterprise manager.
Write OQL for the following
i. Insert details in each object.
ii. Display the Employee details.
iii. Display Student Details.
iv. Modify person details.
v. Delete person details.
Procedure:
Step 1: Download the Matisse Enterprise manager from www.matisse .com .
Step 2: Open matisse as follows
Start->All programs->Enterprise manager

Step 3: To create new database click on example and turn on it. Extend it by
clicking on ‘+’ sign then click on data to use Sql Query Analyzer.
Example->Data->SQL Query Analyzer
Step 4:TO CREATE CLASSES:
Use queries inside the box SQL statement and excute it.
Create Classes called Student then Employee and then Univ
Q1: CREATE CLASS Student (name string, regno integer,department string,
emp REFERENCES SET (Employee) INVERSE Employee.starred_in,
ownedby REFERENCES (Univ) INVERSE Univ.owns);

Q2: CREATE CLASS Employee (name string, street string, city string,
starred_in REFERENCES SET (Student) INVERSE Student.emp);

Q3: CREATE CLASS Univ (name string,address string,


owns REFERENCES SE (Student)INVERSE Student.ownedby);

Execute query by using F5 and then execution result will be at the bottom of SQL statement
box.
Step 5: TO INSERT THE VALUES:

insert into Univ(name,address) values('Anna','Gundiy') returning ref(Student) into Univ1 ;


insert into Student(name,regno,department,ownedby) values('ani',201,'cse',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('aadh','sainagar','chennai',Student1);

insert into Univ(name,address) values('Madras','chennai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('priya',202,'ece',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('Paul ','vellore','gandhi nagar',Student1);

insert into Univ(name,address) values('Thiruvallur','chennai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('bhaviya',203,'eee',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('anand ','trichy','anna salai',Student1);

insert into Univ(name,address) values('periyar','chennai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('mano',204,'IT',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('krish','madurai','kambam',Student1);

insert into Univ(name,address) values('sathyabama','chennai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('surya',205,'cse',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('karthi','arani','chethpait',Student1);

insert into Univ(name,address) values('bharathi','kovai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('malathi',206,'IT',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in)
values('ramani','thirunelveli','bharathinagar',Student1);

insert into Univ(name,address) values('bharathidasan','chennai') returning ref(Student) into


Univ1;
insert into Student(name,regno,department,ownedby) values('divi',207,'ece',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in)
values('kalai','villupuram','bharathinagar',Student1);

insert into Univ(name,address) values('anna','kovai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('sandhiya',208,'ece',Univ1)
returning ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('anadhi','villupuram','kamarajar
salai',Student1);
insert into Univ(name,address) values('anna','madurai') returning ref(Student) into Univ1;
insert into Student(name,regno,department,ownedby) values('rahini',209,'civil',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('mohan','salem','mgr street',Student1);

insert into Univ(name,address) values('Dr.MGR','chennai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('vinay',210,'eee',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('vinod','chennai','bharathi
street',Student1);

insert into Univ(name,address) values('anna','chennai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('akila',211,'ece',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('vijay','madurai','balaji street',Student1);
insert into Employee(name,street,city,starred_in) values('anusha','palani','EVP street',Student1);
insert into Employee(name,street,city,starred_in) values('julie','chennai','TVS street',Student1);

insert into Univ(name,address) values('bharathi','chennai') returning ref(Student) into Univ1;


insert into Student(name,regno,department,ownedby) values('vimal',211,'cse',Univ1) returning
ref(Employee) into Student1;
insert into Employee(name,street,city,starred_in) values('uma','theni','anna street',Student1);

Execute these quesries .


Step 6: TO DISPLAYING EMPLOYEE AND STUDENT DETAILS:
Select * from Student;
Select * from Employee;

Student details:

Employee details:
Step 7: TO MODIFY THE DETAILS
update Student s set s.name='mano' where s.name='ani';

Step 8: TO DELETE THE DETAILS


delete from student where name ='mano';
Step 9: For UML diagram

Extend these
Example->Meta Schema->Classes->UML Diagram

Step 10: Stop after creating, inserting, updating, and deleting the details

RESULT:
Thus an Enhanced Entity Relationship (EER) Model for university database by using Matisse
Enterprise manager has been created and successfully executed the following
i. Insert details in each object.
ii. Display the Employee details.
iii. Display Student Details.
iv. Modify person details.
v. Delete person details
RESULT:
Parallel database -1

AIM:
To develop an university counselling application for engineering
colleges.

Software Objective:
The college, department and vacancy details are maintained in 3 sites.
Students are allocated colleges in these 3 sites simultaneously. Implement this
application using parallel database. [State any assumptions you have made].

Assumption Made:
Two forms are created for viewing available seats and allocating seats.
The first form will view only the available seats in each site. The second form is
used to allocate seats for students. If a seat is allocated to a student, all the 3
sites are updated in parallel.
Implementation:

Form 1: To view Number of seats available

Form 2: To allocate seats for a student (Before Updating)


Form 2: To allocate seats for a student (Before Updating)

Codes:
Public Class Form2

Dim cnn As New OleDb.OleDbConnection

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button7.Click

Me.Close()

End Sub

Private Sub RefreshData()

If Not cnn.State = ConnectionState.Open Then

'open connection

cnn.Open()

End If

Dim da As New OleDb.OleDbDataAdapter("SELECT CollegeName,Department,Vacancy


FROM Site1", cnn)
Dim db As New OleDb.OleDbDataAdapter("SELECT CollegeName,Department,Vacancy
FROM Site2", cnn)

Dim dc As New OleDb.OleDbDataAdapter("SELECT CollegeName,Department,Vacancy


FROM Site3", cnn)

Dim dt As New DataTable

Dim du As New DataTable

Dim dv As New DataTable

'fill data to datatable

da.Fill(dt)

db.Fill(du)

dc.Fill(dv)

'offer data in data table into datagridview

Me.Site1DataGridView.DataSource = dt

Me.Site2DataGridView.DataSource = du

Me.Site3DataGridView.DataSource = dv

'close connection

cnn.Close()

End Sub

Private Sub Site1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal


e As System.EventArgs)

Me.Validate()

Me.Site1BindingSource.EndEdit()

Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)

End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
'TODO: This line of code loads data into the 'Database1DataSet1.Site3' table. You can move,
or remove it, as needed.

Me.Site3TableAdapter1.Fill(Me.Database1DataSet1.Site3)

'TODO: This line of code loads data into the 'Database1DataSet1.Site2' table. You can move,
or remove it, as needed.

Me.Site2TableAdapter1.Fill(Me.Database1DataSet1.Site2)

'TODO: This line of code loads data into the 'Database1DataSet1.Site1' table. You can move,
or remove it, as needed.

Me.Site1TableAdapter1.Fill(Me.Database1DataSet1.Site1)

'TODO: This line of code loads data into the 'Database1DataSet.Site3' table. You can move,
or remove it, as needed.

cnn = New OleDb.OleDbConnection

cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" &


Application.StartupPath & "\Database1.mdb"

'get data into list

Me.RefreshData()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click

Dim cmd As New OleDb.OleDbCommand

If Not cnn.State = ConnectionState.Open Then

'open connection if it is not yet open

cnn.Open()

End If

cmd.Connection = cnn

cmd.CommandText = "UPDATE Site1 SET Vacancy = Vacancy - 1 Where (CollegeName='"


& Me.TextBox3.Text & "')"

cmd.ExecuteNonQuery()
cmd.CommandText = "UPDATE Site2 SET Vacancy = Vacancy - 1 Where (CollegeName='"
& Me.TextBox3.Text & "')"

cmd.ExecuteNonQuery()

cmd.CommandText = "UPDATE Site3 SET Vacancy = Vacancy - 1 Where (CollegeName='"


& Me.TextBox3.Text & "')"

cmd.ExecuteNonQuery()

'refresh data in list

RefreshData()

'clear form

'close connection

cnn.Close()

End Sub

Private Sub Site3DataGridView_CellContentClick(ByVal sender As System.Object, ByVal e


As System.Windows.Forms.DataGridViewCellEventArgs) Handles
Site3DataGridView.CellContentClick

End Sub

End Class

Conclusion:
This software provides an efficient way of managing university
counselling application for engineering colleges.
Parallel database -2

AIM:
To implement parallel join and parallel sort algorithms to get marks from
different colleges of the university and publish 10 ranks for each discipline.

Objective:
There are 5 processors working in parallel environment and producing
output. The output record contains college details and student mark information.
Implement parallel join and parallel sort algorithms to get the marks from different
colleges of the university and publish 10 ranks for each discipline.

Assumption Made:
Five tables are created in which each table represents a college. Each table
contains various departments and its overall percentage. Query is written to extract
the details from all the 5 tables in parallel and colleges are arranged based on their
department overall percentage.
Implementation:
Creating of Tables
SQL> create table REC (id int, collg varchar(20), cse int, mech int, it int, civil int, ece int);

Table created.

SQL> create table PEC (id int, collg varchar(20), cse int, mech int, it int, civil int, ece int);

Table created.

SQL> create table APEC (id int, collg varchar(20), cse int, mech int, it int, civil int, ece int);

Table created.

SQL> create table SSN (id int, collg varchar(20), cse int, mech int, it int, civil int, ece int);

Table created.

SQL> create table SVCE (id int, collg varchar(20), cse int, mech int, it int, civil int, ece int);

Table created.

Insertion of Values in the tables

Conclusion:
This software provides an efficient way of managing university counselling
application for engineering colleges
SQL> insert into REC values(1,'REC',88,74,90,98,77);

1 row created.

SQL> select * from rec;

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE

----------

1 REC 88 74 90 98

77

SQL> insert into PEC values(1,'PEC',70,78,80,82,80);

1 row created.

SQL> insert into APEC values(1,'APEC',80,71,92,90,70);

1 row created.

SQL> insert into SSN values(1,'SSN',72,73,88,76,67);


1 row created.

SQL> insert into SVCE values(1,'SVCE',68,64,60,91,90);

1 row created.

SQL> select * from rec;

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE

----------

1 REC 88 74 90 98

77

SQL> select * from pec

2 ;

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE

----------

1 PEC 70 78 80 82

80
SQL> select * from ssn;

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE

----------

1 SSN 72 73 88 76

67

SQL> select * from SVCE;

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE

----------

1 SVCE 68 64 60 91

90

SQL> select * from apec;

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE
----------

1 APEC 80 71 92 90

70

SQL> select CSE,MECH from REC;

CSE MECH

---------- ----------

88 74

SQL> select CSE from REC union select CSE from apec;

CSE

----------

80

88

SQL> select CSE from REC union select cse from apec order by desc;

select CSE from REC union select cse from apec order by desc

ERROR at line 1:

ORA-00936: missing expression

SQL> select collg,CSE,mech,it,civil from rec union select collg,cse,mech,it,civil from apec order by
cse desc;

COLLG CSE MECH IT CIVIL

-------------------- ---------- ---------- ---------- ----------

REC 88 74 90 98

APEC 80 71 92 90

SQL> select collg,CSE from rec union select collg,cse from apec union select collg,cse from pec unio

n select collg,cse from ssn union select collg,cse from ssn order by cse;

COLLG CSE

-------------------- ----------

PEC 70

SSN 72

APEC 80

REC 88

SQL> select collg,CSE from rec union select collg,cse from apec union select collg,cse from pec unio

n select collg,cse from ssn union select collg,cse from ssn union select collg,cse from svce order b

y cse;

COLLG CSE

-------------------- ----------

SVCE 68

PEC 70

SSN 72
APEC 80

REC 88

SQL> select collg,mech from rec union select collg,mech from apec union select collg,mech from pec u

nion select collg,mech from ssn union select collg,mech from svce order by mech;

COLLG MECH

-------------------- ----------

SVCE 64

APEC 71

SSN 73

REC 74

PEC 78

SQL> select collg,mech from rec union select collg,mech from apec union select collg,mech from pec u

nion select collg,mech from ssn union select collg,mech from svce order by mech desc;

COLLG MECH

-------------------- ----------

PEC 78

REC 74

SSN 73

APEC 71

SVCE 64

SQL> select collg,mech from rec union select collg,mech from apec union select collg,mech from pec u
nion select collg,mech from ssn union select collg,mech from svce order by mech union select collg,m

ech from rec union select collg,cse from apec union select collg,cse from pec union select collg,cse

from ssn union select collg,cse from svce order by cse;

select collg,mech from rec union select collg,mech from apec union select collg,mech from pec union

ERROR at line 1:

ORA-00933: SQL command not properly ended

SQL> select collg,mech from rec union select collg,mech from apec union select collg,mech from pec u

nion select collg,mech from ssn union select collg,mech from svce order by mech ;unionselect collg,m

ech from rec union select collg,cse from apec union select collg,cse from pec union select collg,cse

from ssn union select collg,cse from svce order by cse;

select collg,mech from rec union select collg,mech from apec union select collg,mech from pec union

ERROR at line 1:

ORA-00911: invalid character

SQL> select collg,it from rec union select collg,it from apec union select collg,it from pec union s

elect collg,it from ssn union select collg,it from svce order by it;

COLLG IT

-------------------- ----------

SVCE 60

PEC 80
SSN 88

REC 90

APEC 92

SQL> select collg,ece from rec union select collg,ece from apec union select collg,ece from pec unio

n select collg,ece from ssn union select collg,ece from svce order by ece;

COLLG ECE

-------------------- ----------

SSN 67

APEC 70

REC 77

PEC 80

SVCE 90

SQL> select collg,civil from rec union select collg,civil from apec union select collg,civil from pe

c union select collg,civil from ssn union select collg,civil from svce order by civil;

COLLG CIVIL

-------------------- ----------

SSN 76

PEC 82

APEC 90

SVCE 91

REC 98
SQL>

SQL> ((select collg,mech from rec union select collg,mech from apec union select collg,mech from pec

union select collg,mech from ssn union select collg,mech from svce order by mech desc )

2 union

3 (select collg,cse from rec union select collg,cse from apec union select collg,cse from pec uni

on select collg,cse from ssn union select collg,cse from svce order by cse desc)

4 union

5 (select collg,it from rec union select collg,it from apec union select collg,it from pec union

select collg,it from ssn union select collg,it from svce order by it desc)

6 union

7 (select collg,ece from rec union select collg,ece from apec union select collg,ece from pec uni

on select collg,ece from ssn union select collg,ece from svce order by ece desc)

8 union

9 (select collg,civil from rec union select collg,civil from apec union select collg,civil from p

ec union select collg,civil from ssn union select collg,civil from svce order by civil desc));

((select collg,mech from rec union select collg,mech from apec union select collg,mech from pec unio

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> (select * from apec);

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE
----------

1 APEC 80 71 92 90

70

SQL> (select * from apec) union (select * from rec);

ID COLLG CSE MECH IT CIVIL

---------- -------------------- ---------- ---------- ---------- ----------

ECE

----------

1 APEC 80 71 92 90

70

1 REC 88 74 90 98

77

SQL> (select collg,mech from rec union select collg,mech from apec union select collg,mech from pec

union select collg,mech from ssn union select collg,mech from svce order by mech desc )

2 union

3 (select collg,cse from rec union select collg,cse from apec union select collg,cse from pec uni

on select collg,cse from ssn union select collg,cse from svce order by cse desc)

4 union

5 (select collg,it from rec union select collg,it from apec union select collg,it from pec union

select collg,it from ssn union select collg,it from svce order by it desc)
6 union

7 (select collg,ece from rec union select collg,ece from apec union select collg,ece from pec uni

on select collg,ece from ssn union select collg,ece from svce order by ece desc)

8 union

9 (select collg,civil from rec union select collg,civil from apec union select collg,civil from p

ec union select collg,civil from ssn union select collg,civil from svce order by civil desc);

(select collg,mech from rec union select collg,mech from apec union select collg,mech from pec union

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> (select collg,mech from rec union select collg,mech from apec union select collg,mech from pec

union select collg,mech from ssn union select collg,mech from svce order by mech desc )

2 union

3 (select collg,cse from rec union select collg,cse from apec union select collg,cse from pec uni

on select collg,cse from ssn union select collg,cse from svce order by cse desc)

4 ;

(select collg,mech from rec union select collg,mech from apec union select collg,mech from pec union

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> (select collg,mech from rec union select collg,mech from apec union select collg,mech from pec

union select collg,mech from ssn union select collg,mech from svce order by mech desc );
(select collg,mech from rec union select collg,mech from apec union select collg,mech from pec union

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> (select collg,cse from rec union select collg,cse from apec union select collg,cse from pec uni

on select collg,cse from ssn union select collg,cse from svce order by cse desc);

(select collg,cse from rec union select collg,cse from apec union select collg,cse from pec union se

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> ((select collg,mech from rec) union (select collg,mech from apec)union (select collg,mech from

pec) union (select collg,mech from ssn) union (select collg,mech from svce order by mech desc) );

((select collg,mech from rec) union (select collg,mech from apec)union (select collg,mech from pec)

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> (select collg,cse from REC) union (select collg,cse from apec) order by cse;

COLLG CSE

-------------------- ----------
APEC 80

REC 88

SQL> (select collg,mech from rec) union (select collg,mech from apec)union (select collg,mech from p

ec) union (select collg,mech from ssn) union (select collg,mech from svce) order by mech desc;

COLLG MECH

-------------------- ----------

PEC 78

REC 74

SSN 73

APEC 71

SVCE 64

SQL> ((select collg,mech from rec) union (select collg,mech from apec) order by mech desc) union (se

lect collg,mech from rec) union (select collg,mech from apec) order by mech desc));

((select collg,mech from rec) union (select collg,mech from apec) order by mech desc) union (select

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> select collg,mech from rec union select collg,mech from apec union select collg,mech from pec u

nion select collg,mech from ssn union select collg,mech from svce order by mech desc

2 union

3 select collg,mech from rec union select collg,mech from apec union select collg,mech from pec u
nion select collg,mech from ssn union select collg,mech from svce order by mech desc;

union

ERROR at line 2:

ORA-00933: SQL command not properly ended

SQL> select collg,mech from rec union select collg,mech from apec union select collg,mech from pec u

nion select collg,mech from ssn union select collg,mech from svce order by mech desc;

COLLG MECH

-------------------- ----------

PEC 78

REC 74

SSN 73

APEC 71

SVCE 64

SQL> commit

2 l

SQL> commit;

Commit complete.

SQL>
Ex.No:6 ACTIVE DATABASE

Date:

AIM:

To create triggers and assertions for Bank database handling deposits and loan and
admission database handling seat allocation and vacancy position.

PROCEDURE:

1. Start the program


2. Create the relational database schema and implement the following trigger and
assertions.
3. When a deposit is made by customer, create a trigger for updating customers account
and bank account.
4. When a loan is issued to the customer, create a trigger for updating customer’s loan
account and bank account.
5. Create assertion for bank database so that the total loan amount does not exceed the
total balance in the bank.
6. When an admission is made, create a trigger for updating the seat allocation details
and vacancy position.
7. Stop the program.

STEP 1:

Create a trigger for updating customers account and bank account when a deposit is made
by an customer.

Syntax:

Query1: create table bank(bank_no number primary key,bank_name varchar2(50),


balance number);

Table Created.

Query2: create table cust(acc_no number primary key,cust_name varchar2(50),acc_type


varchar2(15),balance number);

Table Created.
Query3: create table deposit(deposit_id number,bank_no number,acc_no number,amount
number,foreign key (acc_no) references cust(acc_no),foreign key (bank_no) references
bank(bank_no));

Table Created.

Query4: create sequence deposit_seq start with 1 increment by 1;

Sequence Created.

Query5: create table loan1(loan1_id number,bank_no number,acc_no number,amount


number,foreign key (acc_no) references cust(acc_no),foreign key (bank_no) references
bank(bank_no));

Table Created.

Query 6:create sequence loan1_seq start with 1 increment by 1;

Sequence Created.

Trigger 1:

create or replace

trigger deposit_trg

after insert on deposit

for each row

begin

update bank set balance=balance+:new.amount where bank_no=:new.bank_no;

update cust set balance=balance+:new.amount where acc_no=:new.acc_no;

end;

Statement Processed.

Trigger 2:

create or replace

trigger loan1_trg

after insert on loan1


for each row

begin

update bank set balance=balance-:new.amount where bank_no=:new.bank_no;

update cust set balance=balance+:new.amount where acc_no=:new.acc_no;

end;

Statement Processed.

Query7: insert into bank values(002,'INDIAN_BANK',5000000);

1 row(s) inserted.

Query8: insert into bank values(003,'CANARA_BANK',3000000);

1 row(s) inserted.

Query9: insert into cust values(1234,'SANTHOSH','SAVINGS',75000);

1 row(s) inserted.

Query10: insert into deposit values(deposit_seq.nextval,002,1234,2500);

1 row(s) inserted.

Query11: select * from cust;

Query12: select * from bank;

Query13: insert into cust values(12345,'SANTHOSH','LOAN',0);

1 row(s) inserted.

Query14: insert into loan1 values(loan1_seq.nextval,002,1235,200);

1 row(s) inserted.
Query15: select * from bank;
Query16:select * from cust;

STEP 2:

Create a trigger for updating customer’s loan account and bank account when a loan is
issued to the customer.

Syntax:

Query1: create table bank(bank_no number primary key, bank_namevarchar2(50),


balance number);

Table Created.
Query2: create table cust(acc_no number primary key,cust_name varchar2(50),acc_type
varchar2(15),balance number);

Table Created.

Query3: create table loan3(loan_id number,bank_no number,acc_no number,amount


number,foreign key (acc_no) references cust(acc_no),foreign key (bank_no) references
bank(bank_no));

Table Created.

Query4: create sequence loan3_seq start with 1 increment by 1;

Sequence Created.

Trigger 1:

create or replace

trigger loan3_trg

after insert on loan3

for each row

begin

update bank set balance=balance-:new.amount where bank_no=:new.bank_no;

update cust set balance=balance+:new.amount where acc_no=:new.acc_no;

end;

Statement Processed.

Query5: insert into bank values(002,'INDIAN_BANK',5000);

1 row(s) inserted.

Query6: insert into bank values(003,'CANARA_BANK',3000);

1 row(s) inserted.
Query7: insert into cust values(1234,'SANTHOSH','SAVINGS',1500);

1 row(s) inserted.

Query8: select * from cust;

Query9: select * from bank;


Query10: insert into cust values(12345,'SANTHOSH','LOAN',0);

1 row(s) inserted.

Query11: insert into loan1 values(loan3_seq.nextval,002,12345,200);

1 row(s) inserted.

Query12: select * from bank;

Query13: select * from cust;


STEP 3:

Create assertion for bank database so that the total loan amount does not exceed the total
balance in the bank.

Syntax:

Query1: create table bank(bank_no number primary key, bank_namevarchar2(50),


balance number);

Table Created.

Query2: create table cust(acc_no number primary key,cust_name varchar2(50),acc_type


varchar2(15),balance number);

Table Created.

Query3: create table loan3(loan_id number,bank_no number,acc_no number,amount


number,foreign key (acc_no) references cust(acc_no),foreign key (bank_no) references
bank(bank_no));
Table Created.

Query4: create sequence loan3_seq start with 1 increment by 1;

Sequence Created.

Trigger 1:

create or replace

trigger loan3_trg

after insert on loan3

for each row

begin

update bank set balance=balance-:new.amount where bank_no=:new.bank_no;

update cust set balance=balance+:new.amount where acc_no=:new.acc_no;

end;

Statement Processed.

Query 5: insert into bank values(002,'INDIAN_BANK',100000);

1 row(s) inserted.

Query 6: insert into cust values(12345,'SANTHOSH','LOAN',0);

1 row(s) inserted.

Query7:Select * from bank;


select * from cust;

Query 7: insert into loan3 values(loan3_seq.nextval,002,12345,100010);


Cannot insert 100010 Since the total loan amount exceeds the total bank balance

STEP 4:

Create a trigger for updating the seat selection details and vacancy position, when an
admission is made.

Syntax:

Query1: create table admission(branch varchar2(50) primary key, available_seats


number, allocated_seats number, vacancy_seats number);

Table Created.

Query2: alter table admission ADD CONSTRAINT chk_admission


CHECK(allocated_seats<251);

Table Created.

Query3: create table selection(branch varchar2(50), selected_seats number, foreign


key(branch)references admission(branch));

Table Created.

Query4: insert into admission values('cse',250,0,250);


1 row(s) inserted.

Trigger 1:

create or replace

trigger selection_trg

after insert on selection

for each row

begin

update admission set allocated_seats =allocated_seats+:new.selected_seats;

update admission set vacancy_seats=vacancy_seats-:new.selected_seats;

end;

Statement Processed.

Query5: insert into selection values('cse',4);

1 row(s) inserted.
Query6: select * from selection;
Query7: select * from admission;

RESULT:

Thus the triggers and assertions has been created, executed and verified
successfully.
Ex.No:7 DEDUCTIVE DATABASE

Date:

AIM:

To construct a knowledge database for kinship domain (family relations) with facts.
Extract the following relations using rules:
Parent, Sibling, Brother, Sister, Child, Daughter, Son, Spouse, Wife, husband, Grandparent,
Grandchild, Cousin, Aunt and Uncle.

PROCEDURE:
1. Start
2. Download the Prolog 7.1.11 software and install it.
3. Open Prolog 7.1.11 and click onto the File -> New and save the filename with
filename.pl and click save.
4. Type the program and save it as File -> Save buffer and close the current window.
5. Open the Main window and type consult(filename). to compile the program.
6. If it is true then the program has no errors.
7. Then check for each and every condition.
8. Terminate the program.

PROGRAM:

Step 1:
In the edit window type the following code. Describe each and every conditions and
relations here.

male(raja).
male(bharani).
male(pandithurai).
male(kannan).
male(semban).
male(ragul).
female(ranimuthu).
female(poorni).
female(anburani).
female(jansi).
female(moni).
female(vaishu).
female(inbam).
female(nive).

parent(anburani,pandithurai).
parent(anburani,ranimuthu).
parent(anburani,jansi).
parent(semban,raja).
parent(seemban,kannan).
parent(semban,inbam).
parent(raja,bharani).
parent(raja,poorni).
parent(raja,rahul).
parent(ranimuthu,bharani).
parent(ranimuthu,poorni).
parent(ranimuthu,rahul).
parent(jansi,moni).
parent(jansi,vaishu).
parent(kannan,moni).
parent(kannan,vaishu).
parent(pandithurai,nive).
married(raja,ranimuthu).
married(kannan,jansi).

sister(X,Y):- female(X),parent(Par,X),parent(Par,Y), X\=Y.


daughter(X,Y):- female(X),parent(Y,X).
son(X,Y):- male(X),parent(Y,X).
brother(X,Y):-male(X),parent(Somebody,X),parent(Somebody,Y), X\=Y.
father(X,Y):-male(X),parent(X,Y).
mother(X,Y):-female(X),parent(X,Y).
grandparent(X,Y):-parent(Z,X),parent(Z,Y).
sibling(X,Y):-parent(Z,X),parent(Z,Y).
aunt(X,Y):-female(X),sister(X,Mom),mother(Mom,Y).
aunt(X,Y):-female(X),sister(X,Dad),father(Dad,Y).
uncle(X,Y):-brother(X,Par),parent(Par,Y).
cousin(X,Y):-uncle(Unc,X),father(Unc,Y).
spouse(X,Y):-married(X,Y).
husband(X,Y):-male(X),married(X,Y).
wife(Y,X):-female(Y),married(X,Y).
child(Y,X):-parent(X,Y).
grandchild(X,Z):-grandparent(Z,X).

Step 2:
Compile and run the coding for all the relations given above.
RESULT:
Thus the Deuctive Database for Kinship domain with facts are executed and verified
successfully.
EX.NO:8 WEKA TOOL
DATE:
AIM:
To work with weka tool classification and clustering algorithms for
the given training data and test with unknown samples.
WHAT IS WEKA?
WEKA stands for Waikato Environment for Knowledge
Learning. It was developed by the University of Waikato, New
Zealand.
WEKA supports many data mining and machine learning
algorithms, including data re-processing, classification, clustering,
regression and association rule extraction.
The workflow of WEKA would be as follows:
Data->Pre-processing->Data Mining-> Knowledge
PROCEDURE:
Step 1: From windows desktop,
 click “Start”, choose “All programs”,
 Choose “Weka 3.7” to start Weka
 Then the first interface window appears:
 Weka GUI Chooser Window
Step 2: Create one file in ARFF file format in notepad.
An ARFF file consists of two distinct sections:
 The Header section defines attribute name, type and
relations, start with a keyword.
@Relation <data-name>
@attribute <attribute-name> <type> or {range}
 The Data section lists the data records, starts with
@Data list of data instances
 Any line start with % is the comments.

 After this save this file in arff extensions.


Step 3: Click on ‘Explorer’ button in the ‘WEKA GUI Chooser’
window.
 ‘WEKA Explorer’ window appears on a screen.

Step 4: Select open file button in Explorer window.

 It brings up a dialog box allowing we to browse for the data


file on the local file system, choose “weather.arff” file.

 Click ‘Open’ button to open the file.


Step 5: Select attributes from ‘Selected attribute’ box .Then it will
show the statistic at the right bottom corner.
Step 6: Building “Classifiers”

Classifiers in WEKA are the models for predicting nominal or numeric


quantities. The learning schemes available in WEKA include decision
trees and lists, instance-based classifiers, support vector machines,
multi-layer perceptrons, logistic regression, and bayes’ nets. “Meta”-
classifiers include bagging, boosting, stacking, error-correcting output
codes, and locally weighted learning .
 Once we have our data set loaded, all the tabs are available to us.
Click on the ‘Classify’ tab.
 Then click on “Use training set” button under Test option in
“Classifer window”.
 Use training set.:Evaluates the classifier on how well it predicts
the class of the instances it was trained on.
Step 7: Choosing a Classifier
Click on ‘Choose’ button in the ‘Classifier’ box just below the tabs and
select J48
classifier WEKA -> Classifiers ->Trees->J48.

Step 8: Identify what is included into the output. In the ‘Classifier


evaluation options’ make sure that the following options are checked :
1. Output model. The output is the classification model on the full
training set, so that it can be viewed, visualized, etc.
2. Output per-class stats. The precision/recall and true/false statistics
for each class output.
3. Output confusion matrix. The confusion matrix of the classifier’s
predictions is included in the output.
4. Store predictions for visualization. The classifier’s predictions are
remembered so that they can be visualized.
5. Set ‘Random seed for Xval / % Split’ to 1.This specifies the random
seed used when randomizing the data before it is divided up for
evaluation purposes.
6. Output entropy evaluation measures. Entropy evaluation measures
are included in the output.
7. Output predictions. The classifier’s predictions are remembered so
that they can be visualized.

Step 8: Once the options have been specified, we can run the
classification algorithm. Click on ‘Start’ button to start the learning
process. We can stop learning process at any time by clicking on ‘Stop’
button.
 When training set is complete, the ‘Classifier’ output area on the
right panel of ‘Classify’ window is filled with text describing the
results of training and testing. A new entry appears in the ‘Result
list’ box on the left panel of ‘Classify’ window.
Sept 9: Visualization of Results
After training a classifier, the result list adds an entry. WEKA lets we to
see a graphical representation of the classification tree. Right-click on
the entry in ‘Result list’ for which we would like to visualize a tree. It
invokes a menu containing the following items:

 Select the item ‘Visualize tree’; a new window comes up to the


screen displaying the tree.
CLASSIFICATION OUTPUT:

=== Run information ===

Scheme: weka.classifiers.trees.J48 -C 0.25 -M 2


Relation: weather
Instances: 14
Attributes: 5
outlook
temperature
humidity
windy
play
Test mode: evaluate on training data

=== Classifier model (full training set) ===

J48 pruned tree


------------------

outlook = sunny
| humidity <= 75: yes (2.0)
| humidity > 75: no (3.0)
outlook = overcast: yes (4.0)
outlook = rainy
| windy = TRUE: no (2.0)
| windy = FALSE: yes (3.0)

Number of Leaves : 5

Size of the tree : 8

Time taken to build model: 0.05 seconds

=== Evaluation on training set ===

Time taken to test model on training data: 0.02 seconds

=== Summary ===

Correctly Classified Instances 14 100 %


Incorrectly Classified Instances 0 0 %
Kappa statistic 1
Mean absolute error 0
Root mean squared error 0
Relative absolute error 0 %
Root relative squared error 0 %
Coverage of cases (0.95 level) 100 %
Mean rel. region size (0.95 level) 50 %
Total Number of Instances 14

=== Detailed Accuracy By Class ===

TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area Class
1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 yes
1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 no
Weighted
Avg. 1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000

=== Confusion Matrix ===

a b <-- classified as
9 0 | a = yes
0 5 | b = no
Stucture of tree:

Step 10: Clustering Data


WEKA contains “clusterers” for finding groups of similar
instances in a dataset. The clustering schemes available in WEKA are k-
Means, EM, Cobweb, X-means, FarthestFirst. Clusters can be visualized
and compared to “true” clusters (if given). Evaluation is based on log
likelihood if clustering scheme produces a probability distribution .
For this we will use weather data that is contained in “weather.arff” file
and analyze it with k-means clustering scheme.
 In ‘Preprocess’ window click on ‘Open file…’ button and select
“weather.arff” file. Click‘Cluster’ tab at the top of WEKA
Explorer window.
Step 11: Choosing Clustering Scheme
 In the ‘Clusterer’ box click on ‘Choose’ button. In pull-down menu
select WEKA ->Clusterers, and select the cluster scheme
‘SimpleKMeans’. Some implementations of K-means only allow
numerical values for attributes; therefore, we do not need to use a
filter.
 Once the clustering algorithm is chosen, right-click on the
algorithm, “weak.gui.GenericObjectEditor” comes up to the
screen. Set the value in “numClusters” box to 5(instead of default
2) because you have five clusters in your .arff file. Leave the value
of ‘seed’ as is. The seed value is used in generating a random
number, which is used for making the initial assignment of
instances to clusters. Note that, in general, K-means is quite
sensitive to how clusters are initially assigned. Thus, it is often
necessary to try different values and evaluate the results.
Step 12: Once the options have been specified, you can run the
clustering algorithm. Click on the ‘Start’ button to execute the
algorithm.
When training set is complete, the ‘Cluster’ output area on the right
panel of ‘Cluster’ window is filled with text describing the results of
training and testing. A new entry appears in the ‘Result list’ box on the
left of the result. These behave just like their classification counterparts.
CLUSTERING OUTPUT:

=== Run information ===

Scheme: weka.clusterers.SimpleKMeans -N 2 -A "weka.core.EuclideanDistance -R first-last"


-I 500 -num-slots 1 -S 10
Relation: weather
Instances: 14
Attributes: 5
outlook
temperature
humidity
windy
play
Test mode: evaluate on training data

=== Clustering model (full training set) ===

kMeans
======

Number of iterations: 3
Within cluster sum of squared errors: 16.237456311387238
Missing values globally replaced with mean/mode

Cluster centroids:
Cluster#
Attribute Full Data 0 1
(14) (9) (5)
==============================================
outlook sunny sunny overcast
temperature 73.5714 75.8889 69.4
humidity 81.6429 84.1111 77.2
windy FALSE FALSE TRUE
play yes yes yes

Time taken to build model (full training data) : 0 seconds

=== Model and evaluation on training set ===

Clustered Instances

0 9 ( 64%)
1 5 ( 36%)
Step 13: Visualization of Results
 Another way of representation of results of clustering is through
visualization. Right-click on the entry in the ‘Result list’ and select
‘Visualize cluster assignments’ in the pull-down window.

Step 14:
 This brings up the ‘Weka Clusterer Visualize’ window. On the
‘Weka Clusterer Visualize’ window, beneath the X-axis selector
there is a dropdown list, ‘Colour’, for choosing the color scheme.
This allows we to choose the color of points based on the attribute
selected. Below the plot area, there is a legend that describes what
values the colors correspond to.. Leftclick on ‘3’ in the ‘Class
colour’ box and select lighter color from the color palette.
 To the right of the plot area there are series of horizontal strips.
Each strip represents an attribute, and the dots within it show the
distribution values of the attribute. we can choose what axes are
used in the main graph by clicking on these strips (left-click
changes X-axis, right31 click changes Y-axis).

 The initially correctly clustered instances are represented by blue


crosses, incorrectly clustered once represented as rd crosses. By
changing the color dimension to other attributes, we can see their
distribution within each of the clusters.

Step 15: Stop

RESULT:

Thus worked with weka tool, classification and clustering algorithms for
the given training data and test with unknown samples are created,
executed and verified successfully.
Query Processing

AIM:
To implement query optimizer with relational algebraic expression
construction and execution plan generation for choosing an efficient execution
strategy for processing the given query

Objective:
To design employee database and test the algorithm with following sample
queries,

a) Select empid,empname from employee where experience > 5.


b) Find all managers working at London Branch.

Query processing: A 3-step process that transforms a high-level query (of


relational calculus/SQL) into an equivalent and more efficient lower-level query
(of relational algebra).

1. Parsing and translation

– Check syntax and verify relations.

– Translate the query into an equivalent relational algebra expression.

2. Optimization

– Generate an optimal evaluation plan (with lowest cost) for the query plan.

3. Evaluation

– The query-execution engine takes an (optimal) evaluation plan, executes


that plan, and returns the answers to the query.
Query optimization
1. Query optimization aims to minimize the cost function:
2. I/O cost + CPU cost + communication cost
3. Query optimizers vary by search type (exhaustive search, heuristics) and by
type of the algorithm (dynamic, staticand hybrid). Different statistics are
collected to support the query optimization process
4. Query optimizers vary by decision sites (centralized, distributed, hybrid)
5. Query processing is done in the following sequence: query decomposition -
>data
6. Localization -> global optimization -> local optimization

Relational algebra expression


A relational algebra expression can be evaluated in manyways. An annotated
expression specifying detailed evaluationstrategy is called the execution plan
(includes, e.g., whetherindex is used, join algorithms, . . . )

Among all semantically equivalent expressions, the one withthe least costly
evaluation plan is chosen. Cost estimate of aplan is based on statistical information
in the system catalogues.

Eg) π empid,empname,experience (σ (experience>5) (employee))


Implementation:
Creating of Tables
Step 1: click new relation
Step 2: Click on Add tuple to add row or Add Column to add column.
Insertion of Values in the tables
Just click on the field name to change the column name and enter
the values directly as much as need and finally click ok.
Queries:
1. Select empid,empname from employee where experience > 5.
π empid,empname,experience (σ (experience>5) (employee))
2. Find all managers working at London Branch.
π empid,designation (σ branch=='london' (branches))
3. Display employee id,name,designation and branch.

σempid,empname,experience,empid,branch,designation(employeeᐅᐊbranch
es)
4. View the employee id and branch alone from two tables using join.

πempid,branch (employeeᐅᐊbranches)
5. Select all the employees who have experience more than ten years.

σ experience>10 (employee)
Conclusion:
Thus, to implement query optimizer with relational algebraic expression
construction and execution plan generation for choosing an efficient execution
strategy for processing the given query is executed and implemented successfully.
Aim :
Design XML Schema for the given company database

Department ( deptName, deptNo, deptManagerSSN, deptManagerStartDate,

deptLocation )

Employee ( empName, empSSN, empSex, empSalary, empBirthDate,

empDeptNo, empSupervisorSSN, empAddress, empWorksOn)

Project ( projName, projNo, projLocation, projDeptNo, projWorker )

a. Implement the following queries using XQuery and XPath

1)Retrieve the department name, manager name, and manager salary for every

department’

2)Retrieve the employee name, supervisor name and employee salary for each

employee who works in the Research Department.

3)Retrieve the project name, controlling department name, number of employees

and total hours worked per week on the project for each project.

4)Retrieve the project name, controlling department name, number of employees

and total hours worked per week on the project for each project with more than

one employee working on it

b.Implement a storage structure for storing XML database and test with the above

schema.

1) Open Db2 in Vmware


2) go to console centre
3) Select 'Create New database'
4) give database name and then click next until finish(default storage path will be set)
a new database with the name given will be opened under ALL DATABASES

5) Select tables -> Create a new table -> give table name
click next till finish. Anew table will be created.

6) To add columns to it ->click ADD on the right hand side

7) give column name as per the table and the data type, for instance, Employee ( empName, empSSN,
empSex, empSalary, empBirthDate, empDeptNo, empSupervisorSSN, empAddress, empWorksOn)

column name Data Type


empName varchar
empSSN smallINT
empSalary bigINT
empBirthDate Date
empDeptNo smallINT
empSupervisorSSN smallINT
empAddress LongVarchar
empWorkerOn Date
Empdetails xml
8) To Connect to a database
Give -> connect to DATABASENAME

Go to Command editor or click Query link which is present at the bottom link by clicking any table

9) To insert values at run time

insert into Department values ('deptname', deptno, deptManagerSSN, deptLocation,


<xmlattribute>xmldata</xmlattribute>

insert into Department values ('Management', 01, 343, 03-04-2001', 'India',


<'deptName>Management</deptName>');
for Employee table
for Project Table
After Inserting values into the table u will get the following

For Department Table


Employee Table
project table
The XML files generated would be like as follows
To check whether data can be fetched from the xml file

To perform Xquery on XML data

You might also like