0% found this document useful (0 votes)
46 views

DBMS Lab activities

Uploaded by

Ravi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

DBMS Lab activities

Uploaded by

Ravi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

DBMS lab [1]

ACTIVITY 1:
Database: student (DDL,DML,statements)
Table: Student
Name Regno Class Major
smith 17 1 CS
Brown 8 2 CS

Table: Course
Coursename coursenumber Credithours Department
Intro to computer science CS1310 4 CS
Data structure CS3320 4 CS
Discrete mathematics MATH2410 3 MATH
Database CS3380 3 CS

Table: Section
SectionIndentifier CourseNumber Year Instructor
85 MATH2410 98 King
92 CS1310 98 Anderson
102 CS3320 99 Knuth
112 MATH2410 99 Chang
119 CS1310 99 Andres
135 CS3380 99 Stone

Table: Grade report


Regno Section_identifier Grade
17 112 B
17 119 C
8 85 A
8 92 A
8 102 B
8 135 A

1. Create tables using Create statement


2. Insert rows to individual tables using insert statements.
3. Alter table section add new field section and update record
4. Delete Brown’s grade report
5. Drop the table section
Queries :

1) Create Tables using create statement


SQL> create table stud1 (name varchar(10),regno number(2) primary key,class number(1),major
varchar(2));
Table created.
SQL> create table course1 (cname varchar(20), cno varchar(10), chours number(1), dept
varchar(4));
Table created.
DBMS lab [2]

SQL> create table sect1(secid number(3) primary key, cno varcahr(10) references course1.year
number(2), instructor varcahr(10));
Table created
SQL> create table grade1(regno number(2) references stud1, sectid number(3), grade varchar(1));
Table created.

2) Insert rows to individual tables using insert statement


SQL> insert into stud1 values('smith',17,1,'cs');
1 row created.
SQL> insert into stud1 values('brown',8,2,'cs');
1 row created.

SQL> insert into course1 values ('computer science','cs130',4,'cs');


1 row created.
SQL> insert into course values ('data structure','cs3320',4,'cs');
1 row created.
SQL> insert into sect1 values(85,'math2410',98,'king');
1 row created.
SQL> insert into sect1 values(92,'cs130',98,'andreson');
1 row created.

SQL> insert into grade1 values(17,112,'b');


1 row created.
SQL> insert into grade1 values(17,119,'c');
1 row created.

SQL> select * from stud1;


SQL> select *from course1;
SQL> select * from sect1;

SQL> select *from grade1t;

3) Alter table section add new field section and update record
SQL> alter table sect1 add(section varchar(1));
Table altered.
SQL> update sect1 set section='a' where secid=85;
1 row updated.
SQL> update sect1 set section='b' where secid=92;
1 row updated.
SQL> select *from sect1;
DBMS lab [3]

4) Delete Brown’s grade report


SQL> delete from grade1 where regno in (select regno from student where name=’brown’ );
4 rows deleted
SQL> select * from grade1;
5) Drop the table section
SQL> drop table section;
Table dropped.
------------------------------------------------------------------------------------------------------------------
Activity 2: (Select clause,Arithmetic Operators)
Database:employee
Create following tables and insert tuples with suitable constraints
Table :EMPLOYEE

EMPID FIRSTNAME LASTNAME HIRE_DATE ADDRESS CITY


1001 George Smith 11-May-06 83 first street Paris
1002 Mary Jones 25-Feb-08 842 Vine Ave Losantiville
1012 Sam Tones 12-Sep-05 33 Elm St. Paris
1015 Peter Thompson 19-Dec-06 11 Red Road Paris
1016 Sarath Sharma 22-Aug-07 440 MG Road New Delhi
1020 Monika Gupta 07-Jun-08 9 Bandra Mumbai

Table: EMPSALARY

EMPID SALARY BENEFITS DESIGNATION


1001 10000 3000 Manager
1002 8000 1200 Salesman
1012 20000 5000 Director
1015 6500 1300 Clerk
1016 6000 1000 Clerk
1020 8000 1200 Salesman

1. To display FIRSTNAME, LASTNAME, ADDRESS AND CITY of all employees living in


