Вы находитесь на странице: 1из 26

2018

Look forward,
learn modern
knowledge, and
do not waste
time in studies
of old subjects of
no values.

Lab Manual
B.Sc. (CA)
SEMESTER - III

CCB-3P1: LABORATORY COURSE - III

DEPARTMENT OF COMPUTER SCIENCE

ALIGARH MUSLIM UNIVERSITY ALIGARH


Credits

Lab Manual Design Committee:


 Prof. Mohammad Ubaidullah Bokhari
 Dr. Arman Rasool Faridi
 Dr. Faisal Anwar
 Dr. Aasim Zafar (Convener)

Editor:
 Dr. Aasim Zafar

Design & Compilation:


 Mr. S. K. Sharma

Second Edition: July 2018

Department of Computer Science


A.M.U., Aligarh, (U.P.), India
COURSE TITLE: Laboratory Course-III COURSE CODE: CCB – 3P1
CREDIT: 02 PERIODS PER WEEK: 03
CONTINUOUS ASSESSMENT: 40 EXAMS: 60

COURSE DESCRIPTION
This assignment on DBMS is designed for the students of B.Sc.
(Computer Application), IV-Semester to learn the concepts of DBMS.
DBMS is actually 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. Student can
use Oracle/MySQL for this assignment.

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 databases from an ER diagram.


 Normalize the database to remove redundancy.

 Create a full fledge database for any system.

 Write different types of SQL queries.

 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.

 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.

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 (Only for the questions 1,2,3,6, 7,8,9,10 and 11)

 SQL query with output

 Each question will be evaluated on a scale of 10 points, 4 for E-


R Diagram (where applicable) and 6/10 for queries.

 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.
APPENDIX-1
Template for the Index of Lab File
WEEK NO.

PAGE NO.
SIGNATURE OF THE
PROBLEMS WITH DESCRIPTION TEACHER WITH DATE

1#

1 2#

3#

1#

2 2#

3#

1#

3 2#

3#

Note: The students should use Header and Footer mentioning their roll no. & name in footer and page no in header.
WEEK #1
OBJECTIVES

 To learn to draw E-R diagram.


 To learn to design database based on E-R diagram.

OUTCOMES

After completing this, the students would be able to:

 Draw E-R diagram.


 Design Database based on E-R diagram

PROBLEMS

1# Consider a CONFERENCE_REVIEW database in which researchers submit


their research papers for consideration. Reviews by reviewers are recorded
for use in the paper selection process. The database system caters primarily
to reviewers who record answers to evaluation questions for each paper they
review and make recommendations regarding whether to accept or reject the
paper. The data requirements are summarized as follows:

a) Authors of papers are uniquely identified by e-mail id. First and last
names are also recorded.
b) Each paper is assigned a unique identifier by the system and is described
by a title, abstract, and the name of the electronic file containing the
paper.
c) A paper may have multiple authors, but one of the authors is designated
as the contact author.
d) Reviewers of papers are uniquely identified by e-mail address. Each
reviewer‟s first name, last name, phone number, affiliation, and topics of
interest are also recorded.
e) Each paper is assigned between two and four reviewers. A reviewer rates
each paper assigned to him or her on a scale of 1 to 10 in four categories:
technical merit, readability, originality, and relevance to the conference.
Finally, each reviewer provides an overall recommendation regarding each
paper.
f) Each review contains two types of written comments: one to be seen by
the review committee only and the other as feedback to the author(s).

Design ER diagram and construct database for the above. Give logical
reasoning for the database design.
WEEK #2
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
professionally.

PROBLEMS

1# Consider a MAIL_ORDER database in which employees take orders for parts


from customers. The data requirements are summarized as follows:

a) The mail order company has employees, each identified by a unique


