2020-21 ual · This Lab assignment course is designed to help students to create database and apply...

38
B.Sc. (C.A.) Semester-III ALIGARH MUSLIM UNIVERSITY ALIGARH 2020-21 Look forward, learn modern knowledge, and do not waste time in studies of old subjects of no values. Computer Lab Manual DEPARTMENT OF COMPUTER SCIENCE CCB-3P1: PRACTICAL LAB III

Transcript of 2020-21 ual · This Lab assignment course is designed to help students to create database and apply...

Page 1: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

B.Sc. (C.A.) Semester-III

ALIGARH MUSLIM UNIVERSITY ALIGARH

2020-21

Look forward,

learn modern

knowledge, and

do not waste

time in studies

of old subjects of

no values.

Co

mp

ute

r L

ab

Ma

nu

al

DEPARTMENT OF COMPUTER SCIENCE

CCB-3P1: PRACTICAL LAB – III

Page 2: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Important Instructions to the students in the

ongoing Covid-19 Scenario

❒ In the present Covid-19 scenario, all the labs will be conducted

ONLINE till the further instructions issued by the University.

❒ Students are instructed to perform their lab exercises/assignments at

their own system from their respective residences.

❒ During this prevailing situation (COVID-19 crises), the mode

(policies/rules) of conducting Lecture/Lab classes will be as per the

time to time instructions issued by University.

❒ The students are advised to complete the weekly

activities/assignments well in time (i.e., within the same week).

❒ The students are also advised to maintain the soft copy of the Lab

File of their completed activities/assignments in the prescribed

format.

!! Stay Home, Stay Safe !!

Page 3: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

The following Lab Manuals Up-gradation Committee members updated

the Lab Manuals during lockdown and finally approved in the meeting

of Lab Manuals Up-gradation Committee held on 07.07.2020 at 11:30

AM through ONLINE mode using Google Meet:

Prof. Rafiqul Zaman Khan (Chairperson)

Mr. Suhel Mustajab

Dr. Aasim Zafar

Dr. Arman Rasool Faridi

Dr. Faisal Anwer

Dr. Mohammad Nadeem

The following committee members originally designed the Lab Manual

under the supervision of former Chairperson Prof. Jamshed Siddiqui:

Prof. Mohammad Ubaidullah Bokhari

Dr. Arman Rasool Faridi

Dr. Faisal Anwer

Dr. Aasim Zafar (Convener)

Design & Compilation:

Mr. S. K. Sharma

Revised Edition: July 2020

Approved by BoS: 14.07.2020

Department of Computer Science

A.M.U., Aligarh, (U.P.), India

CREDITS

s

Page 4: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Lab Manual: Practical Lab – III (CCB-3P1)

CONTENTS PAGE NO.

WEEK WISE CONTENTS 2

COURSE DESCRIPTION 3

CONTENT 3

OBJECTIVES 3

OUTCOME 4

HOW TO DO WELL IN THIS COURSE 4

RULES AND REGULATIONS 6

Page 5: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 2

WEEK WISE CONTENTS

Week No. Contents Page No.

#1& #2 Installation and access of DBMS 9

#3 E-R diagram using automated tools 17

#4 Create tables and insert some records 19

#5& #6

Queries for retrieving, updating, deleting the records,

alter table structure and rename table 23

#7& #8

Queries for creating tables with constraints, inserting

and retrieving the records. 25

#9& #10

Queries for inserting and retrieving the records based

on given scenario. 27

#11

Queries for inserting and retrieving the records based

on given scenario. 29

#12 PL/SQL stored procedures. 31

#13 Cursors and triggers in PL/SQL 32

#14 Triggers and cursors, PL/SQL block and cursors. 34

Page 6: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 3

COURSE TITLE: Practical Lab-III COURSE CODE: CCB – 3P1

CREDIT: 4 PERIODS PER WEEK: 3

CONTINUOUS ASSESSMENT: 40 Marks EXAMS: 60 Marks

COURSE DESCRIPTION

This assignment on DBMS is designed for the students of B.Sc.

(Computer Application) III-Semester to learn the concepts of DBMS. DBMS is

system software that enables a user to create and maintain a database. It

facilitates the process of defining, constructing, manipulating and sharing

databases among various users.

There are several DBMS in the market, among these Oracle, MySQL are