PARIS.
2. To display the content of employee table in descending order of FIRSTNAME
3. Select FIRSTNAME and SALARY of salesman
4. To display the FIRSTNAME,LASTNAME, AND TOTAL SALARY of all employees from the
table EMPLOYEE and EMPSALARY. Where TOTAL SALARY is calculated as
SALARY+BENEFITS
5. List the Names of employees, who are more than 1 year old in the organization
6. Count number of distinct DESINGATION from EMPSALARY
7. Add new column PHONE_NO to EMPLOYEE and update the records
8. List employee names, who have joined before 15-Jun-08 and after 16-Jun-07
9. Generate Salary slip with Name, Salary, Benefits, HRA-50%, DA-30%, PF-12%, Calculate
gross. Order the result in descending order of the gross.
DBMS lab [4]

Table creation:
SQL> create table empl1 (empid number(4) primary key, fame character(10),
lname character(10), hiredate date, addr varchar(15), city character(15));
Table created.
SQL> insert into empl1 values(1001,'George','Smith','11-May-06','83 first street','Paris');
1 row created.
SQL> insert into empl1 values(1002,'Mary','Jones','25-Feb-08','842 Vine Ave','Losantiville');
1 row created.
SQL> select * from empl1;
SQL> create table empsal1 (empid number(4) references empl1, sal number(8,2), benefits
number(8,2), desig char(15));
Table created.
SQL> insert into empsal1 values(1001,10000,3000,'Manger');
1 row created.
SQL> insert into empsal1 values(1002,8000,1200,'Salesman');
1 row created.
SQL> select * from empsal1;

1) To display FIRSTNAME, LASTNAME, ADDRESS AND CITY of all employees living in


PARIS.
SQL> select fname, lname, addr, city from empl1 where city='Paris';

2) To display the content of employee table in descending order of FIRSTNAME


SQL> select * from empl1 order by fname desc;

3) Select FIRSTNAME and SALARY of salesman


SQL> select empl1.fname, empsal1.sal from empl1, empsal1 where empsal1.desig='Salesman'
and empl1.empid=empsal1.empid;

4) To display the FIRSTNAME, LASTNAME AND TOTAL SALARY of all employees from
the table EMPLOYEE and EMPSALARY.Where TOTAL SALARY is calculated as
SALARY+BENEFITS

SQL> select empl1.fname, empl1.lname, empsal1.sal + empsal1.benefits "total salary" from


empl1, empsal1 where empl1.empid=empsal1.empid;

5) List the Names of employees, who are more than 1 year old in the organization
SQL> select fname, lname from empl1 where (sysdate-hiredate)>365;
DBMS lab [5]

6) Count number of distinct DESIGNATION from EMPSALARY


SQL> select count(distinct desig)from empsal1;

7) Add new column PHONE_NO to EMPLOYEE and update the records

SQL> alter table empl1 add phno number(10);


Table altered.
SQL> update empl1 set phno='9632581' where empid='1001';
1 row updated.
SQL> update empl1 set phno='9874562' where empid='1002';
1 row updated.
SQL> select * from empl1;

8 ) List employee names, who have joined before 15-jun-08 and after 16-jun-07

SQL> select fname,lname from empl1 where hiredate > '16-Jan-07' and hiredate <'13-Jan-08';

9 ) Generate Salary slip with Name ,Salary,Benefits,HRA-50%,DA-30%,PF-12%,Calculate


gross. Order the result in descending order of the gross.
SQL> select fname, sal , benefits, sal*50/100+sal*30/100*12/100 "gross" from empl1, empsal1
where empl1.empid=empsal1.empid order by sal desc;
--------------------------------------------------------------------------------------------------------------------
Activity:03 ( Logical,Relational Operators)
Database :Library

Create Following tales and insert tuples with suitable constraints

Table:Books

BOOK_ID BOOK_NAME AUTHOR_NAME PUBLISHERS Price Type Quantity


C0001 The Klone and I
Lata Kappor EPP 355 Novel 5
F0001 The Tears William Hopkins First Publ 650 Fiction 20
T0001 My First C++ Brain & Brooke ERP 350 Text 10
T0002 C++ Brainworks
A.W.Rossaine TDH 350 Text 15
F0002 THUNDERBOLTS Ana Roberts First Publ. 750 Fiction 50
Table:Issued

Book_ID Quantity_Issued
T0001 4
C0001 5
F0001 2
T0002 5
F0002 8
DBMS lab [6]

1. To show Book name, Author name and price of books of First Publ. publisher
2. Display Book id, Book name and publisher of books having quantity more than 8 and price less
than 500
3. Select Book id, book name, author name of books which is published by other than ERP
publishers and price between 300 to 700
4. Generate a Bill with Book_id, Book_name, Publisher, Price, Quantity, 4% of VAT “Total”
5. Display book details with book id’s C0001, F0001, T0002, F0002 (Hint: use IN operator)
6. Display Book list other than, type Novel and Fiction
7. Display book details with author name starts with letter ‘A’
8. Display book details with author name starts with letter ‘T’ and ends with ‘S’
9. Select BookId, BookName, Author Name , Quantity Issued where Books.BooksId =
Issued.BookId
10. List the book_name, Author_name, Price. In ascending order of Book_name and then on
descendingorder of price