employee number, first and last name, and Zip Code.
b) Each customer of the company is identified by a unique customer number,
first and last name, and Zip Code.
c) Each part sold by the company is identified by a unique part number, a
part name, price, and quantity in stock.
d) Each order placed by a customer is taken by an employee and is given a
unique order number. Each order contains specified quantities of one or
more parts. Each order has a date of receipt as well as an expected ship
date. The actual ship date is also recorded.
Design an Entity-Relationship Diagram and Database for the MAIL_ORDER
system using a tool such as ERDPlus etc.
WEEK #3

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
ADDRESS 1 Varchar2 30
ADDRESS 2 Varchar2 30
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
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:


Client Name City Pin State BalDue
No code
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 Descripti Profit Unit Qty On Reorde Sell Cost


No on Percent Measure Hand rLvl Price Price

P00001 T-Shirts 5 Piece 200 50 350 250


P0345 Shirts 6 Piece 150 50 500 350
P06734 Cotton 5 Piece 100 20 600 450
Jeans
P07865 Jeans 5 Piece 100 20 750 500
P07868 Trousers 2 Piece 150 50 850 550
P07885 Pull 2.5 Piece 80 30 700 450
Overs
P07965 Denim 4 Piece 100 40 350 250
Shirts
P07975 Lycra 5 Piece 70 30 300 175
Tops
P08865 Skirts 5 Piece 75 30 450 300

c) Data for SALESMAN_MASTER table:

Salesman Name Address1 Address2 City PinCode State SALAMT


No

S00001 Aman A/14 Worli Mumba 400002 Maharashtr 3500


i a
S00002 Omkar 65 Nariman Mumba 400001 Maharashtr 4000
i a
S00003 Raj P-7 Bandra Mumba 400032 Maharashtr 5000
i a
S00004 Ashish A/5 Juhu Mumba 400044 Maharashtr 3500
i a
WEEK #4–5

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 week #3 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 sate 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‟.
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 alongwith its data.


VI. Exercise on renaming the table

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


WEEK #6–7
OBJECTIVES

 To learn how o write queries for creating tables with constraints and
inserting and retrieving the records.
 To learn to add columns to table.

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# A database is to be designed for Book dealer with the following details:

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, Publisher-id: int, Category-id: int, Year:
int, Price: int)

BOOK_AUTHOR(Book-id: int,author-id: int)

CATEGORY (Category-id: int, Description: string)

ORDER-DETAILS (Order-no : int, Book-id: int, Quantity: int)

a) Create above tables and mention primary keys and foreign keys.
b) Insert at least five relevant records in each of the created relations.
c) Write the following SQL queries based on the created Database:
i) Retrieve details of the authors who have authored 1 or more books.
ii) Retrieve details of the books whose price is greater than the average
price of the books in the catalog and the year of publication are after
2010.
iii) Retrieve details of the books which have more than 1 author.
iv) Retrieve details of publishers associated with author “John”.
v) Demonstrate how you increase the price of books published by a
specific publisher by 10%.
d) Write a SQL query to add two more columns, Association and
Qualification in AUTHOR table.
WEEK #8–9
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.
iv) List all the clients who are located in ALIGARH.
v) Find the products whose selling price is greater than 2000 and less
than orequal to 5000.
vi) List the products in sorted order of their description.
WEEK #10–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 Database created in Question
No. 8:
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.
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.
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 maximum and minimum of
three numbers entered through users.
3# Write a PL/SQL stored procedure to find sum of first ten natural numbers.
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.
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 Empoyee)

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)

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.
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_LOGtable.
c) Write a PL-SQL cursor that increments the salary of employees of
Grade „D‟ by 20%.
d) 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‟

2# Write a PL-SQL cursor to find second highest salary from EMPLOYEE table.

3# 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 selects the maximum department number in the
department table and store it in a variable and print the results to screen.
b) Create a PL/SQL block to insert a new department record into the
Departments table. Use maximum dept number fetched from above and
adds 10 to it.
c) Create a PL/SQL Block to delete the department no. 10.Print to the screen
the number of rows affected.
d) Write a Cursor to find MGRID of Departments located in “Mumbai”.

4# Establish a relationship between tables given in 1# and the previous week.


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 forall 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".
Department of Computer Science
Aligarh Muslim University Aligarh

Вам также может понравиться