You are on page 1of 25

Page 1

Assignment No: 01
Assignment Name: Employee Database
Create the database of the following table
employee(empno,empname,job,deptno,salary,dob)

1. List all employee who draws salary not less than 3000/- but more less than 6000/-
2. List employee no. and employee name in employee name order
3. Display all different job types
4. List the details of employee in D2 & D1 in alphabetical order of name
5. Display all employee details whose name have ‘sa’ or ‘am’
6. Show all employee whose date of birth between 1-Jan-1975 & 20-Dec-1979
7. Show the average salary for job excluding manager
8. Add a new field telephone number.

SQL Queries:
SQL> create table emp01
2 (empno varchar2(4),empname varchar2(20),job varchar2(10),deptno varchar2(4),salary
number(6),dob date);

Table created.

SQL> insert into emp01


2 values('&empno','&empname','&job','&deptno','&salary','&dob');
Enter value for empno: E001
Enter value for empname: saikat jana
Enter value for job: manager
Enter value for deptno: D3
Enter value for salary: 9500
Page 2

Enter value for dob: 25-jan-76


old 2: values('&empno','&empname','&job','&deptno','&salary','&dob')
new 2: values('E001','saikat jana','manager','D3','9500','25-jan-76')

1 row created.
SQL> select * from emp01;

EMPN EMPNAME JOB DEPT SALARY DOB


---- -------------------- ---------- ---- ---------- ---------
E001 saikat jana manager D3 9500 25-JAN-76
E002 somnath jana supplier D2 4000 05-SEP-83
E003 sampa patra salesgirl D2 4500 14-FEB-84
E004 anikesh bera manager D2 9000 26-MAY-77
E005 raju mana salesman D3 5000 03-OCT-80
E006 ranjan shit salesman D1 5500 22-JAN-79
E007 kamini patra supplier D3 4500 27-AUG-85

7 rows selected.

Q1:
SQL> select empname from emp01
2 where salary between 3000 and 6000;

EMPNAME
--------------------
somnath jana
Page 3

sampa patra
raju mana
ranjan shit
kamini patra

Q2:
SQL> select empno,empname from emp01
2 order by empname;

EMPN EMPNAME
---- --------------------
E004 anikesh bera
E007 kamini patra
E005 raju mana
E006 ranjan shit
E001 saikat jana
E003 sampa patra
E002 somnath jana

7 rows selected.

Q3:
SQL> select job from emp01;

JOB
Page 4

----------
manager
supplier
salesgirl
manager
salesman
salesman
supplier

7 rows selected.

Q4:
SQL> select * from emp01
2 where deptno='D2' or deptno='D1'
3 order by empname;

EMPN EMPNAME JOB DEPT SALARY DOB


---- -------------------- ---------- ---- ---------- ---------
E004 anikesh bera manager D2 9000 26-MAY-77
E006 ranjan shit salesman D1 5500 22-JAN-79
E003 sampa patra salesgirl D2 4500 14-FEB-84
E002 somnath jana supplier D2 4000 05-SEP-83

Q5:
SQL> select * from emp01
2 where empname like '%sa%' or empname like '%am%';
Page 5

EMPN EMPNAME JOB DEPT SALARY DOB


---- -------------------- ---------- ---- ---------- ---------
E001 saikat jana manager D3 9500 25-JAN-76
E003 sampa patra salesgirl D2 4500 14-FEB-84
E007 kamini patra supplier D3 4500 27-AUG-85

Q6:
SQL> select * from emp01
2 where dob between '1-jan-1975' and '20-dec-1980';

EMPN EMPNAME JOB DEPT SALARY DOB


---- -------------------- ---------- ---- ---------- ---------
E001 saikat jana manager D3 9500 25-JAN-76
E004 anikesh bera manager D2 9000 26-MAY-77
E005 raju mana salesman D3 5000 03-OCT-80
E006 ranjan shit salesman D1 5500 22-JAN-79
Q7:
SQL> select avg(salary) from emp01
2 where not job='manager';

AVG(SALARY)
-----------
4700
Q8:
SQL> alter table emp01 add(telno number(11));
Page 6

Table altered.

SQL> update emp01 telno set telno=7031111016 where empname='saikat jana';


1 row updated.
SQL> update emp01 telno set telno=9609972877 where empname='anikesh bera';
1 row updated.