SQL> create table books(Bid varchar(6) primary key, Bname char(20), author char(20), publisher
varchar(10), price number(5), type char(10),qty number(5));
Table created.
SQL> insert into books values('c0001','the klone and i','lata kappor','epp',355,'novel',5);
1 row created.
SQL> insert into books values('f0001','the tears','william hopkins','first pub1',650,'fiction',20);
1 row created.
SQL> select *from books;

SQL> create table issued (Bid varchar(6) references books, qtyissued number(3));
Table created.
SQL> insert into issued values('t0001',4);
1 row created.
SQL> insert into issued values('c0001',5);

1) To show bookname, authorname and price of books of firstpub1. Publisher?


SQL> select Bname, author, price from books where publishers='first pub1';

2 ) Display bookid, bookname and publisher of books having quantity more than 8 and price
less than 500?
SQL> select Bid, Bname, publishers from books where qty > 8 and price<500;

3 ) select bookid, bookname, authorname of books which is published by other than erp
publishers and price between 300 to 700?
SQL> select Bid, Bname, author from books where publishers != 'erp' and price>=300 and
price<=700;
DBMS lab [7]

4 ) Generate a bill with a bookid,bookname,publisher,price,quantity,4% of VAT “total”?


SQL> select Bid, Bname, publishers, price, qty, price+0.04*price "total" from books;

5 ) Display book details with bookid’s c0001,f0001,t0002,f0002 (hint:use IN operator)?


SQL> select *from books where Bid in('c0001','f0001','t0002','f0002');

6) Display booklist other than, type novel and fiction?


SQL> select * from books where type !='novel' and type != 'fiction';

7) Display book details with authorname starts with a lette ‘A’?


SQL> select *from books where author like 'a%';

8) Display book details with authorname starts with letter ‘T’ and ends with ‘S’?
SQL> select *from books where author like 't%s';
no rows selected

9) select bookid, bookname, authorname, quatityissued where books.bookid=issed.bookid?


SQL> select books.Bid, books.Bname, books.author, issued.qtyissued from books, issued where
books.Bid=issued.Bid;

10) list the bookname, autorname, price.in ascending order of booksname and then on
descending order of price?
SQL> select Bname, author, price from books order by Bname asc;

SQL> select Bname, author, price from books order by Bname desc;
---------------------------------------------------------------------------------------------------------------------
Activity 04:(Data Functions)
Database: Lab
Create Following table and insert tuples with suitable constraints

Table:Equipments_Details

NO ITEMNAME COSTPRICE QUANTITY DATEOFPURCHASE WARRANTY OPERATIONAL


1 Computer 30000 9 21/5/07 2 7
2 Printer 5000 3 21/5/06 4 2
3 Scanner 8000 1 29/8/08 3 1
4 Camera 7000 2 13/6/05 1 2
5 UPS 15000 5 21/5/08 1 4
6 Hubs 8000 1 31/10/08 2 1
7 Plotter 25000 2 11/01/09 2 2

Queries :
1. To select the ItemName purchase after 31/10/07
2. Extend the warranty of each item by 6 months
DBMS lab [8]

4. To list the ItemName in ascending order of the date of purchase where quantity is more than 3.
5. To count the number, average of costperitem of items purchased before 1/1/08
6. To display the minimum warranty, maximum warranty period
7. To display the next Sunday from the date ’07-JUN-96’

Table creation:
SQL> create table eqpdet(no number(5), item char(15), itemcost number(15),
qty number(5), dop varchar(15), warranty number(5), operational number(5));
Table created.
SQL> insert into eqpdet values(1, 'computer', 30000, 9, '21-may-07', 2, 7);
1 row created.
SQL> insert into eqpdet values(2, 'printer', 5000, 3, '21-may-06', 4, 2);
1 row created.
SQL> select * from eqpdet;

1) To select the ItemName purchase after 31/10/07


SQL> select item from eqpdet where dop > '31-oct-07';

2) Extend the warranty of each item by 6 months


SQL> update eqpdet set warranty = warranty+0.6;
7 rows updated.
SQL> select * from eqpdet;

