DBMS Lab activities
DBMS Lab activities
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
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.
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]
Table: EMPSALARY
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;
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
SQL> select fname, lname from empl1 where (sysdate-hiredate)>365;
DBMS lab [5]
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';
Table:Books
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);
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]
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
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
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;
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;
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
Table:Physics
Table:Computer_Science
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
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 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
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 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;
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';
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;
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~