SQL> select * from emp01;

EMPN EMPNAME JOB DEPT SALARY DOB TELNO


---- -------------------- ---------- ---- ---------- --------- ----------
E001 saikat jana manager D3 9500 25-JAN-76 7031111016
E002 somnath jana supplier D2 4000 05-SEP-83
E003 sampa patra salesgirl D2 4500 14-FEB-84
E004 anikesh bera manager D2 9000 26-MAY-77 9609972877
E005 raju mana salesman D3 5000 03-OCT-80
E006 ranjan shit salesman D1 5500 22-JAN-79
E007 kamini patra supplier D3 4500 27-AUG-85

7 rows selected.
Page 7

Assignment No: 02
Assignment Name: Company Database
Create the database of the following table
Client-master(client_no.,client_name,city,due balance)
Product-master(product no,product description,profit,sellprice)
Salesman-master(salesman no,sales name,city,sales amount)

1. List names of all clients having ‘a’ as the 2nd letter of the name
2. List the clients who stay in a city whose 1st letter is ‘M’
3. List all clients who stay in ‘Bangalore’ or ‘bangalore’
4. List all clients whose balance due is greater than 10,000/-
5. Change the city of client no. ‘C05’ to Bangalore
6. Count the no of product having price less than or equal to 40000/-
7. Determine the maximum or minimum product price
8. List the name and city of salesman who are not in the city Kolkata

SQK Queries:
SQL> create table cmaster
2 (cno varchar2(4),cname varchar2(15),ccity varchar2(10),duebal number(9));

Table created.

SQL> insert into cmaster values