3) Display Itemname , Dateof purchase and number of months between purchase date and
present date
SQL> select item, dop, ((sysdate-dop)/30) as months from eqpdet;
4) To list the ItemName in ascending order of the date of purchase where quantity is more
than 3.
SQL> select item, dop from eqpdet where qty > 3 order by dop asc;

5) To count the number, average of costperitem of items purchased before 1/1/08


SQL> select count(*), avg(itemcost) from eqpdet where dop < '1-jan-08';

6) To display the minimum warranty , maximum warrenty period


SQL> select min(warranty), max(warranty) from eqpdet;

7) To display the next day from the date ’07-JAN-06’


SQL> select next_day('07-jan-06','sunday')from dual;
DBMS lab [9]

Activity : 05 (numeric , character functions)


Using function for the following

1. Find the mod of 165,16


2. Find Square Root of 5000
3. Truncate the value 128.3285 to 2 and -1 decimal places
4. Round the value 92.7683 to 2 and -1 decimal places
5. Convert the string ‘Department’ to uppercase and lowercase
6. Display your address convert the first character of each word to uppercase and rest are in
lowercase
7. Combine your first name and last name under the title Full name
8. Find the length of the string ‘sdm mmk college’
9. Display substring ‘BASE’ from ‘DATABASE’
10. Display the position of the first occurrence of character ‘o’ in Position and Length
11. Display the ASCII value of ‘ ‘ (Space).
1 ) Find the mod of 165,16
SQL> select mod(165,16) from dual;
MOD(165,16)
---------------------
5
2) Find square root of 5000
SQL> select sqrt(5000) from dual;
SQRT(5000)
--------------------
70.710678
3) Truncate the value 128.3285 to 2 and -1 decimal places
SQL> select trunc(128.3285,2),trunc(128.3285,-1) from dual;
TRUNC(128.3285,2) TRUNC(128.3285,-1)
-------------------------- -------------------------------
128.32 120
4) Round the value 92.7683 to 2and -1 decimal places
SQL> select round(92.7683,2),round(92.7683,-1) from dual;
ROUND(92.7683,2) ROUND(92.7683,-1)
------------------------- -----------------------------
92.77 90
5) Convert the string ‘Department’ to uppercase and lowercase
SQL> select upper('department')”uppercase”, lower('DEPARTMENT')”lowercase” from dual;
Uppercase Lowercase
------------------- ------------------------
DEPARTMENT department
6) Display your address convert the first character of each word to uppercase and rest are in
lowercase
SQL> select initcap('SDM MMK COLLEGE')"college name" from dual;
college name
-------------------------
Sdm Mmk College
DBMS lab [10]

7) Combine your first name and last name under the title full name
SQL> select 'meher'||' '||'pandya' "fullname" from dual;
fullname
----------------
meher pandya
8) Find the length of the string ‘SDM MMK College’
SQL> select length('sdm mmk college') from dual;
LENGTH('SDMMMKCOLLEGE')
-------------------------------------------
15
9) Display substring ‘BASE’ from ‘DATABASE’
SQL> select substr('database','5','4') from dual;
SUBS
--------
base
10) Display the position of the first occurrence of character ‘o’ in position and length
SQL> select instr('position','o') from dual;
INSTR('POSITION','O')
---------------------
2
11) Display the ASCII value of ‘’(Space)
SQL> select ascii('asciilength') from dual;
ASCII('ASCIILENGTH')
--------------------
97

--------------------------------------------------------------------------------------------------------------------
Activity:6 (set operators)
Database :Subject

Create Following tables and insert tuples with suitable constraints

Table:Physics

REGNO NAME YEAR COMBINATION


AJ00325 Ashwin First PCM
AJ00225 Swaroop Second PMCs
AJ00385 Sarika Third PME
AJ00388 Hamsa First PMCs

Table:Computer_Science

REGNO NAME YEAR COMBINATION


AJ00225 Swaroop Second PMCs
AJ00296 Tajas Second BCA
AJ00112 Geetha First BCA
AJ00388 Hamsa First PMCs
DBMS lab [11]

Queries :
1. Select all students from physics and Computer Science
2. Select student common in physics and Computer Science
3. Display all student details those are studying in second year 50
4. Display student those who are studying both physics and computer science in second year
5. Display the students studying only physics
6. Display the students studying only Computer Science
7. select all student having PMCs combination
8. select all student having BCA combination
9. select all student studying in Third year
10. Rename table Computer Science to CS