most popular and widely used. Oracle provides a free version namely Oracle

Express edition for the student and independent developers for performing data

base related tasks. MySQL is an open source DBMS maintained by Oracle.

CONTENT

This Lab assignment course is designed to help students to create database

and apply PL/SQL to manipulate the database. Several live scenarios have been

included in the assignment to design E-R Diagram and subsequently create

database. Students are supposed to write queries for creating, retrieving and

manipulating the database. This course is indented to develop a deep

understanding of various query languages such as DDL, DCL, DML, PL

OBJECTIVES

After completing this Lab assignment, the students should be able to:

Design ER diagram and Schema diagram

Design databases from an ER diagram.

Create a full fledge database for any system.

Write different types of SQL queries.

Page 7: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 4

Write PL/SQL block, Cursors, Triggers, Procedures and functions.

OUTCOMES

After completing this course, the students would be able to:

Understand the concept of relational database management system.

Understand the concept of Object-relational database management

system.

Comprehend query languages and their usage.

Logically identify logical entities and their relationships.

Draw Entity relationship diagram for any system.

Create cursor, function, procedure, triggers and other database objects.

HOW TO DO WELL IN THIS COURSE

❒ The students are advised to attend all their theory classes and respective

labs regularly as both are integrated to each other. If any student will miss

the theory lecture, he/she may not able to do well in lab related to that

topic.

❒ The students are advised to submit the assignments given in theory and

lab classes timely to their respective Teachers/Instructors online.

❒ The students should demonstrate disciplined and well behaved demeanor

in the Department.

❒ Each student shall be assigned a system in their introductory lab. They are

advised to do their work on that system only for the whole semester.

Students should store all their lab activities regularly.

❒ All students are advised to understand course objectives and outcomes and

achieve both during their lab work.

Page 8: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 5

❒ The students are advised to follow books/eBooks/online tutorial/other

online study material links given in lecture/lab manual/ syllabus

references. These study materials are very helpful in terms of skills,

knowledge and placement.

❒ This Lab course is very important in terms of placement. Therefore,

students are advised to implement all the problems by her /him given in

the individual week.

❒ All students are advised to solve old placement papers for campus

selection. Following links may be useful for the preparation of your

campus placements.

https://www.indiabix.com/placement-papers/companies/

https://www.offcampusjobs4u.com/download-tcs-placement-test-

question-papers-with-solutions/

https://www.indiabix.com/placement-papers/tcs/

https://www.firstnaukri.com/career-guidance/infosys-placement-

papers-with-solutions-2019-firstnaukri-prep

https://prepinsta.com/ibm/

https://www.faceprep.in/infosys/infosys-aptitude-questions/

https://alpingi.com/infosys-placement-papers-solution-pdf-download/

http://placement.freshersworld.com/

❒ The Students are advised to follow mentioned tutorials links:

https://www.javatpoint.com/dbms-tutorial

https://www.tutorialspoint.com/dbms/index.htm

https://www.w3schools.com/sql/

https://www.tutorialspoint.com/sql/index.htm

https://www.oracletutorial.com/plsql-tutorial/

https://www.plsqltutorial.com/

Page 9: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 6

The Students are advised to follow below Links for installing application

software:

https://www.oracle.com/in/database/technologies/appdev/xe.html

https://www.oracle.com/database/technologies/xe-downloads.html

The Students are advised to follow below Links for online compilers :

https://www.tutorialspoint.com/execute_sql_online.php

https://www.onlinegdb.com/online_sqlite_editor

RULES AND REGULATIONS

Students are required to strictly adhere to the following rules.

The students must complete the weekly activities/assignments well in

time (i.e., within the same week).

The students must maintain the Lab File of their completed

activities/assignments in the prescribed format (Appendix-1).

The students must get the completed weekly activities/assignments

checked and signed by the concerned teachers in the Lab in the

immediate succeeding week. Failing which the activities/assignments for

that week will be treated as incomplete.

At least TEN (10) such timely completed and duly signed weekly

activities/assignments are compulsory, failing which students will not be

allowed to appear in the final Lab Examination.

The students need to submit the following two deliverables for each

exercise duly signed by the Teacher:

ER Diagram and Schema Diagram (Only for the questions 3, 7-8,9-10

and 11)

SQL or PL/SQL query with output.

