DATABASE APPLICATIONS LABORATORY GCEM
Xv | Gopalan College
Aw of Engineering and Management
180 9001 : 2008
APPROVED BY AICTE NEW DELHI, AFFILIATED TO VTU BELGAUM
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
DATABASE APPLICATIONS LAB MANUAL-10CSL57
2016-2017
SEMESTER-VII
Prepared by: Reviewed by: Approved by:
JSomasekar, NSS Saradha Devi Dr. A A Powly Thomas
Asse. Professor Head of the Department Principal
Dept. of CSE, Dept. of CSE GCEM
GCEM GCEM
181/1, 182/1, Hoodi Village, Sonnenahalli, K.R. Puram, Bengaluru,
Karnataka 560048
DEPARTMENT OF C&R BAGH]Database applications laboratory GCEM
COURSE OBJECTIVE
Upon successful completion of this Lab the student will be able to:
> Creating database objects
> Modifying database objects
y
Manipulating the data
> Retrieving the data from the database server
v
Performing database operations in a procedural manner using pl/sql
v
Performing database operations (create, update, modify, retrieve, ete.,)
> Design and Develop applications like banking, reservation system, ete.,
COURSE OUTCOME
> Gaining the Knowledge on SQL.
> Able to create tables with and without constraints
> Able to make relation between two or more tables,
v
Able to retrieve data based on various conditions.
DEPARTMENT OF CSE PAGE 2 SEMESTER -VDatabase applications laboratory GCEM
COMPUTER LAB DO’S AND DON’T
DO’S
1. Know the location of the fire extinguisher and the first aid box and how to
use them in case of an emergency.
2. Read and understand how to carry out an activity thoroughly before coming
to the laboratory.
3. Report fires or accidents to your lecturer/laboratory technician immediately.
4. Report any broken plugs or exposed electrical wires to your
lecturer/laboratory technician immediately.
DON’TS
1. Do not eat or drink in the laboratory.
2. Avoid stepping on electrical wires or any other computer cables.
3. Do not open the system unit casing or monitor casing particularly when the
power is turned on. Some internal components hold electric voltages of up to
30000 volts, which can be fatal.
4. Do not insert metal objects such as clips, pins and needles into the computer
casings. They may cause fire.
5. Do not remove anything from the computer laboratory without permission.
6. Do not touch, connect or disconnect any plug or cable without your
lecturer/laboratory technician’s permission.
7. Do not misbehave in the computer laboratory.
DEPARTMENT OF CSE PAGE 3 SEMESTER -VDATABASE APPLICATIONS LABORATORY GCEM
SYLLABUS
Database Applications Laboratory
1. Consider the following relations:
STUDENT (snum: integer, sname: string, major: string, level: string, age: integer)
CLASS (name: string, meets at: string, room: string, d: integer)
ENROLLED (snum: integer, cname: string)
FACULTY (fid: integer, fname: string, deptid: integer)
The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair
such that the student is enrolled in the class. Level is a two character code with 4 different values (example:
Junior: JR etc) Write the following queries in SQL. No duplicates should be printed in any of the answers.
i, Find the names of all Juniors (level = JR) who are enrolled in a class taught by Prof. Harshith
ii, Find the names of all classes that either meet in room R128 or have five or more Students enrolled.
iii, Find the names of all students who are enrolled in two classes that meet at the same time.
iv. Find the names of faculty members who teach in every room in which some class is taught.
v. Find the names of faculty members for whom the combined enrollment of the courses that they teach is
less than five.
2. The following relations keep track of airline flight information:
FLIGHTS (no: integer, from: string, to: string, distance: integer, Departs: time, arrives: time, price: real)
AIRCRAFT (aid: integer, aname: string, cruisingrange: integer)
‘TIFIED (cid: integer, aid: integer)
EMPLOYEES (cid: integer, ename: string, salary: integer)
Note that the Employees relation describes pilots and other kinds of employees as well; Every pilot is
certified for some aircraft, and only pilots are certified to fly. Write each of the following queries in SQL.
i, Find the names of aircraft such that all pilots certified to operate them have salaries more than Rs.80, 000.
ii, For each pilot who is certified for more than three aircrafts, find the eid and the maximum cruisingrange of
the aircraft for which she or he is certified.
iii, Find the names of pilots whose salary is less than the price of the cheapest route from Bengaluru to
Frankfurt
iv. For all aircraft with cruisingrange over 1000 Kms, find the name of the aircraft and the average salary of
all pilots certified for this aircraft
v. Find the names of pilots certified for some Boeing aircraft. vi. Find the aids of all aircraft that can be used
on routes fiom Bengaluru to New Delhi.
3. Consider the following database of student enrollment in courses & books adopted for each course.
STUDENT (regno: string, name: string, major: string, bdate:date)
COURSE (course #:int, cname:string, dept:string)
ENROLL ( regno:string, course#:int, sem:int, marks:int)
BOOK _ ADOPTION (course# :int, sem:int, book-ISBN:int)
TEXT (book-ISBN:int, book-title:string, publisher:string, author:string)
DEPARTMENT OF CSE PAGE -4- SEMESTER -VDatabase applications laboratory GCEM
i. Create the above tables by properly specifying the primary keys and the foreign keys
ii, Enter at least five tuples for each relation.
iii, Demonstrate how you add a new text book to the database and make this book be adopted by some
department,
iv. Produce a list of text books (include Course if, Book-ISBN, Book-title) in the alphabetical order for
courses offered by the ‘CS’ department that use more than two books.
v. List any department that has all its adopted books published by a specific publisher.
vi. Generate suitable reports.
vii. Create suitable front end for querying and displaying the results.
4. The following tables are maintained by a book dealer.
AUTHOR (author-id:int, name:string, city:string, country:string)
PUBLISHER (publisher-id:int, name:string, city:string, country:string)
CATALOG (book-id:int, title:string, author-id:int, publisher-id:int, category-id:int, year-int, price:int)
CATEGORY (category-id:int, description:string)
ORDER-DETAILS (order-no:int, book-id:int, quantity:int)
i, Create the above tables by properly specifying the primary keys and the foreign keys.
ii, Enter at least five tuples for each relation.
iii, Give the details of the authors who have 2 or more books in the catalog and the price of the books is
greater than the average price of the books in the catalog and the year of publication is after 2000.
iv. Find the author of the book which has maximum sales,
v, Demonstrate how you increase the price of books published by a specific publisher by 10%
vi. Generate suitable reports.
vii. Create suitable front end for querying and displaying the results.
5. Consider the following database for a banking enterprise
BRANCH (branch-name:string, branch-city:string, assets:real)
ACCOUNT(aceno:int, branch-name:string, balance:real)
DEPOSITOR(customer-name:string, accno:int)
CUSTOMER (customer-name:string, customer-street:string, customer-city:string)
LOAN(loan-number:int, branch-name:string, amount:real)
BORROWER (customer-name:string, loan-number:int)
i, Create the above tables by properly specifying the primary keys and the foreign keys
ii, Enter at least five tuples for each relation
iii, Find all the customers who have at least two accounts at the Main branch.
iv. Find all the customers who have an account at all the branches located in a specific city.
v. Demonstrate how you delete all account tuples at every branch located in a specific city.
vi. Generate suitable reports.
vii. Create suitable front end for querying and displaying the results.
DEPARTMENT OF CSE Page-5- semesterDatabase applications laboratory GCEM
INSTRUCTIONS:
1, The exercises are to be solved in an RDBMS environment like Oracle or DB2.
2. Suitable tuples have to be entered so that queries are executed correctly.
3. Front end may be created using either VB or VAJ or any other similar tool.
4, The student need not create the front end in the examination. The results of the queries may be displayed
directly.
5. Relevant queries other than the ones listed along with the exercises may also be asked in the examination.
6. Questions must be asked based on lots.
DEPARTMENT OF CSE Page-6- semesterDatabase applications laboratory GCEM
TABLE OF CONTENTS:
sl Page No.
no | DATE NAME OF THE EXPERIMENT
12-14
1 STUDENT FACULTY DATABASE — Solving
Queries and Report Generation
2 AIRCRAFT DATABASE ~ Solving Queries and | !>!7
Report Generation
18-20
5 STUDENT BOOK DATABASE — Solving Queries
and Report Generation
21-23
4 BOOK DEALER DATABASE — Solving Queries
and Report Generation
5 BANK DATABASE - Creation & Insertion of 2426
Values
DEPARTMENT OF CSE Page-7- 3 semesterDatabase applications laboratory GCEM
BACKGROUND THEORY OF SQL
Oracle workgroup or server is the largest selling RDBMS product.it is estimated that the combined sales
of both these oracle database product account for aroud 80% of the RDBMSsystems sold worldwide. These
products are constantly undergoing change and evolving. The natural language of this RDBMS product is
ANSI SQL,PL/SQL a superset of ANST SQL.oracle 8i and 91 also under stand SQLJ.Oracle corp has also
incorporated a full-fledged java virtual machine into its database engine.since both executable share the same
memory space the JVM can communicate With the database engine with ease and has direct access to oracle
tables and their data.
SQL is structure query language.SQL contains different data types those are
char(size)
varchar2(size)
date
number(p.s)
long
raw/long raw
aya eEe
ifferent types of commands L:
A). DDL commands: - To create a database objects
B). DML commands: - To manipulate data of a database objects
C). DQL command: - To retrieve the data from a database.
D). DCL/DTL commands: - To control the data of a database,
DDL commands
1, The Create Table Command: - it defines each column of the table uniquely. Each column has minimum
of three attributes, a name , data type and size.
Syntax:
Create table
(
(),));
Ex:
create table emp(empno number(4) primary key, ename char(10));
2. Modifying the structure of tables.
a)add new columns
Syntax:
Alter table add(datatype(size));
Ex:
alter table emp add(sal number(7,2));
3. Dropping a column from a table.
Syntax:
Aller table drop column
;
DEPARTMENT OF CSE Page-8-
semesterDatabase applications laboratory GCEM
Ex:
alter table emp drop column sal;
4. Modifying existing columns.
Syntax:
Alter table modify(
Ex:
alter table emp modify(ename varchar2(15));
5, Renaming the tables
syntax:
Rename to ;
Ex:
rename emp to empl;
6, truncating the tables.
Syntax:
Truncate table ;
Ex:
trune table emp];
7. Destroying tables.
Syntax:
Drop table ;
Ex:
drop table emp;
DML commands:
8. Inserting Data into Tables:
to be manipulated later.
once a table is created the most natural thing to do is load this table with data
Syntax:
insert into (,) values();
9. Delete operations.
a) remove all rows
Syntax:
delete from ;
DEPARTMENT OF CSE Page-9- semesterDatabase applications laboratory GCEM
) removal of a specified row/s
Syntax:
delete from where ;
10. Updating the contents of a table.
a) updating all rows
Syntax:
Update set
=,
;
b) updating seleted records,
Syntax:
Updateset
=,
= where ;
11. Types of data constrains.
a) not null constraint at column level
Syntax:
(size)not null
b) unique constraint
Syntax:
Unique constraint at column level.
(size) check()
DEPARTMENT OF CSE Page- 10- S® semesterDatabase applications laboratory GCEM
4) check constraint constraint at table level.
Syntax: check()
DQL Command:
12. Viewing data in the tables: - once data has been inserted into a table, the next most logical operation
would be to view what has been inserted.
a) all rows and all columns
Syntax:
Select
to
from tablename;
Select * from tablename;
13, Filtering table data: - while viewing data from a table, it is rare that all the data from table will be
required each time. Hence, sql must give us a method of filtering out data that is not required data.
a) Selected columns and all rows:
Syntax:
select , from ;
b) selected rows and all columns:
Syntax:
select * from where ;
¢) selected columns and selected rows
Syntax:
select , from where;
14, Sorting data in a table.
Syntax:
Select * from order by , <[sortorder}>;
DCL commands:
Oracle provides extensive feature in order to safeguard information stored in its tables from unauthoraised
viewing and damage.The rights that allow the user of some or all oracle resources on the server are called
privileges.
a) Grant privileges using the GRANT statement
The grant statement provides various types of access to database objects such as tables,views and sequences
and so on,
Syntax:
GRANT