SQL> create table phy(regno varchar(20), name varchar(20), year varchar(20),comb


varchar(20));
Table created.
SQL> insert into phy values('AJ00325','ashwin','first','PCM');
1 row created.
SQL> insert into phy values('AJ00225','swaroop','second','PMCs');
1 row created.
SQL> select *from phy;
SQL> create table cmps(regno varchar(20), name varchar(20), year varchar(20),combination
varchar(20));
Table created.
SQL> insert into cmps values('AJ00225','swaroop','second','PMCs');
1 row created.
SQL> insert into cmps values('AJ00296','tajas','second','BCA');
1 row created.
SQL> select *from cmps;
1) select all students from physics and computer science.
SQL> select *from phy union select *from cmps;
2) Select student common in physics and computer science.
SQL> select *from phy intersect select *from cmps;
3) Display all student details those are studying in second year.
SQL> select *from phy where year='second' union select *from cmps where year='second';
4) Display those students who are studying both physics and computer science in second
year.
SQL> select *from phy where year='second' intersect select *from cmps where year='second';
5 ) Display the students studying only physics. (IN phy NOT IN cmps)
SQL> select * from phy ;
6) Display the students studying only computer science.
SQL> select * from cmps;
DBMS lab [12]

7) Select all students having PMCs combination.


SQL> select *from phy where combination ='PMCs' union select *from cmps where combination
='PMCs';
8) Select all students having BCA combination.
SQL> select *from cmps where combination='BCA';
9) Select all students studying in third year.
SQL> select *from phy where year='third' union select *from cmps where year='third';
10) Rename table computer science to cs.
SQL> rename cmps to computerscience;
Table renamed.
---------------------------------------------------------------------------------------------------------------------
Activity:07
Database:Railways Reservation System
Create Following Table and insert tuples with suitable constraints
Table:Train Details
TRAIN_NO TRAIN_NAME START_PLACE DESTINATION
RJD16 Rajdhani Express Bangalore Mumbai
UDE04 Udhyan Express Chennai Hyderabad
KKE55 Karnataka Express Bangalore Chennai
CSE3 Shivaji Express Coimbatore Bangalore
JNS8 Janashatabdi Bangalore Salem
Table:Availability
TRAIN_NO CLASS START_PLACE DESTINATION NO_OF_SEATS
RJD16 Sleeper Class Bangalore Mumbai 15
UDE04 First Class Chennai Hyderabad 22
KKE55 First Class A/C Bangalore Chennai 15
CSE3 Second Class Coimbatore Bangalore 8
JNS8 Sleeper Class Bangalore Salem 18

1.Create view sleeper to display train no, start place, destination which have sleeper class and
perform the following
a. insert new record
b. update destination=’Manglore’ where train no=’RJD16’
c. delete a record which have train no=’KKE55’
2. Create view details to display train no, train name, class
3. Rename view sleeper to class
4. Delete view details

SQL> create table trdet(trno varchar(10) primary key,trname char(20),start char(15),dest


char(15));
Table created.
SQL> insert into trdet values('rjd16', 'rajdhani express', 'bangalore', 'mumbai');
1 row created.
DBMS lab [13]

SQL> insert into trdet values('ude04', 'udhyan express', 'chennai', 'hyderabad');


1 row created.
SQL> select * from trdet;
SQL> create table avail (trno varchar(10) references trdet, class char(20),start char(15), dest
char(15), noofseats number(5));
Table created.
SQL> insert into avail values('rjd16', 'sleeperclass', 'bangalore', 'mumbai', 15);
1 row created.
SQL> insert into avail values('ude04', 'firstclass', 'chennai', 'hyderabad', 22);
1 row created.
SQL> select * from av1;
1) Create view sleeper to display train no, start place, destination which have sleeper class
SQL> create view slpr as select trno, start, dest from avail where class='sleeperclass';
View created.
SQL> select * from slpr;
a) insert new record
SQL> insert into slpr values('kke55', 'bangalore', 'chennai');
1 row created.
SQL> select * from slpr;
b) update destination=’Manglore’ where train no=’RJD16’
SQL> update slpr set dest = 'mangalore' where trno='rjd16';
1 row updated.
SQL> select * from slpr;
c) delete a record which have train no=’KKE55’
SQL> delete from slpr where trno='kke55';
1 row deleted.
SQL>Select * from slpr;
2) Create view details to display train no, train name, class
SQL>create view details as select trdet.trno, trdet.trname, avail.class from trdet, avail where
trdet.trno = avail.train_no;
View created.
Select * from slpr;
3) Rename view sleeper to class
SQL>rename slpr to class;
Table renamed.
SQL>Select * from class;
DBMS lab [14]

4) Delete view details