Each question will be evaluated on a scale of 10 points.

Page 10: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 7

The students need to ensure that each question is assessed and signed by

the Teacher in the week/time.

Late submission would not be accepted after the due date.

Cooperate, collaborate and explore for the best individual learning

outcomes but copying is strictly prohibited.

Page 11: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 8

APPENDIX–I

Template for the Index of Lab File

WE

EK

NO

.

PROBLEMS WITH DESCRIPTION

PA

GE

NO

. SIGNATURE

OF THE

TEACHER

WITH DATE

1

1#

2#

3#

2

1#

2#

3#

3

1#

2#

3#

Note: The students should use Header and Footer mentioning their roll no. &

name in footer and page no in header.

Page 12: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 9

WEEK #1 & #2

OBJECTIVES

To learn basics of DBMS and its different types.

To learn to how to access Oracle and MySql.

OUTCOMES

After completing this, the students would be able to:

know different types of DBMS.

install Oracle Express Edition.

access Oracle Express Edition

Steps of Installing Oracle Express Edition

Oracle Database Express Edition (XE) is a free edition of Oracle Database. This

edition of Oracle is a community supported edition of the Oracle Database family.

Step 1: Open the website Oracle.com and click as given in below figure

Resources-Software Download

Page 13: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 10

Step 2: Click on Database Database 18C Express Edition

Page 14: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 11

Step 3: Click on Oracle database 18C Express Edition as per your Operating

system

Step 4: Accept the License Agreement and click on Download

Page 15: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 12

Step 4: You need to create an account in Oracle

Step 5: After download extract the zip file. You will get the following files.

Click on setup that will show you installing window.

Page 16: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 13

e

Step 6: Click on Next

Step 7: Enter Database Password and Conform Database Password

Page 17: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 14

Page 18: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 15

Steps of Accessing Oracle

Step 1: Go to Start button and press Oracle folder then click SQL Plus as

given below:

Step 2: Enter user name and password in the next screen as provided during

the installation of Oracle

Page 19: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 16

Step 3: After entering the correct user name and password you will get the

SQL prompt, where you can enter the SQL commands

Page 20: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 17

WEEK #3

OBJECTIVES

To learn to draw E-R diagram using automated tools.

To learn to design database using automated tools.

OUTCOMES

After completing this, the students would be able to:

Understand E-R Diagram.

Understand Database.

Design of ER Diagram and database using automated tools.

PROBLEMS

1# Indian Railway wants to maintain its database for the train, driver and the

platforms with the following requirements:

a) A train has attributes as train no., name, source, destination.

b) A driver has its attributes as Driver name, age,

c) Each Platform has its attributes as Platform id, name, district name.

d) Each train may be driven by different drivers but each driver drives

only specific train.

e) A train may stop at different platforms and a platform may

accommodate several trains at a moment of time.

2# Consider a car dealership that sells both new and used cars, and it operates a

service facility. The data requirements are summarized as follows:

a) A salesperson may sell many cars, but each car is sold by only one

salesperson.

Page 21: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 18

b) A customer may buy many cars, but each car is bought by only one

customer.

c) A salesperson writes a single invoice for each car he or she sells.

d) A customer gets an invoice for each car he or she buys.

e) A customer may come in just to have his or her car serviced; that is, a

customer need not buy a car to be classified as a customer.

f) When a customer takes one or more cars in for repair or service, one

service ticket is written for each car.

g) The car dealership maintains a service history for each of the cars

serviced. The service records are referenced by the car‟s serial number.

h) A car brought in for service can be worked on by many mechanics, and

each mechanic may work on many cars.

i) A car that is serviced may or may not need parts (e.g., adjusting a

carburettor or cleaning a fuel injector nozzle does not require providing

new parts).

Design ER diagram, schema diagram and construct database for the above.

Give logical reasoning for the database design.

Page 22: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 19

WEEK #4

OBJECTIVES

To learn to create tables and insert some records.

OUTCOMES

After completing this, the students would be able to:

Understand table and its related concepts.

PROBLEMS

1# Create the tables described below:

Table Name: CLIENT_MASTER

Description: Used to store client information.

Column Name Data Type Size Default Attributes

CLIENTNO Varchar2 6

NAME Varchar2 20

CITY Varchar2 15

PINCODE Number 8

STATE Varchar2 15

