Sunteți pe pagina 1din 44

KL University

Page No.:

Lab Experiment 1 Date:

Design and Create Relational Schema for Employee project


Management system

Aim:

The Aim of this program is to understand the database objects


primarily tables and then identifying database constraints to construct
the database of records.

Description:

To create database containing records for each table created in


the database and then use simple select commands to retrieve the data
from the database.

Code:

a) Create the tables with the appropriate integrity constraints

create table Employee( FName varchar(30), MInit varchar(30), LName


varchar(30),SSN varchar(10) primary key, DOB date, Address
varchar(30),Sex char(1),Salary number(7,2));

create table Department (DName varchar(30),DNumber number(1)


primary key, MGRstartdate date) ;

create table Dept_Locations (Dept_Location varchar(20)) ;

alter table Employee add SuperSSN varchar(10) references


Employee(SSN) ;

alter table Employee add DNo number(1) references


Department(DNumber) ;

alter table Department add MgrSSN varchar(20) references


Employee(SSN) ;

alter table Dept_Locations add DNumber number(1) references


Department(DNumber) ;
ID No.:09100469
KL University
Page No.:

alter table Dept_Locations add primary key (DNumber, Dept_Location) ;

create table Project (PName varchar(20), PNumber number(10) primary


key, PLocation varchar(10)) ;

alter table Project add DNum number(10) references


Department(DNumber) ;

create table Works_On (ESSN varchar(10),Hours number(5)) ;

alter table Works_On add PNo number(10) references


Project(PNumber) ;

alter table Works_On add primary key (ESSN,PNo) ;

create table Dependent(ESSN varchar(10), DependentName


varchar(20),Sex char(1),BDate date, Relationship varchar(10));

b) Insert the records as per the input given with proper constraint
specification