SQL>drop view details;
SQL>select * from class;
View does not exist
---------------------------------------------------------------------------------------------------------------------
ACTIVITY-08
Database:Bank system
Create Following table and insert tuples with suitable constraints
Table:Branch
BRANCH_ID BRANCH_NAME BRANCH_CITY
SB001 Malleshwaram Bangalore
SB002 MG Road Bangalore
SB003 MG Road Mysore
SB004 Jainagar Mysore
Table:Account
ACCOUNT_NO CUST_NAME BRANCH_ID
AE0012856 Reena SB002
AE1185698 Akhil SB001
AE1203996 Daniel SB004
AE1225889 Roy SB002
AE8532166 Sowparnika SB003
AE8552266 Anil SB003
AE1003996 Saathwik SB004
AE1100996 Swarna SB002
Table:Depositor
ACCOUNT_NO BRANCH_ID BALANCE
AE0012856 SB002 12000
AE1203996 SB004 58900
AE8532166 SB003 40000
AE1225889 SB002 15000
Table:Loan
ACCOUNT_NO BRANCH_ID BALANCE
AE1185698 SB001 102000
AE8552266 SB003 40000
AE1003996 SB004 15000
AE1100996 SB002 1000000
Queries:
1. Display max , min loan amount present in each city.
2. Display average amount deposited in each branch
3. Display maximum of loan amount in each branch where balance is more than 25000
4. Display Total Number of accounts present in each city
5. Display all customer details in ascending order of brachid
6. Update Balance to 26000 where accno=AE1003996
7. Display Customer Names with their branch Name
DBMS lab [15]

SQL> create table branch(bid varchar(10)primary key, bname varchar(20),bcity varchar(15));


Table created.
SQL> insert into branch values('sb001', 'malleshwaram', 'bangalore');
1 row created.
SQL> insert into branch values('sb002', 'mg road', 'bangalore');
1 row created.
SQL> select * from branch;

SQL> create table account(accno varchar(15) primary key, custname varchar(15), bid varchar(15)
references branch);
Table created.
SQL> insert into account values('ae0012856', 'reena', 'sb002');
1 row created.
SQL> insert into account values('ae1185638', 'akhil', 'sb001');
1 row created.
SQL> select * from account;
SQL> create table depositor(accno varchar(15)refere nces account, bid varchar(10) references
branch, balance number(10));
Table created.
SQL> insert into depositor values('ae0012856', 'sb002', 12000);
1 row created.
SQL> insert into depositor(accno,bid,balance)values('ae1203996','sb004',58900);
1 row created.
SQL> select * from depositor;

SQL> create table loan (accno varchar(15) references account, bid varchar(10) references
branch,balance number(15));
Table created.
SQL> insert into loan values('ae1185638', 'sb001', 102000);
1 row created.
SQL> insert into loan values('ae8552266', 'sb003', 40000);
1 row created.
SQL> select * from loan;
1)Display total number of accounts present in each branch

SQL> select bid, count(accno) from account group by bid;


2) Display total loan amount in each branch
SQL> select bid, sum(balance) from loan group by bid;
3) Display total deposited amount in each branch by descending order
SQL> select bid, sum(balance) from depositor group by bid order by bid desc;
DBMS lab [16]

4) Display max, min loan amount present in each city


SQL> select bcity, max(balance), min(balance) from branch, loan group by bcity;
5) Display average amount deposited in each branch
SQL> select bid, avg(balance) from depositor group by bid;
6) Display maximum of loan amount in each branch where balance is more than 25000
SQL> select bid, max(balance) from loan where balance > 25000 group by bid;
7) Display total number of accounts present in each city
SQL> select bcity, count(accno) from account, branch where account.bid=branch.bid group by
bcity;
8) Display all customer details in ascending order of branch id
SQL> select * from account order by bid asc;
9) Update balance to 26000 where accno=AE1003996
SQL> update loan set balance = '26000' where accno = 'ae1003996';
1 row updated.
10) Display customer names with their branch name
SQL> select custname, bname from account, branch where account.bid=branch.bid;
---------------------------------------------------------------------------------------------------------------------
Activity:09
Database:Book Dealer
Table:Author
AUTHOR_ID A_NAME CITY COUNTRY
EE10258 Sudaker Samuel Bangalore India
PE96358 Natarasu Kolkata India
LT45879 Tenenbaum Toranto Canada
PW56325 Sumitabha Das Kolkata India
KA56983 Galvin Loss Angles USA

