CS403 P Lab Manual 1
CS403 P Lab Manual 1
Systems (Practical)
Page
Lab No. Lab Topic
No.
4 Lab 4: Super type and subtype in the ERD (Entity Relationship Diagram) 27
1|Page
Lab 1
Lab Title: Installation of Microsoft SQL Server
Problem Statement
You are required to install any version of Microsoft SQL Server in your system according to
your system and operating system requirements.
Installation Steps:
2|Page
3|Page
4|Page
5|Page
6|Page
7|Page
8|Page
9|Page
10 | P a g e
11 | P a g e
12 | P a g e
13 | P a g e
14 | P a g e
15 | P a g e
16 | P a g e
17 | P a g e
18 | P a g e
19 | P a g e
20 | P a g e
21 | P a g e
Mechanism to Conduct Lab:
22 | P a g e
Lab 2
Lab Title: Context Level DFD (Data Flow Diagram)
Problem Statement
“Thela”, lemon soda offering company has decided to take orders online. By using this online
system customer can place the order and view receipt generated by system. Order is
prepared/processed and sent to delivery man. The delivery man will deliver order and receive
payment form the customer. After receiving payment, the delivery man can update status in the
system as payment received.
Identify the External Entities and processes from the above scenario and draw:
Solution:
23 | P a g e
Level 0 DFD
24 | P a g e
Lab 3
Lab Title: Entity Relationship Diagram
Problem Statement
“Thela”, lemon soda offering company has decided to take orders online. Customer places the
order online and at the time of delivery pays the bill. Order is prepared and delivered by the
delivery man to the customer. Customer pays the bill to the delivery man.
Identify Entities.
Identify the attributes of the entities.
Identify the relationships between the entities.
Draw the Entity Relationship diagram from the information extracted in first three tasks.
25 | P a g e
Solution:
ERD:
Mechanism to Conduct Lab: Lab will be conducted via Google Meet / Zoom.
26 | P a g e
Lab 4
Lab Title: Super type and subtype in the ERD (Entity Relationship Diagram)
Problem Statement
Lemon Soda Service
“Thela”, lemon soda offering company has decided to take orders online. Customer places the
order online and at the time of delivery pays the bill. Order is prepared and delivered by the
delivery man to the customer. Customer pays the bill to the delivery man.
Customer and Delivery man both are the person. Introduce the concept of super type and subtype
in the ERD drawn in Lab 3.
Solution
Problem Statement
Consider the following relation scheme of “Candidate” entity in the domain of Election
Commission of Pakistan (ECP).
Solution:
1. Database relation:
Candidate = { (Rana Maqsood, NA-45, 40, BA) , (Sohail Khan, NA-16, 55, MA), (Shiraz
Hussain Dar, NA-21, 37, MS) ,(Asad Ullah, NA-65, 35, M.Sc) }
2. Table
CandName Constituency Age Qualification
Problem Statement
You are required to transform the following ERD (Entity Relationship Diagram) to Relational
Data model using the transforming/mapping rules taught in the video lectures and handouts. You
also have to show the primary keys and foreign keys.
ERD:
Solution:
Mechanism to Conduct Lab: Lab will be conducted via Google Meet / Zoom.
29 | P a g e
Lab 7
Lab Title: Relational Algebra Operations
Problem Statement
Consider the following two relations:
Employee 1:
Employee 2:
EmpName Designation Age Salary
Solution:
1
EmpName Designation Age Salary
2
EmpName Designation Age Salary
3
EmpName Salary
Farukh 25000
4
31 | P a g e
EmpName Designation Age Salary
32 | P a g e
Lab 8
Lab Title: Normalization (2NF)
Problem Statement
You have studied the concept of normalization (and different normal forms) in this course.
Following relation is already in First Normal Form. You are required to convert it into Second
Normal Form using the techniques you have studied so far.
The above relation contains different redundancies. The relation can be expressed in a shorthand
notation as follows:
The above relation contains a composite primary key of EmpID and CourseTitle. The
functional dependencies in this relation are as follows:
33 | P a g e
Solution:
All the partially dependent attributes are removed and placed in another relation when a relation
is converted from 1NF to 2NF. The decomposition must satisfy one of the following conditions.
The EMPLOYEE relation can be divided into two relations EMPLOYEE and COURSE as
follows:
34 | P a g e
101 Advertising 15/03/2010
The primary key in EMPLOYEE relation consists of only one attribute. It satisfies the first
condition. The attribute DateCompleted in COURSE relation is fully functionally depends on
whole composite key. It satisfies the third condition. It means that both relations are in second
normal forms.
35 | P a g e
Lab 9
Lab Title: Normalization (3NF)
Problem Statement
Following relation is already in Second Normal Form. You are required to convert it into Third
Normal Form using the techniques you have studied so far.
The attribute CustomerID is used as primary key. Each salesman is assigned a unique region.
The above relation contains the following functional dependencies:
SalesMan Region
The above relation is in 2NF because the primary key consists of single attribute. A transitive
dependency exists in the relation. The Region (a non-key attribute) is dependent on another non-
key attribute (SalesMan) and SalesMan is functionally dependent on CustomerID. It means that
region is transitively dependent on CustomerID.
Solution:
Transitive dependency exists if a non-key attribute depends on any other non-key attribute.
36 | P a g e
The transitive dependency can be removed by decomposing the above relation into two relations
as follows:
11 Hamza Khalid
21 Shoaib Umair
31 Shahbaz khalid
44 Salman Zulfiqar
51 Rizwan Umair
61 farooq Uzair
SalesMan Region
Khalid South
Umair West
Zulfiqar East
Uzair North
Both relations are now in 3NF. There is no transitive dependency in these relations.
The determinant attribute in transitive dependency becomes the primary key in SALESMAN
relation.
37 | P a g e
Lab 10
Lab Title: SQL Queries (Create and Insert)
Problem Statement
Teacher:
Class:
Consider the above given tables and perform the following Tasks;
Solution:
);
39 | P a g e
Lab 11
Lab Title: SQL Queries
Problem Statement
Given are the tables of Teacher and Class:
40 | P a g e
Consider the above given tables and perform the following Tasks;
1. Display all the records of the class whose start time is between 09:00 and 12:00
2. Retrieve the details of teachers with first name Dr.
3. On which days classes of CS403 are scheduled at 09:00 AM?
4. List down the Subjects which are taught in B Block.
5. Select the course code from Class table, avoiding the duplicate values.
6. Display all the records of the class whose start time is 09:00 or 12:00 and end time is less
than 14:00
Solution:
1:
Select *
From Classes
Where StartTime Between '09:00' and '12:00'
2:
Select * from Teacher
Where Name Like 'Dr.%'
3:
Select DayofWeek
From Classes
Where CourseCode='CS403' AND StartTime='09:00'
4:
Select CourseCode
From Classes
Where Venue='B Block'
41 | P a g e
5:
Select distinct CourseCode
From Classes
6:
Select *
From Classes
Where (StartTime='09:00' OR StartTime='12:00') AND EndTime<'14:00'
42 | P a g e
Lab 12
Lab Title: SQL Queries (Select, Group By and Having clause)
Problem Statement
Teacher:
Class:
Consider the above given tables and perform the following Tasks;
43 | P a g e
Solution:
1:
Select count(*) from Teacher;
2:
Select count(distinct CourseCode) As All_Courses
from Class;
3:
Select Min(EndTime) As Late_Classes
from Class
GROUP BY CourseCode;
4:
Select AVG(Salary)
From Teacher
GROUP BY Office
Having Office IS NOT NULL;
44 | P a g e
Lab 13
Lab Title: Joins
Problem Statement
45 | P a g e
Consider the above given tables and apply the following types of joins:
1. Inner join
2. Full Outer join
3. Right Outer join
4. Left Outer join
Solution:
46 | P a g e
Lab 14
Lab Title: Indexes
Problem Statement
TEACHER:
1. Write SQL query to create a UNIQUE INDEX on the “TeacherID” column of the given
table in Descending order.
2. Write SQL query to create a UNIQUE INDEX on the “Name” and “Office” columns of
the given table in ascending order.
47 | P a g e
Solution:
48 | P a g e
Lab 15
Lab Title: Views
Problem Statement
Class:
You are required to write an SQL query to create a “View” on this table having ClassID,
CourseCode and Venue columns. Furthermore, the view would have information for only those
classes conducted in the “A Block” venue.
Solution:
49 | P a g e
Lab 16
Lab Title: Views (Continued)
Problem Statement
Consider the following table:
Products:
Bread 20 25 50
French Pastry 17 25 35
Slice 20 25 20
Large Cake 50 60 30
Pastry 10 15 70
Biscuit 15 20 45
Rolls 25 30 65
You are required to write an SQL query to create a “View” on this table having ProductName,
Sale_Price and Stock_Qty columns. Furthermore, the view would have information for only those
products having Sale price greater than the average sale price in the given table.
50 | P a g e
Solution:
51 | P a g e