BALDUE Number 10,2

Table Name: PRODUCT_MASTER

Description: Used to store product information.

Column Name Data Type Size Default Attributes

PRODUCTNO Varchar2 6

Page 23: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 20

DESCRIPTION Varchar2 15

PROFITPERCENT Number 4,2

UNITMEASURE Varchar2 10

QTYONHAND Number 8

REORDERLVL Number 8

SELLPRICE Number 8,2

COSTPRICE Number 8,2

Table Name: SALESMAN_MASTER

Description: Used to store salesman information working for the company.

Column Name Data Type Size Default Attributes

SALESMANNO Varchar2 6

SALESMANNAME Varchar2 20

ADDRESS 1 Varchar2 30

ADDRESS 2 Varchar2 30

CITY Varchar2 20

PINCODE Number 8

STATE Varchar2 20

SALAMT Number 8,2

2# Insert the following data into their respective tables:

a) Data for CLIENT_MASTER table:

Page 24: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 21

ClientNo Name City Pin code State BalDue

C00001 Ivan Bayross Mumbai 400054 Maharashtra 15000

C00002 Mamta

Muzumder Madras 780001 Tamil Nadu 0

C00003 Chhaya Bankar Mumbai 400057 Maharashtra 5000

C00004 Ashwini Joshi Bangalore 560001 Karnataka 0

C00005 Hansel Colaco Mumbai 400060 Maharashtra 2000

C00006 Deepak Sharma Mangalore 560050 Karnataka 0

b) Data for PRODUCT_MASTER table:

Product

No

Description Profit

Percent

Unit

Measure

Qty On

Hand

ReorderLvl Sell

Price

CostPrice

P00001 T-Shirts 5 Piece 200 50 350 250

P0345 Shirts 6 Piece 150 50 500 350

P06734 Cotton

Jeans

5 Piece 100 20 600 450

P07865 Jeans 5 Piece 100 20 750 500

P07868 Trousers 2 Piece 150 50 850 550

P07885 Pull Overs 2.5 Piece 80 30 700 450

P07965 Denim

Shirts

4 Piece 100 40 350 250

P07975 Lycra Tops 5 Piece 70 30 300 175

P08865 Skirts 5 Piece 75 30 450 300

Page 25: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 22

c) Data for SALESMAN_MASTER table:

Salesman

No

Name Address1 Address2 City PinCode State SALAMT

S00001 Aman A/14 Worli Mumbai 400002 Maharashtra 3500

S00002 Omkar 65 Nariman Mumbai 400001 Maharashtra 4000

S00003 Raj P-7 Bandra Mumbai 400032 Maharashtra 5000

S00004 Ashish A/5 Juhu Mumbai 400044 Maharashtra 3500

Page 26: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 23

WEEK #5 & #6

OBJECTIVES

To learn to write queries for retrieving, updating and deleting the records.

To learn to alter table structure, delete and rename table.

OUTCOMES

After completing this, the students would be able to:

Understand how to write DDL, DML based queries.

PROBLEMS

1# Write the SQL queries for the following based on previous week's tables:

I. Exercise on retrieving records from a table

a) Find out the names of all the clients.

b) Retrieve the entire contents of the Client_Master table.

c) Retrieve the list of names, city and the state of all the clients.

II. Exercise on updating records in a table

a) Change the city of ClientNo „C00005‟ to „Bangalore‟.

b) Change the BalDue of ClientNo „C00001‟ to Rs. 1000.

c) Change the cost price of „Trousers‟ to Rs. 950.00.

III. Exercise on deleting records in a table

a) Delete all salesman from the Salesman_Master whose salaries are

equal to Rs. 3500.

b) Delete all products from Product_Master where the quantity on hand

is equal to 100.

c) Delete from Client_Master where the column state holds the value

„Tamil Nadu‟.

Page 27: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 24

IV. Exercise on altering the table structure

a) Add a column called „Telephone‟ of data type „number‟ and size=‟10‟

to the Client_Master table.

b) Change the size of SellPrice column in Product_Master to 10,2.

V. Exercise on deleting the table structure along with the data

a) Destroy the table Client_Master along with its data(Note: Copy the

data to some other temporary table so that the data should not get

lost).

VI. Exercise on renaming the table

a) Change the name of the Salesman_Master table to sman_mast.