Table:Publisher
PUNLISHER_ID NAME CITY COUNTRY
21 TMH Delhi India
22 PHI Kolkata India
23 PEARSON Mumbai India
24 EEE Singapore Singapore
25 LPE Bangalore India

Table:Category
CATEGORY_ID DESCRIPTION
31 CSE
32 ISE
33 E&E
34 E&C
DBMS lab [17]

Table:Catalog
BOOK_ID TITLE AUTHOR_ID PUBLISHER_ID CATEGORY_ID YEAR PRICE
41 OS PW56325 23 31 1998 275
42 CN LT45879 22 32 2000 475
43 EC EE10258 23 34 2002 380
44 SE LT458769 24 32 2002 480
45 DBMS PW56325 21 31 1999 650
46 EC PE96358 25 33 2004 250
Table:Order Details
ORDER_ID BOOK_ID QUNATITY
51 41 15
52 45 50
53 42 20
54 44 10
55 43 35
56 46 25
Queries :
1. List the other publications located where PEARSON publication is located
2. List the book with maximum price
3. Display book details having quantity=25
4. Display the author details those who are publishing with PHI publisher
5. Display the Books details published for ‘CSE’ category
6. Display the author details those who publish in Indian publications
7. Display book details those who have orders less than 20
8. Display all the books published under ‘CSE’ & ‘ISE’ category
9. Delete book details of order_no=56
10. Alter table order details add new column order_date & update the columns
SQL> create table author(aid varchar(15) primary key, aname varchar(20), city varchar(15),
country varchar(15));
Table created.
SQL> insert into author values('EE10258', 'Sunaker Samuel', 'Bangalore', 'India');
1 row created.
SQL> insert into author values('PE96358', 'Natarasu', 'Kolkata', 'India');
1 row created.
SQL> select * from author;
SQL> create table pub (pid varchar(5) primary key, pname varchar(10), city varchar(15), country
varchar(15));
Table created.
SQL> insert into pub values(21, 'TMH', 'Dehli', 'India');
1 row created.
SQL> insert into pub values(22, 'PHI', 'Kolkata', 'India');
1 row created.
SQL> select * from pub;

SQL> create table category(cid varchar(5) primary key, descrip varchar(10));


Table created.
DBMS lab [18]

SQL> insert into category values(31,'CSE');


1 row created.
SQL> insert into category values(32,'ISE');
1 row created.
SQL> select * from category;

SQL> create table catalog (bid varchar(5), title varchar(7), aid varchar(10) references author,
pid varchar(5) references pub, cid varchar(5) references category, year varchar(6), price
varchar(5));
Table created.
SQL> insert into catalog values(41, 'OS', 'PW56325', 25, 31, 1998, 275);
1 row created.
SQL> insert into catalog values(42, 'CN', 'LT45879', 22, 32, 2000, 475);
1 row created.
SQL> select * from catalog;

SQL> create table order(odno varchar(5),bid varchar(5),quantity varchar(5));


Table created.
SQL> insert into order(odno,bid,quantity)values(51,41,15);
1 row created.
SQL> insert into order(odno,bid,quantity)values(52,45,50);
1 row created.
SQL> select * from order;

1) List the other publications located where PEARSON publication is located


SQL> select name from pub where country in (select country from pub where name =
'PEARSON');
2) List the book with maximum price
SQL> select * from catalog where price in (select max(price) from catalog);

3) Display book details having quantity=25


SQL> select catalog.bid, catalog.title, catalog.author, catalog.price from catalog,order where
order.quantity=25 and order.bid=catalog.bid;

4) Display the author details those who are publishing with PHI publisher
SQL> select author.aid, author.city, author.country, author.aname from author, pub, catalog where
pub.pid=catalog.pid and catalog.aid=author.aid and pub.name='PHI';

5) Display the books detailspublished for'CSE' category


SQL> select * from catalog, caid where category.descrip='CSE' and category.caid=catalog.caid;

6) Display the author details those who publish in Indian publications


SQL> select * from author where country='India';

7) Display book details those have orders less than 20


SQL> select * from catalog,order where order.quantity<20 and order.bid=log.bid;
DBMS lab [19]