2 ('&cno','&cname',&ccity',&duebal);

SQL> select * from cmaster;


Page 8

CNO CNAME CCITY DUEBAL


---- --------------- ---------- ---------- --------------
C01 Ashok Mehera Mumbai 5000
C02 Rohit Roy Kolkata 6000
C03 Rahul Desai Bangalore 9000
C04 Prem Iyer Delhi 10000
C05 Ajoy Mehta Mangalore 12000
C06 Nalini Sen Mumbai 11000
C07 Rina Rai Bangalore 13000

7 rows selected.

SQL> create table pmaster


2 (pno varchar2(4),pdes varchar2(10),profit number(5),price number(9));

Table created.

SQL> insert into pmaster


2 values
3 ('&pno','&pdes',&profit,&price);

SQL> select * from pmaster;


Page 9

PNO PDES PROFIT PRICE


---- ---------- ---------- ---------- ----------
P01 Floppies 10 4000
P02 Monitors 12 50000
P03 Mouse 9 25000
P04 Keyboard 15 35000
P05 Cddrive 7 8000
P06 Hdd 10 55000
P07 Laptop 20 300000

7 rows selected.

SQL> create table smaster


2 (sno varchar2(4),sname varchar2(15),scity varchar2(10),samount number(9));

Table created.

SQL> insert into smaster values


2 ('&sno','&sname','&scity',&samount);

SQL> select * from smaster;

SNO SNAME SCITY SAMOUNT


---- --------------- ---------- ---------- ---------------
Page 10

S01 Mahesh Patel Mumbai 10000


S02 Kiran Dixit Delhi 15000
S03 Nitesh Khanna Mumbai 200000
S04 Mahesh Patil Kolkata 100000

4 rows selected.

Q1:
SQL> select * from cmaster where cname like '_a%';

CNO CNAME CCITY DUEBAL


---- --------------- ---------- ---------- --------------
C03 Rahul Desai Bangalore 9000
C06 Nalini Sen Mumbai 11000

Q2:
SQL> select * from cmaster
2 where ccity like 'm%';

CNO CNAME CCITY DUEBAL


---- --------------- ---------- ---------- --------------
C01 Ashok Mehera Mumbai 5000
C05 Ajoy Mehta Mangalore 12000
C06 Nalini Sen Mumbai 11000
Page 11

Q3:
SQL> select * from cmaster
2 where ccity='Bangalore' or ccity='Mangalore';

CNO CNAME CCITY DUEBAL


---- --------------- ---------- ---------- --------------
C03 Rahul Desai Bangalore 9000
C05 Ajoy Mehta Mangalore 12000
C07 Rina Rai Bangalore 13000

Q4:
SQL> select * from cmaster
2 where duebal>10000;

CNO CNAME CCITY DUEBAL


---- --------------- ---------- ---------- --------------
C05 Ajoy Mehta Mangalore 12000
C06 Nalini Sen Mumbai 11000
C07 Rina Rai Bangalore 13000

Q5:
SQL> update cmaster set ccity='bangalore'
2 where cno='C05';

1 row updated.
Page 12

SQL> select * from cmaster;

CNO CNAME CCITY DUEBAL


---- --------------- ---------- ---------- --------------
C01 Ashok Mehera Mumbai 5000
C02 Rohit Roy Kolkata 6000
C03 Rahul Desai Bangalore 9000
C04 Prem Iyer Delhi 10000
C05 Ajoy Mehta Bangalore 12000
C06 Nalini Sen Mumbai 11000
C07 Rina Rai Bangalore 13000

7 rows selected.

Q6:
SQL> select pdes from pmaster
2 where price<=40000;

PDES
----------
floppies
mouse
keyboard
cddrive

Q7:
Page 13

SQL> select max(price) from pmaster;

MAX(PRICE)
-----------------
300000

SQL> select min(price) from pmaster;

MIN(PRICE)
---------------
4000

Q8:
SQL> select sname,scity from smaster
2 where scity<>'kolkata';

SNAME SCITY
--------------- ----------
Mahesh Patel Mumbai
Kiran Dixit Delhi
Nitesh Khan Mumbai
Page 14

Assignment No: 03
Create the database of the following table
patient(p_id, p_name, age, p_address)
doctor(d_id, d_name, d_address)
attend(d_id, p_id)
admitted(p_id, d_o_a)

SQL Queries:
SQL> Create table patient (p_id varchar2(5),p_name varchar2(10),age number(5),p_address
varchar2(10));

Table created.

SQL> Insert into patient


2 values('&p_id','&p_name',’&age’,'&p_address');

SQL> select * from patient;

P_ID P_NAME AGE P_ADDRESS


------- -------------- --------- -------------------
p_001 suman 19 mid
p_002 deborshi 20 jgr
p_003 lipica 21 gar
p_004 suman 20 gar
p_005 priyanka 21 mid
Page 15

5 rows selected.

SQL> Create table doctor (d_id varchar2(5),d_name varchar2(10),d_address varchar2(10));

Table created.

SQL> Insert into doctor


2 values('d_001','biplab','jgr');

SQL> select * from doctor;

D_ID D_NAME D_ADDRESS


---------- -------------- ------------------
d_001 biplab jgr
d_002 papul mid
d_003 basanta mid

3 rows selected.

SQL> Create table attend(d_id varchar2(5),p_id varchar2(5));

Table created.

SQL> Insert into attend


2 values('d_001','p_002');
Page 16

SQL> Select * from attend;

D_ID P_ID
---------- ----------
d_001 p_002
d_001 p_004
d_002 p_001
d_003 p_003
d_003 p_005

5 rows selected.

Q1: List all the patient whose address same with the address of d_id=’d002’

SQL> select p_id,p_name from patient


2 where p_address =(select d_address from doctor where d_id='d_002');

P_ID P_NAME
------- --------------
p_001 suman
p_005 priyanka

Q2: List the doctor id and name who check the patient d_o_a between ‘01-may-05’ to ‘01-
jan-07’
Page 17

SQL> Select doctor.d_id,d_name from doctor,attend,admitted


2 where doctor.d_id=attend.d_id and attend.p_id=admitted.p_id and d_o_a between'01-
may-05' and '01-jan-07';

D_ID D_NAME D_ADDRESS


---------- -------------- ------------------
d_001 biplab jgr
d_002 papul mid

Q3: List the name of the patient assecnding order of age with doctor name

SQL> Select patient.p_id,p_name,doctor.d_id,d_name from patient,doctor,attend


2 where patient.p_id=attend.p_id and doctor.d_id=attend.d_id order by age;

P_ID P_NAME D_ID D_NAME


----- ------------ ---------- -------------
p_001 suman d_002 papul
p_004 suman d_001 biplab
p_002 deborshi d_001 biplab
p_003 lipica d_003 basanta

Q4: Find the doctor id and name for specific p_id=’p_005’

SQL> select doctor.d_id,d_name from patient,doctor,attend


Page 18

2 where patient.p_id=attend.p_id and doctor.d_id=attend.d_id and patient.p_id='p_005';

D_ID D_NAME D_ADDRESS


---------- -------------- ------------------
d_003 basanta mid

Q5: Find the patients name for a specific d_o_a=’01-dec-06’

SQL> Select patient.p_id , p_name from patient,admitted


2 where patient.p_id=admitted.p_id and d_o_a='01-dec-06';

P_ID P_NAME
----- -------------
p_005 priyanka
Page 19

Assignment No: 04
Assignment Name: University Database
Create the following table of the Database
enroll(s#, c#, section)
teach (prof, c#, section)
advice(prof, s#)
pre_req(c#, pre_c#)
grade(s#, c#, grade,year)
student(s#, sname)

enroll table :

SQL> Create table enroll(s# varchar2(5),c# varchar2(5),section varchar(5));

Table created.

SQL> Insert into enroll


2 values (‘&s#’,’&c#’,’&section’);

SQL> select *from enroll;

S# C# SECTION
------ ------ --------------
s001 c001 a
s001 c002 b
Page 20

s002 c001 a
s002 c002 b
s003 c001 b
s004 c002 a

6 rows selected.

teach table :

SQL> Create table teach(prof varcahr2(5),c# varchar(5),section varchar2(5));

Table created.

SQL> Insert into teach


2 values(’&prof’,’&c#’,’&section’);

SQL> select * from teach;

PROF C# SECTION
----------- ------- ----------------
korth c001 a
aho c002 b
bekar c001 b
lamp c002 b

4 rows selected.
Page 21

advice table :

SQL> Create table advice(prof varchar2(5),s# varcahar2(5));

Table created.

SQL> Insert into advice


2 values(‘&prof’,’&s#’);

SQL> select * from advice;

PROF S#
---------- ------
korth s001
aho s002

2 rows selected.

pre_req table :

SQL> Create table pre_req(c# varchar2(5),pre_c# varchar2(5));

Table created.

SQL> Insert into pre_req


Page 22

2 values (‘c001’,’c004’);

SQL> select * from pre_req;

C# PRE_C#
------- -------------
c001 c004
c001 c005
c002 c006
c002 c007

4 rows selected.

grade table :

SQL> create table grade(s# varcahr2(5),c# varchar2(5),grade varchar2(5),year varchar2(5));

Table created.

SQL> Insert into grade


2 values (‘&s#’,’&c#’,’&grade,’&year’);

SQL> select * from grade;

S# C# GRADE YEAR
Page 23

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


s001 c004 a+ 2006
s001 c005 a 2006
s001 c006 b 2006
s001 c007 c 2006
s002 c004 c 2006
s002 c005 a 2006
s002 c006 a 2006
s003 c005 b 2006
s004 c007 a 2006

9 rows selected.

student table :

SQL> Create table student(s# varchar2(5),sname varchar2(5));

Table created.

SQL> Insert into student


2 values(‘&s#’,’&sname’);

SQL> select * from student;

S# SNAME
Page 24

-------- -------------
s001 suman
s002 sudipta
s003 biplab
s004 chandan

5 rows selected.

Q1: List all the student taking course with ‘suman’ and ‘chandan’

SQL> select s_name, student.s#, c# from student,enroll


2 where student.s#=enroll.s# and s_name!='suman' and s_name!='chandan' and c# in
(select c# from student,enroll where student.s#=enroll.s# and s_name='suman' or
s_name='chandan' );

S# C#
------------ ----------
s002 c001
s002 c002
s003 c001

Q2: List all student taking at least one course that their advisor teaches

SQL> select student.s#, s_name from student,enroll,teach,advice


2 where student.s# =enroll.s# and student.s# =advice.s# and enroll.s# =advice.s# and
enroll.c# =teach.c# and teach.prof=advice.prof;
S# C#
Page 25

---------- ---------
s001 suman
s002 sudipta

Q3: List all the course that ‘suman’ can enroll

SQL> select pre_req.c# from pre_req,grade,student


2 where pre_req.pre_c#=grade.c# and grade.s#=student.s# and pre_req.c#!=grade.c# and
s_name='suman';

C#
--------
c001
c002

Q4: List those professor who teach more than one section

SQL> select prof from teach group by prof


2 having count(section)>1;

PROF
-----------
aho
korth
……………………………………………..
Teacher’s Signature

You might also like