insert into Employee values ('john','b','smith','123456789','09-jan-


1965','731 fondren houston TX','m','30000','','') ;

insert into Employee values ('franklin','t','wong ','333445555','00384-dec-


1955','638 voss houston TX','m','40000','','') ;

insert into Employee values ('Charan','c','zelaya ','999887777','19-jul-


1968','3321 castle spring TX','f','25000','','') ;

insert into Employee values ('jennifer','s','wallace','987654321','20-jun-


1941','291 berry bellaire TX','f','43000','','') ;

insert into Employee values ('ramesh','k','narayan','666884444','15-sep-


1962','975 fire oak humble TX','m','38000','','') ;

insert into Employee values ('joyce','a','english','453453453','31-jul-


1972','5631 rice houston TX','m','25000','','') ;

ID No.:09100469
KL University
Page No.:

insert into Employee values ('ahmad','v','jabbar','987987987','29-mar-


1969','980 dallas houston TX','m','25000','','') ;

insert into Employee values ('james','e','borg','888665555','10-nov-


1937','450 stone houston TX','m','55000','''') ;

--->

insert into Department values ('research','5','22-may-1988','333445555') ;

insert into Department values ('administration','4','01-jan-


1995','987654321') ;

insert into Department values ('headquarters','1','19-jun-


1981','888665555') ;

--->

insert into Dept_Locations values ('houston','1') ;

insert into Dept_Locations values ('stafford','4') ;

insert into Dept_Locations values ('sugarland','5') ;

insert into Dept_Locations values ('houston','5') ;

insert into Dept_Locations values ('bellaire','5') ;

--->

insert into Project values ('productx','1','bellaire',5) ;

insert into Project values ('producty','2','sugarland',5) ;

insert into Project values ('product z','3','houston',5) ;

insert into Project values ('computerisation','6','stafford',4) ;

insert into Project values ('reorganisation','8','houston',1) ;

insert into Project values ('new benefits','9','stafford',4) ;

--->

insert into Works_On values ('123456789','32.5','1') ;

insert into Works_On values ('123456789','7.5','2') ;


ID No.:09100469
KL University
Page No.:

insert into Works_On values ('666884444','40','3') ;

insert into Works_On values ('453453453','20','1') ;

insert into Works_On values ('453453453','20','2') ;

insert into Works_On values ('333445555','10','2') ;

insert into Works_On values ('333445555','10','3') ;

insert into Works_On values ('333445555','10','6') ;

insert into Works_On values ('333445555','10','8') ;

insert into Works_On values ('999887777','30','9') ;

insert into Works_On values ('999887777','10','6') ;

insert into Works_On values ('987987987','35','6') ;

insert into Works_On values ('987987987','5','9') ;

insert into Works_On values ('987654321','15','8') ;

insert into Works_On values ('987654321','20','9') ;

insert into Works_On values ('888665555','','8') ;

--->

Insert into Dependent values('333445555','alice','f','05-apr-


1986','daughter') ;

insert into Dependent values('333445555','theodore','m','25-oct-


1983','son') ;

insert into Dependent values('333445555','joy','f','03-may-


1958','spouse');

insert into Dependent values('987654321','abner','m','28-feb-


1942','spouse') ;

insert into Dependent values('123456789','michael','m','04-jan-


1988','son') ;

ID No.:09100469
KL University
Page No.:

insert into Dependent values('123456789','alice','f','30-dec-


1988','daughter') ;

insert into Dependent values('123456789','elizabeth','f','05-may-


1967','spouse') ;

--->

update Employee set DNo=5 where SSN=333445555 ;

update Employee set DNo=1 where SSN=888665555;

update Employee set DNo=4 where SSN=987987987;

update Employee set DNo=5 where SSN=453453453;

update Employee set DNo=5 where SSN=666884444 ;

update Employee set DNo=4 where SSN=987654321 ;

update Employee set DNo=4 where SSN=999887777 ;

update Employee set DNo=5 where SSN=123456789 ;

--->

update Employee set SuperSSN=null where SSN=888665555 ;

update Employee set SuperSSN=987654321 where SSN=987987987 ;

update Employee set SuperSSN=333445555 where SSN=453453453 ;

update Employee set SuperSSN=333445555 where SSN=666884444 ;

update Employee set SuperSSN=888665555 where SSN=987654321 ;

update Employee set SuperSSN=987654321 where SSN=999887777 ;

update Employee set SuperSSN=888665555 where SSN=333445555 ;

update Employee set SuperSSN=333445555 where SSN=123456789 ;

ID No.:09100469
KL University
Page No.:

c) List the details from each table data with select statement

 select * from Employee;

FNAME M LNAME SSN BDATE ADDRESS

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


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

S SALARY SUPERSSN DNO

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

john b smith 123456789 09-JAN-65 73 fondren,houston TX


m 30000 333445555 5

franklin t wong 333445555 08-DEC-55 638 voss houston TX


m 40000 888665555 5

Charan c zelaya 999887777 19-JUL-68 3321 castle


spring TX f 25000 987654321 4

jennifer s wallace 987654321 20-JUN-41 291 berry bellaire TX


f 43000 888665555 4

ramesh k narayan 666884444 15-SEP-62 975 fire oak humble TX


m 38000 333445555 5

joyce a english 453453453 31-JUL-72 5631 rice houston TX


m 25000 333445555 5

ahmad v jabbar 987987987 29-MAR-69 980 dallas houston TX


m 25000 987654321 4

ID No.:09100469
KL University
Page No.:

james e borg 888665555 10-NOV-37 450 stone houston TX


m 55000 - 1

 select * from Department;

DNAME DNUMBER MGRSTARTD MGRSSN

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

research 5 22-MAY-88 333445555

administration 4 01-JAN-95 987654321

headquarters 1 19-JUN-81 888665555

 select * from Dept_Locations;

DEPT_LOCATION DNUMBER

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

houston 1

stafford 4

bellaire 5

houston 5

sugarland 5

ID No.:09100469
KL University
Page No.:

 select * from Works_On;

ESSN HOURS PNO

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

123456789 33 1

123456789 8 2

666884444 40 3

453453453 20 1

453453453 20 2

333445555 10 2

333445555 10 3

333445555 10 6

333445555 10 8

999887777 30 9

999887777 10 6

987987987 35 6

987987987 5 9

987654321 15 8

987654321 20 9

888665555 8

ID No.:09100469
KL University
Page No.:

 select * from Dependent;

ESSN DEPENDENTNAME S BDATE RELATIONSHIP

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

333445555 alice f 05-APR-86 daughter

333445555 theodore m 25-OCT-83 son

333445555 joy f 03-MAY-58 spouse

987654321 abner m 28-FEB-42 spouse

123456789 michael m 04-JAN-88 son

123456789 alice f 30-DEC-88 daughter

123456789 elizabeth f 05-MAY-67 spouse

 select * from Project;

PNAME PNUMBER PLOCATION DNUM

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

productx 1 bellaire 5

producty 2 sugarland 5

product z 3 houston 5

computerisation 6 stafford 4

reorganisation 8 houston 1

new benefits 9 stafford 4

ID No.:09100469
KL University
Page No.:

Lab Experiment 2 Date:

Manipulating Data from Employee Project Management System

Aim:

The aim of this program is to understand the database objects primarily


tables and then identifying database constraints to retrieve the database
of records and to apply basic DML commands to display the data.

Code:

a) Retrieve SSN values of the employees

select SSN from Employee;

SSN

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

123456789

333445555

453453453

666884444

888665555

987654321

987987987

999887777

ID No.:09100469
KL University
Page No.:

b) Retrieve the Birthdate and Address of the employee whose name


is 'John B. Smith'.

select dob,Address from Employee where FName='john' and MInit='b'


and LName='smith';

DOB ADDRESS

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

09-JAN-65 731 fondren houston TX

c) List the details of all employees who are working in the department
number 4

select * from Employee where DNo='4';

FNAME M LNAME SSN BDATE ADDRESS

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


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

S SALARY SUPERSSN DNO

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

Charan c zelaya 999887777 19-JUL-68 3321 castle


spring TX f 25000 987654321 4

jennifer s wallace 987654321 20-JUN-41 291 berry bellaire TX


f 43000 888665555 4

ID No.:09100469
KL University
Page No.:

ahmad v jabbar 987987987 29-MAR-69 980 dallas houston TX


m 25000 987654321 4

d) List the details of all female supervisors.

select * from Employee where SSN in (select SuperSSN from Employee


where Sex='f');

FNAME M LNAME SSN BDATE ADDRESS

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


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

S SUPERSSN DNO SALARY

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

jennifer s wallace 987654321 20-JUN-41 291 berry bellaire TX

f 888665555 4 43000

e) List the details of all employees working for the project ProductX.

select FName, LName, Address, SSN from Employee where SSN in


(select ESSN from Works_On where PNo in (select PNumber from
Project where PName='productx'));

FNAME LNAME ADDRESS SSN

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

joyce english 5631 rice houston TX 453453453

john smith 731 fondren houston TX 123456789

ID No.:09100469
KL University
Page No.:

f) Retrieve the name and Address of all employees who work for the
'Research' department.

select FName, LName, Address from Employee, Department where


DName='research' and DNumber=DNo;

FNAME LNAME ADDRESS

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

john smith 731 fondren houston TX

franklin wong 638 voss houston TX

ramesh narayan 975 fire oak humble TX

joyce English 5631 rice houston TX

g) For every project located in 'Stafford', list the project number, the
controlling department number, and the department manager's last
name, Address, and birthdate.

Select PNumber, DNumber, LName, Address, DOB from Project,


Department, Employee where DNumber=DNo and MgrSSN=SSN and
PLocation='stafford';

PNUMBER DNUMBER LNAME ADDRESS DOB

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

6 4 wallace 291 berry bellaire TX 20-JUN-


41

ID No.:09100469
KL University
Page No.:

9 4 wallace 291 berry bellaire TX 20-JUN-


41

h) For each employee, retrieve the employee's name, and the name
of his or her immediate supervisor.

select e.FName, e.LName, s.FName, s.LName from Employee e,


Employee s where e.superSSN=s.SSN;

FNAME LNAME FNAME LNAME

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

john smith franklin wong

ramesh narayan franklin wong

Charan zelaya jennifer Wallace

jennifer Wallace james borg

joyce English franklin wong

ahmad jabbar jennifer Wallace

franklin wong james borg

james borg -

i) How many number of dependents for the employee whose SSN is


123456789

select count(DependentName) from Dependent where


ESSN='123456789';

COUNT (DEPENDENTNAME)

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

ID No.:09100469
KL University
Page No.:

j) Retrieve all employees whose Address is in Houston, Texas.


(Here, the value of the ADDRESS attribute must contain the
substring 'Houston, TX')

select FName, LName from Employee where Address like'%houston,tx


%';

FNAME LNAME

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

john smith

ahmad jabbar

james borg

joyce english

k) Retrieve all employees who were born during the 1950s. (Here, '5'
must be the 8th character of the string (according to format for
date).

select FName, LName from Employee where dob like '------5-';

FNAME LNAME

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

franklin wong

ID No.:09100469
KL University
Page No.:

l) Show the effect of giving all employees who work on the 'ProductX'
project a 10% raise.

select FName, LName, 1.1*Salary as NewSalary from Employee,


Works_On, Project where SSN=ESSN and PNumber=PNo and
PName='productx';

FNAME LNAME NEWSALARY

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

john smith 33000

joyce english 27500

m) List the details of all projects handled by the Administration


Department

select PName, PNumber, PLocation from Project, Department where


DNum=DNumber and DName= ‘Administration’;

PName PNumber PLocation

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

computerization 6 stafford

new benefits 9 stafford

ID No.:09100469
KL University
Page No.:

Lab Experiment 3 Date:

Manipulating Data from Employee Project Management System

Aim:

The aim of this program is to understand the database objects


primarily tables and then identifying database constraints to retrieve the
database of records and to apply complex DML commands to display
the data.

Code:

a) Make a list of all project numbers for projects that involve an


employee whose last name is 'Smith' as a worker or as a manager
of the department that controls the project.

select PNumber from Project, Department, Employee where


DNumber=DNo and MgrSSN=SSN and LName='smith'

union

select PNumber from Project, Works_On, Employee where


PNumber=PNo and ESSN=SSN and LName='smith';

PNUMBER

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

ID No.:09100469
KL University
Page No.:

b) Retrieve the name and Address of all employees who work for the
'Research' department.

select FName, LName, MInit from Employee, Department where


DNumber=DNo and DName='research';

FNAME LNAME ADDRESS

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

john smith 731 fondren houston TX

franklin wong 638 voss houston TX

ramesh narayan 975 fire oak humble TX

joyce English 5631 rice houston TX

c) Retrieve the name of each employee who has a dependent with


the same first name as the employee.

select FName, LName, MInit from Employee where SSN in (select


ESSN from Dependent where FName=DependentName);

no rows selected

ID No.:09100469
KL University
Page No.:

d) Retrieve the name of each employee who works on all the


projects controlled by department number 5

select FName, LName from Employee where SSN in (select ESSN from
Works_On where PNo in (select PNumber from proj0377 where
DNum=5));

FNAME LNAME

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

john smith

franklin wong

ramesh narayan

joyce English

e) Retrieve the names of employees who have no dependents

select FName, LName from Employee where not exists(select * from


Dependent where SSN=ESSN);

FNAME LNAME

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

joyce english

ramesh narayan

james borg

ID No.:09100469
KL University
Page No.:

ahmad jabbar

Charan zelaya

f) Retrieve the social security numbers of all employees who work on


project number 1, 2, or 3.

select ESSN from Works_On where PNo=1 or PNo=2 or PNo=3;

ESSN

----------

123456789

333445555

453453453

666884444

g) Retrieve the names of all employees who do not have supervisors.

select FName, LName from Employee where SuperSSN is null;

FNAME LNAME

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

james borg

h) Find the maximum Salary, the minimum Salary, and the average
Salary among all employees.

select min(Salary), max(Salary), avg(Salary) from Employee;

MIN (SALARY) MAX (SALARY) AVG (SALARY)

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

ID No.:09100469
KL University
Page No.:

25000 55000 35125

i) Find the maximum Salary, the minimum Salary, and the average
Salary among employees who work for the 'Research' department.

select min(Salary), max(Salary), avg(Salary) from Employee,


Department where DNo=dnumber and DName='research';

MIN(SALARY) MAX(SALARY) AVG(SALARY)

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

25000 40000 33250

j) Retrieve the total number of employees in the company and the


number of employees in the 'Research' department.

select count(*) from Employee;

COUNT(*)

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

select count(*) from Employee, Department where DNo=DNumber and


DName='research';

COUNT(*)

ID No.:09100469
KL University
Page No.:

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

k) For each department, retrieve the department number, the number


of employees in the department, and their average Salary

select DNo, count (*), avg (Salary) from Employee group by DNo;

DNO COUNT (*) AVG (SALARY)

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

1 1 55000

5 4 33250

4 3 31000

l) For each project, retrieve the project number, project name, and
the number of employees who work on that project.

select PNumber, PName, count (*) from Project, Works_On where


PNumber=PNo group by PNumber, PName;

PNUMBER PNAME COUNT (*)

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

3 product z 2

6 computerisation 3

1 productx 2

ID No.:09100469
KL University
Page No.:

2 producty 3

9 new benefits 3

8 reorganisation 3

m) For each project on which more than two employees work, retrieve
the project number, project name, and the number of employees
who work on that project.

select PNumber, PName, count (*) from Project, Works_On where


PNumber=PNo group by PNumber, PName having count(*)>2;

PNUMBER PNAME COUNT (*)

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

6 computerisation 3

2 producty 3

9 new benefits 3

8 reorganisation 3

ID No.:09100469
KL University
Page No.:

Lab Experiment 4 Date:

Design and Create Relational Schema for Library Management


System

Aim:

The aim of this program is to understand the database objects


primarily tables and then identifying database constraints to construct
the database of records.

Code:

a) Create the tables with the appropriate integrity constraints

create table Student469(StudNo number(10) primary key, StudName


varchar(30)) ;

create table Membership580(MemNo number(15) primary key) ;

create table Book(BookNo number(15) primary key,


BookNamevarchar(20), Author varchar(15)) ;

create table Iss_rec469(Author number(15) primary key, IssDatedate) ;

alter table Membership469add StudNo references Student469(StudNo) ;

ID No.:09100469
KL University
Page No.:

alter table Iss_rec469 add MemNo references


Membership580(MemNo) ;

alter table Iss_rec469 add BookNo references Book(BookNo) ;

b) Insert around 6 records in each of the tables

insert into Student469 values('1','Charan');

insert into Student469 values('2','Vijay');

insert into Student469 values('3','Bharghava');

insert into Student469 values('4','Srujan');

insert into Student469 values('5','Prem');

insert into Student469 values('6','Mukesh');

 select * from Student469;

STUDNO STUD_NAME

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

1 Charan

2 Vijay

3 Bharghava

4 Srujan

5 Prem

ID No.:09100469
KL University
Page No.:

6 Mukesh

insert into Membership469values('123456789','1');

insert into Membership469values('222334444','2');

insert into Membership469values('333445555','3');

insert into Membership469values('444556666','4');

insert into Membership469values('555667777','5');

insert into Membership469values('666778888','6');

 select * from Membership580;

MEMNO STUDNO

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

123456789 1

222334444 2

333445555 3

444556666 4

555667777 5

666778888 6

insert into Book values('123','dbms','cjdate');

insert into Book values('456','webtech','dietel');

insert into Book values('789','o.s','Silberschatz');

ID No.:09100469
KL University
Page No.:

insert into Book values('111','daa','sahani');

insert into Book values('222','m.p','Douglas');

insert into Book values('333','probablity','Richard');

 select * from Book;

BOOKNO BOOKNAME AUTHOR

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

123 dbms cjdate

456 webtech dietel

789 o.s Silberschatz

111 daa sahani

222 m.p Douglas

333 probablity Richard

insert into Iss_rec469 values('1111','09-jan-11','123456789','111');

insert into Iss_rec469 values('2222','09-feb-11','222334444','123');

insert into Iss_rec469 values('3333','09-mar-11','333445555','456');

insert into Iss_rec469 values('4444','09-may-11','444556666','111');

insert into Iss_rec469 values('5555','09-jun-11','555667777','222');

insert into Iss_rec469 values('666','09-aug-11','666778888','333');

ID No.:09100469
KL University
Page No.:

 select * from Iss_rec469;

ISSNO ISSDATE MEMNO BOOKNO

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

1111 09-JAN-11 123456789 111

2222 09-FEB-11 222334444 123

3333 09-MAR-11 333445555 456

4444 09-MAY-11 444556666 111

5555 09-JUN-11 555667777 222

666 09-AUG-11 666778888 333

Queries

c) List all the Student469 names with their Membership469numbers

select StudName, MemNo from Student469, Membership469 where


Student469.StudNo=Membership580.StudNo ;

STUDNAME MEMNO

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

Charan 123456789

Vijay 222334444

Bharghava 333445555

ID No.:09100469
KL University
Page No.:

Srujan 444556666

Prem 555667777

Mukesh 666778888

d) List the details of Student469s who borrowed book whose Author


is

CJDATE

select StudName, StudNo from Student469 where StudNo in(select


StudNo from Membership469where MemNo in (select MemNo from
Iss_rec469 where BookNo in (select BookNo from Book where
Author='cjdate'))) ;

STUD_NAME STUDNO

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

Vijay 2

e) Give a count of how many books have been bought by each


Student469

select count(IssNo) from Iss_rec469 group by MemNo ;

COUNT(ISSNO)

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

ID No.:09100469
KL University
Page No.:

f) Give a list of books taken by Student469 with stud_no as 5

select * from Book where BookNo in(select BookNo from Iss_rec469

where MemNo in(select MemNo from Membership469where


StudNo='5')) ;

BOOKNO BOOKNAME AUTHOR

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

222 m.p Douglas

g) List the book details which are issued as of today.

Select distinct(BookName), BookNo from Iss_rec469, Book where


Iss_rec469.BookNo=Book.BookNo ;

BOOKNAME BOOKNO

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

dbms 123

webtech 456

daa 111

mp 222

probability 333

ID No.:09100469
KL University
Page No.:

Lab Experiment 5 Date:

Design and Create Relational schema for Video Library


Management system
Aim:

The aim of this program is to understand the database objects


primarily tables and then identifying database constraints to construct
the database of records and to apply basic DML commands to display
the data.

Code:

a) Create the tables with the appropriate integrity constraints

create table Customer469 (cust_no number(10) primary key,cust_name


varchar(30) ) ;

create table Membership469(mem_no number(10) primary key) ;

create table Cassette469(cass_no number(10) primary key,cass_name


varchar(30),language varchar(10)) ;

ID No.:09100469
KL University
Page No.:

create table Iss_rec469(iss_no number(10) primary key,IssDatedate) ;

alter table Membership469add cust_no number(10) references


Customer469(cust_no) ;

alter table Iss_rec469 add mem_no number(10) references


Membership580(mem_no) ;

alter table Iss_rec469 add cass_no number(10) references


Cassette469(cass_no) ;

b) Insert around 6 records in each of the tables

insert into Customer469 values ('446','Vijay') ;

insert into Customer469 values ('481','Charan') ;

insert into Customer469 values ('458','Prem') ;

insert into Customer469 values ('427','Mukesh') ;

insert into Customer469 values ('436','Srujan') ;

insert into Customer469 values ('469','Bharghava') ;

 select * from Customer469;

CUST_NO CUST_NAME

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

446 Vijay

481 Charan

ID No.:09100469
KL University
Page No.:

458 Prem

427 Mukesh

436 Srujan

469 Bharghava

insert into Membership469values ('123456789','446') ;

insert into Membership469values ('333445555','458') ;

insert into Membership469values ('999887777','427') ;

insert into Membership469values ('987654321','481') ;

insert into Membership469values ('666884444','469') ;

insert into Membership469values ('888665555','436') ;

 select * from Membership580;

MEM_NO CUST_NO

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

123456789 446

333445555 458

999887777 427

987654321 481

666884444 469

888665555 436

insert into Cassette469 values ('4901','the legend','english') ;

ID No.:09100469
KL University
Page No.:

insert into Cassette469 values ('4904','lonely road','english') ;

insert into Cassette469 values ('4916','all rise','english') ;

insert into Cassette469 values ('4936','meri kahani','hindi') ;

insert into Cassette469 values ('4949','tera chehra','hindi') ;

insert into Cassette469 values ('4964','strings','hindi') ;

 select * from Cassette469;

CASS_NO CASS_NAME LANGUAGE

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

4901 the legend english

4904 lonely road english

4916 all rise english

4936 meri kahani hindi

4949 tera chehra hindi

4964 strings hindi

insert into Iss_rec469 values ('2501','09-feb-2011','123456789','4949') ;

insert into Iss_rec469 values ('2504','19-feb-2011','123456789','4916') ;

insert into Iss_rec469 values ('2509','14-mar-2011','333445555','4916') ;

insert into Iss_rec469 values ('2516','12-jan-2011','333445555','4949') ;

insert into Iss_rec469 values ('2549','22-dec-2010','888665555','4901') ;

insert into Iss_rec469 values ('2536','10-dec-2010','999887777','4936') ;

ID No.:09100469
KL University
Page No.:

insert into Iss_rec469 values ('2564','30-nov-2010','987654321','4964') ;

 select * from Iss_rec469;

ISS_NO ISSDATE MEM_NO CASS_NO

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

2501 09-FEB-11 123456789 4949

2504 19-FEB-11 123456789 4916

2509 14-MAR-11 333445555 4916

2516 12-JAN-11 333445555 4949

2549 22-DEC-10 888665555 4901

2536 10-DEC-10 999887777 4936

2564 30-NOV-10 987654321 4964

Queries

c) List all the Customer469 names with their


Membership469numbers

select cust_name, mem_no from Customer469, Membership469where


Customer469.cust_no=Membership580.cust_no ;

CUST_NAME MEM_NO

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

ID No.:09100469
KL University
Page No.:

Vijay 123456789

Prem 333445555

Mukesh 999887777

Charan 987654321

Srujan 888665555

Bharghava 666884444

d) List the details of the Customer469 who has borrowed the


Cassette469 whose title is “ The Legend”

select cust_no,cust_name from Customer469 where cust_no in (select


cust_no from Membership469where mem_no in ( select mem_no from
Iss_rec469 where cass_no in (select cass_no from Cassette469 where
cass_name='the legend'))) ;

CUST_NO CUST_NAME

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

436 Srujan

e) Give a count of how many Cassette469s have been borrowed by


each

Customer469.

select count(iss_no), mem_no from Iss_rec469 group by mem_no ;

ID No.:09100469
KL University
Page No.:

COUNT(ISS_NO) MEM_NO

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

2 123456789

1 987654321

2 333445555

1 888665555

1 999887777

f) Give a list of book which has been taken by the Student469 with
mem_no as 5

select * from Cassette469 where cass_no in (select cass_no from


Iss_rec469 where mem_no in (select mem_no from Membership469
where cust_no='0384')) ;

no rows selected.

g) List the Cassette469s issued for today

Select cass_no, issdate from Iss_rec469 where issdate= ‘14-mar-2011’

CASS_NO ISSDATE

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

4916 14-MAR-11

ID No.:09100469
KL University
Page No.:

Lab Experiment 6 Date:

Design and Create Relational schema for Student469 Lab


Allocation system
Aim:

The aim of this program is to understand the database objects


primarily tables and then identifying database constraints to construct
the database of records and to apply basic DML commands to display
the data.

Code:

a) Create the tables with the appropriate integrity constraints

create table Student469(stud_no number(10) primary key, stud_name


varchar(20));

create table Class469(class varchar(20) primary key, descrip


varchar(20));

ID No.:09100469
KL University
Page No.:

create table Lab469(machno number(10) primary key, labno


number(10), description varchar(20));

create table Allotment469(dayofweek varchar(20));

alter table Student469 add classes varchar(20) references Class(class);

alter table Allotment add StudNo number(10) references


Student469(stud_no);

alter table Allotment add mach_no number(10) references Lab(machno);

b) Insert around 6 records in each of the tables

insert into Student469 values('1','Charan','');

insert into Student469 values('2','ramesh','');

insert into Student469 values('3','elizabeth','');

insert into Student469 values('4','ahmad','');

insert into Student469 values('5','james','');

--->

insert into Class469 values('csit','computer information');

insert into Class469 values('ce','civil');

insert into Class469 values('cse','computers');

insert into Class469 values('eee','electrical');

ID No.:09100469
KL University
Page No.:

insert into Class469 values('ece','electronics');

--->

insert into Lab469 values('101','1111','databaselab');

insert into Lab469 values('102','2222','webtechnology');

insert into Lab469 values('103','3333','microprocessor');

.insert into Lab469 values('104','4444','clab');

insert into Lab469 values('105','5555','java');

insert into Allotment469 values('monday','1','102');

insert into Allotment469 values('thrusday','4','105');

insert into Allotment469 values('tuesday','3','101');

insert into Allotment469 values('wednesday','2','103');

insert into Allotment469 values('friday','5','104');

--->

update Student469 set classes='csit' where stud_no=4;

update Student469 set classes='ce' where stud_no=1;

update Student469 set classes='cse' where stud_no=3;

update Student469 set classes='eee' where stud_no=5;

update Student469 set classes='ece' where stud_no=2;

 select * from Student469;

STUD_NO STUD_NAME CLASSES

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

ID No.:09100469
KL University
Page No.:

1 Charan ce

2 ramesh ece

3 elizabeth cse

4 ahmad csit

5 james eee

 select * from Allotment;

DAYOFWEEK STUDNO MACH_NO

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

monday 1 102

thrusday 4 105

tuesday 3 101

wednesday 2 103

friday 5 104

 select * from Lab;

MACHNO LABNO DESCRIPTION

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

101 1111 databaselab


ID No.:09100469
KL University
Page No.:

102 2222 webtechnology

103 3333 microprocessor

104 4444 clab

105 5555 java

 select * from Class;

CLASS DESCRIP

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

csit computer information

ce civil

cse computers

eee electrical

ece electronics

Queries

c) List all the machine allotments with the Student469 names, lab and

Machine numbers

Select stud_name, labno, description, mach_no from Allotment469,


Lab469, Student469 where Student469.stud_no=Allotment.StudNo and
Lab.machno=Allotment.mach_no;

ID No.:09100469
KL University
Page No.:

STUD_NAME LABNO DESCRIPTION MACH_NO

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

Charan 2222 webtechnology 102

ramesh 3333 microprocessor 103

elizabeth 1111 databaselab 101

ahmad 5555 java 105

james 4444 clab 104

d) List the total number of lab allotments day wise

select count(mach_no), dayofweek from Allotment469 group by


dayofweek;

COUNT(MACH_NO) DAYOFWEEK

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

1 friday

1 monday

1 wednesday

1 thursday

1 tuesday

e) Give a count of how many machines have been allocated to the


‘CSIT’ class

ID No.:09100469
KL University
Page No.:

select count(mach_no) from Allotment469, Student469 where


classes='csit' and StudNo=stud_no;

COUNT(MACH_NO)

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

f) Give a machine allotment details of the stud_no 5 with his personal

and class details.

select classes, labno, mach_no, stud_name from Student469,


Lab469,Allotment469 where stud_no=5 and stud_no=StudNo and
machno=mach_no;

CLASSES LABNO MACH_NO STUD_NAME

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

eee 4444 104 james

g) Count for how many machines have been allocated in Lab_no 1


for the day of the week as “Monday”

select count(machno) from Lab469, Allotment469 where


machno=mach_no and dayofweek= ‘monday' and labno= ‘1’;

COUNT(MACHNO)

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

ID No.:09100469

S-ar putea să vă placă și