8) Display all the books published under 'CSE' & 'ISE' category
SQL> select * from log,caid where(category.descrip='CSE' or category.descrip='ISE') and
category.caid=catalog.caid;
9) Delete book details of order_no=56
SQL> delete from order where odno=56;
1 row deleted
10) Alter table order details add new column order_date & update the columns
SQL> alter table order add(oddate date);
Table altered.
SQL> update order set oddate='11-may-09' where odno=51;
1 row updated.
SQL> update order set oddate='12-may-09'where odno=52;
1 row updated.
SQL> select * from order;
----------------------------------------------------------------------------------------------------------------------
Activity 10
Database:Mobile Shoppe(Using Joins)
Create following table and insert tuples with suitable constraints
Table:Mobile Handsets
CUSTNO CNAME MODEL HANDSETNO AMOUNT
1010 Sita Nokia RM560 9500
1020 Ritesh Samsung SR12365 3200
1030 Reena Nokia RM236 1200
1040 Karan Sony Ericsson SE12334 8200
1050 Anu LG LT1255 2000
Table:Connection Details
CUST CNAME CONNECTI ACTIVATION VALIDI AMOUNT PHONENO
NO ON DATE TY
1010 Seetha Airtel 11-May-09 365 650 9985632551
1020 Ritesh Vodafone 10-Sep-08 180 400 9923033652
1030 Reena Tata Docomo 12-Aug-09 100 150 9036225636
1040 Karan Airtel 12-Jan-09 90 200 9896325415
1060 Anoop Reliance 12-Sep-09 365 220 9342653326
Queries :
1. Display Customer Name, Handset Model, connection, Validity of the connection
2. Display All Mobile Handsets along with Connection and Activation date
3. Display all Connection Details along with handset model and Handset purchase date
4. Display The Handset Details which is having highest amount than Samsung handset
5. Display Customer Name, Handset Model, connection, Validity which is having validity of one
year
6. Display Customer number, customer name, connection and activation date of connections
activated between 01-Jan-08 to 30-Dec-09
7. Display Customer number, Model, Connection which is having ‘Airtel’ Connection
DBMS lab [20]

8. Display Customer number, Model, Connection which is having model is Nokia and connection
is Airtel
9. Select Customer number, customer name and model which is having price more than model
Samsung

SQL> create table mobile(custno number(10), cname varchar(20), model varchar(20), handsetno
varchar(20), amt number(10));
Table created.
SQL> insert into mobile values(1010,'sita','nokia','rm560',9500);
1 row created.
SQL> insert into mobile values(1020,'ritesh','samsung','sr12365',3200);
1 row created.
SQL> select * from mobile;
SQL> create table connect(custno number(10), cname varchar(20), connection varchar(20), adate
date, validity number(10), amt number(10), pno number(20));
Table created.
SQL> insert into connect values(1010,'seetha','airtel','11-may-09',365,650,998562355);
1 row created.
SQL> insert into connect values(1020,'ritesh','vodafone','10-sep-08',180,400,992302265);
1 row created.
SQL> select * from connect;
1) Display customer name,handset model,connection,validity of the connection
SQL> select connect.custno, mobile.model, connect.connection, connect.validity from connect,
mobile where connect.cname = mobile.cname;

2) Display all mobile handset along with connection and activation date
SQL> select mobile.model, connect.connection, connect.adate from connect, mobile where
connect.cname=mobile.cname;

3) Display all connection deatails along with handset model and handset purchase date
SQL> alter table mobile add(pdate date);
Table altered.
SQL> update mobile set pdate='18-sep-09' where custno=1010;
1 row updated.
SQL> update mobile set pdate='15-jan-09' where custno=1020;
1 row updated.
SQL> select * from mobile;
SQL> select connect.connection, mobile.model, mobile.pdate from connect, mobile where
connect.cname=mobile.cname;

4) Display the handset details which is having highest amount than samsung handset
SQL> select * from mobile where amt>3200;
DBMS lab [21]

5) Display customer name, handset model, connection, validity which is having validity of
one year
SQL> select connect.cname, mobile.model, connect.connection, connect.validity from connect,
mobile where connect.cname=mobile.cname;

6 ) Display customer number,customer name,connection and activation date of connections


activated between 01-jan-08 to 30-dec-09
SQL> select custno, cname, connection from connect where adate between '01-jan-08' and
'30-dec-09';
7) Display customer number,model,connection which is having ‘airtel’ connection
SQL> select mobile.custno,mobile.model, connect.connection from mobile, connect where
connect.connection='airtel' and mobile.custno= connect.custno;
8) Display customernumber, model,connection which is having model is nokia and
connection is airtel
SQL> select mobile.custno, mobile.model, connect.connection from mobile, connect where
mobile.model='nokia' and connect.connection='airtel' and mobile.custno= connect.custno;

9) Select customer number,customer name and model which is having price more than
model Samsung
SQL> select custno, cname, model from mobile where amt>3200;

~0~0~0~0~0~

You might also like