Page 28: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 25

WEEK #7 & #8

OBJECTIVES

To learn how to write queries for creating tables with constraints and

inserting and retrieving the records.

OUTCOMES

After completing this, the students would be able to:

Understand the different constraints that can be applied on a table.

Write DML, DDL based queries.

PROBLEMS

1# Consider the insurance database given below. The primary keys are made

bold and the data types are specified.

PERSON(driver_id:string , name:string , address:string )

CAR(regno:string , model:string , year:int )

ACCIDENT(report_number:int , accd_date:date , location:string )

OWNS(driver_id:string , regno:string )

PARTICIPATED(driver_id:string , regno:string , report_number:int ,

damage_amount:int).

a) Create the above tables by properly specifying the primary keys and

foreign keys.

b) Enter at least five tuples for each relation.

c) Update the damage amount for the car with specific regno in the

accident with report number 12 to 25000.

d) Add a new accident to the database.

Page 29: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 26

e) Find the total number of people who owned cars that were involved in

accidents in the year 2008.

f) Find the number of accidents in which cars belonging to a specific

model were involved.

2# Consider the following database for a banking enterprise.

BRANCH( branch_name:string , branch_city:string , assets:real )

ACCOUNT( accno: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 )

a) Create the above tables by properly specifying the primary keys and

foreign keys.

b) Enter at least five tuples for each relation.

c) Find all the customers who have at least two accounts at

the main branch.

d) Find all the customers who have an account at all the branches located

in a specific city.

e) Demonstrate how you delete all account tuples at every branch located

in a specific city.

Page 30: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 27

WEEK #9 & #10

OBJECTIVES

To learn to create tables based on given scenario.

To learn to write queries for inserting and retrieving the records.

OUTCOMES

After completing this, the students would be able to:

Understanding of creating tables based on given scenario.

Understanding of writing DML, DDL based queries.

PROBLEMS

1# A database is to be designed for sales information system. A product can be

described with a unique product number, product name, sellingprice,

manufacturer name. The product can sale to a particular client and each

client have its own unique client ID, client name, client addresses, city, pin

code and total balance to be required to paid. Each client orders to buy

product from the salesman. In the order, it has unique sales order number,

sales order date, client number and salesman number. Each salesman has the

salesman number (unique), name, addresses, city, pin code, salary of the

sales man.

a) Create the above tables and mention primary keys and the foreign keys

b) Insert at least five relevant records in each of the created relations.

c) Write following SQL queries based on created Database:

i) Retrieve names and cities of all the clients.

ii) Retrieve the available products.

iii) Find the names of all clients having „a‟ as the second letter in their

names.

Page 31: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 28

iv) List all the clients who are located in ALIGARH.

v) Find the products whose selling price is greater than 2000 and less

than or equal to 5000.

vi) List the products in sorted order of their description.

Page 32: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 29

WEEK #11

OBJECTIVES

To learn to create tables based on given scenario.

To learn to write queries for inserting and retrieving the records.

OUTCOMES

After completing this, the students would be able to:

Understanding of creating tables based on given scenario.

Understanding of writing DML, DDL based queries.

PROBLEMS

1# Create an inter University Database with the following relations. Include at

least four attributes for each table.

University

Department

Program

Course

Syllabus

Faculty(Teacher)

a) Create above tables and mention primary keys and foreign keys. Also

create secondary index for each table.

b) Insert at least 5 relevant records in each of the created tables.

c) Write following SQL queries based on above created database:

i) List of Universities situated at Delhi.

ii) List of all Departments of AMU.

iii) Find the location of JNU.

iv) List of all Programs run by University of Jammu.

Page 33: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 30

v) List of Universities that run Program "MCA".

vi) List of Courses of "MCA" run by AMU.

vii) List of Faculties specialized in "Information Security" across

different universities.

viii) Syllabus of "Computer Architecture" of different Universities.

ix) List of all faculties of Department of Computer Science of

Delhi University.

x) Find the University which has maximum Departments.

Page 34: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 31

WEEK #12

OBJECTIVES

To learn to write PL/SQL stored procedures.

OUTCOMES

After completing this, the students would be able to:

Understand how to write procedures in PL/SQL.

Understand how to write PL/SQL functions.

PROBLEMS

1# Write a PL/SQL stored procedure to display “Hello World”.

2# Write a PL/SQL stored procedure to calculate the sum of digits of a number

entered through users.

3# Write a PL/SQL stored procedure to count no. of even and odd integers

entered by the user.

4# Write a PL-SQL function to compare three numbers entered through users

and display them in ascending and descending orders.

5# Write a PL/SQL function that performs simple arithmetic like Addition,

Subtraction, Multiplication & Division of input numbers.

Page 35: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 32

WEEK #13

OBJECTIVES

To learn to write cursors and triggers in PL/SQL.

OUTCOMES

After completing this, the students would be able to:

Understand how to use cursors and triggers in PL/SQL.

PROBLEMS

1# Create table EMPLOYEE with 5 columns:

ENo Number (Employee Number)

FName Varchar2 (First name )

Age Number (Age of Employee)

Grade Varchar2 (Grade of Employee such Asst. Prof., Associate Prof. or

Professor)

Salary Number (Salary of the Employee)

Create a Cursor Emp_Cursor that fetches the record of employee and their

salary are incremented according to grade such as for Asst prof, the salary

increment is 10000, for Associate Prof 20,000 and for Professor 30,000.

2# Create table GRADES with 5 columns:

SENo Number (Student's Enrollment Number)

M1 Number (Mark from test 1 )

M2 Number (Mark from test 2)

M3 Number (Mark from test 3)

Page 36: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 33

Avg_M Number (average mark from test 1, 2 and 3)

a) Create a trigger GRADES_TRG that calculates the value of the Avg_M

column.

b) Create a trigger on table GRADES such that it restricts the entry of

duplicate SENo and also it restricts the marks greater than 50 in each

test.

Page 37: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 34

WEEK #14

OBJECTIVES

To learn to write triggers and cursors in PL/SQL.

To learn to write PL/SQL block and cursors.

OUTCOMES

After completing this, the students would be able to:

Understand the use of cursors and triggers.

Understand PL/SQL block and cursors.

PROBLEMS

1# Create an EMPLOYEE table with columns:

(EMP_ID,EMP_NAME,EMP_DOB,EMP_SAL,EMP_GRADE,

EMP_DNO) and an EMPLOYEE_LOG table with columns

(EMP_ID,EMP_NAME,EMP_DOB,

EMP_PRE_GRADE,EMP_PRE_SAL). EMP_GRADE contains value like

„A‟,‟B‟,‟C‟,‟D‟. Next solve the following:

a) Write a PL/SQL code to insert some rows in Employee table

b) Create a PL/SQL trigger called EMPLOYEE_TRIGGER on the

EMPLOYEE table. This trigger will be executed after every update of

EMP_SAL or EMP_GRADE which will put the previous Employee

value to EMPLOYEE_LOG table.

c) Write a PL/SQL block to find the salary grade of the specified

employee.

i) If grade is „D‟ display „the employee is junior engineer‟

ii) If grade is „C‟ display „the employee is engineer‟

iii) If grade is „B‟ display „the employee is lead engineer‟

iv) If grade is „A‟ display „the employee is Manager‟

Page 38: 2020-21 ual · This Lab assignment course is designed to help students to create database and apply PL/SQL to manipulate the database. Several live scenarios have been included in

Department of Computer Science/Lab Manual/ Under Graduate/ CCB-3P1 35

2# Create a DEPARTMENT table with columns:

(DEPT_NO,DEPT_NAME,DEPT_LOC,DEPT_MGRID).

Next solve the following:

a) Write a PL/SQL block that counts the number of departments in each

location. If any location has more than 5 departments then display

message “too many departments”.

b) Create a PL/SQL block to insert a new department record into the

Departments table.

c) Create a PL/SQL Block to delete the department no. 10.Print to the

screen the number of rows affected.

3# Establish a relationship between tables given in 1# and 2#. Next solve the

following:

a) Write a PL/SQL block which accepts employee number and finds the

average salary of the employees working in the department where that

employee works. If his salary is more than the average salary of his

department, then display message that "employee‟s salary is more than

average salary" else display "employee‟s salary is less than average

salary".

b) Write a PL/SQL block which displays the department name, total no of

employees in the department, average salary of the employees in the

department for all the departments from department 10 to department

40 in the Department table. If no employee is working in the

department, then display a message "No employees are working in that

department".