0% found this document useful (1 vote)
788 views

SQL Hands On Document - Final

Uploaded by

Sanjay Raaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
788 views

SQL Hands On Document - Final

Uploaded by

Sanjay Raaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Hands-on Exercise:

SQL
Version: SQL /Hands-on Exercise/1.0
Date: 28-07-20

Table of Contents
Hands-on Exercise – SQL

Exercise 1................................................................................................................. 3
Exercise 2................................................................................................................. 5
Exercise 3................................................................................................................. 8
Exercise 4................................................................................................................. 8
Exercise 5................................................................................................................. 9
Exercise 6................................................................................................................. 9
Exercise 7...............................................................................................................10
Exercise 8...............................................................................................................10
Exercise 9...............................................................................................................10
Exercise 10.............................................................................................................11
Exercise 11.............................................................................................................12
Exercise 12.............................................................................................................13
Exercise 13.............................................................................................................14
Exercise 14.............................................................................................................14
Exercise 15.............................................................................................................14
Exercise 16.............................................................................................................14
Exercise 17.............................................................................................................14
Exercise 18.............................................................................................................15
Exercise 19.............................................................................................................15
Exercise 20.............................................................................................................15
Exercise 21.............................................................................................................16
Exercise 22.............................................................................................................16
Exercise 23.............................................................................................................16
Exercise 24.............................................................................................................16
Exercise 25.............................................................................................................17
Exercise 26.............................................................................................................17

Week1

Page 2
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

DDL, DML, DQL, DCL, TCL

Exercise 1
Hands-on Exercise Objective
After completing the hands-on exercises, you will be able to:
Understand How to Create Tables

Problem Statement:
You have to create all tables whose structure is as mentioned below:

Trainer_Info
Siz
Field Description Type
e
Trainer_Id Unique ID to every trainer Character 20
Salutation Salutaion of trainer Character 7
Trainer_Name Name of trainer Character 30
Trainer_Location Location of trainer Character 30
Trainer_Track Track of trainer e.g. JAVA, .Net, Mainframe Character 15
Trainer_Qualification Qualification of trainer e.g. MCA,B. Tech Character 100
Trainer_Experiance Experience of trainer e.g .2,4 years Integer 11
Trainer_Email Email Id of trainer Character 100
Trainer_Password Login password of Trainer Character 20

Page 3
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Batch_Info
Siz
Field Description Type
e
Batch_Id Unique ID to every batch Character 20
Batch_Owner Batch owner name Character 30
Batch_BU_Name Business unit to which batch belongs Character 30

Module_Info
Siz
Field Description Type
e
Module_Id Unique ID to every module e.g J2SE, J2EE Character 20
Module_Name Name of module e.g. Core Java SE 1.6 Character 40
Module_Duration Duration in hrs Integer 11

Associate_Info
Siz
Field Description Type
e
Characte
Associate_Id Unique ID to every associate 20
r
Characte
Salutation Salutaion of associate 7
r
Characte
Associate_Name Name of associate 30
r
Characte
Associate_Location Location of associate 30
r
Characte
Associate_Track Track of associate e.g. JAVA, .Net, Mainframe 15
r
Characte
Associate_Qualification Qualification of associate e.g. MCA,B. Tech 200
r
Characte
Associate_Email Email Id of associate 100
r
Characte
Associate_Password Login password of associate 20
r

Questions
Field Description Type Size
Question_Id Unique ID to every question Character 20
Module_Id Module id from module Character 20
Question_Text Actual feedback question Character 900

Associate_Status
Siz
Field Description Type
e
Characte
Associate_Id Associate Id from associate_Info 20
r
Module_Id Module Id from module Characte 20

Page 4
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

r
Characte
Start_Date Date when associate batch started 20
r
Characte
End_Date Date when associate batch ended 20
r
AFeedbackGive Characte
Flag to test whether Associate has given feedback or not 20
n r
TFeedbackGive Characte
Flag to test whether Trainer has given feedback or not 20
n r

Trainer_Feedback
Siz
Field Description Type
e
Trainer_Id Trainer Id from trainer_Info Character 20
Question_Id Question Id from Questions Character 20
Batch_Id Batch Id from batch_Info Character 20
Module_Id Module Id from module Character 20
Trainer_Rating Rating given by trainer for a perticular question Integer 11

Associate_Feedback
Siz
Field Description Type
e
Characte
Associate_Id Associate Id from associate_Info 20
r
Characte
Question_Id Question Id from Questions 20
r
Characte
Module_Id Module Id from module 20
r
Associate_Rating Rating given by associate for a perticular question Integer 11

Login_Details
Siz
Field Description Type
e
Characte
User_Id User id for login 20
r
Characte
User_Password Password to authenticate user 20
r

Deliverables Expected:
All Tables creation as per details mentioned above

Exercise 2

Page 5
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Hands-on Exercise Objective


After completing the hands-on exercises, you will be able to:
Insert data into tables

Problem Statement:
Insert below details into table:

Trainer_Info
Trainer_Id,Salutation,Trainer_Name,Trainer_Location,Trainer_Track,Trainer_Qualificatio
n,Trainer_Experiance,Trainer_Email,Trainer_Password

F001,Mr.,PANKAJ GHOSH,Pune,Java,Bachelor of
Technology,12,[email protected],fac1@123
F002,Mr.,SANJAY RADHAKRISHNAN ,Bangalore,DotNet,Bachelor of
Technology,12,[email protected],fac2@123
F003,Mr.,VIJAY MATHUR,Chennai,Mainframe,Bachelor of
Technology,10,[email protected],fac3@123
F004,Mrs.,NANDINI NAIR,Kolkata,Java,Master of Computer
Applications,9,[email protected],fac4@123
F005,Miss.,ANITHA PAREKH,Hyderabad,Testing,Master of Computer
Applications,6,[email protected],fac5@123
F006,Mr.,MANOJ AGRAWAL ,Mumbai,Mainframe,Bachelor of
Technology,9,[email protected],fac6@123
F007,Ms.,MEENA KULKARNI,Coimbatore,Testing,Bachelor of
Technology,5,[email protected],fac7@123
F009,Mr.,SAGAR MENON ,Mumbai,Java,Master of Science In Information
Technology,12,[email protected],fac8@123
Batch_Info
Batch_Id,Batch_Owner,Batch_BU_Name
B001,MRS.SWATI ROY,MSP
B002,MRS.ARURNA K,HEALTHCARE
B003,MR.RAJESH KRISHNAN,LIFE SCIENCES
B004,MR.SACHIN SHETTY,BFS
B005,MR.RAMESH PATEL,COMMUNICATIONS
B006,MRS.SUSAN CHERIAN,RETAIL & HOSPITALITY
B007,MRS.SAMPADA JAIN,MSP
B008,MRS.KAVITA REGE,BPO
B009,MR.RAVI SEJPAL,MSP

Module_Info
Module_Id,Module_Name,Module_Duration
O10SQL,Oracle 10g SQL ,16
O10PLSQL,Oracle 10g PL/ SQL ,16
J2SE,Core Java SE 1.6,288
J2EE,Advanced Java EE 1.6,80
JAVAFX,JavaFX 2.1,80
DOTNT4,.Net Framework 4.0 ,50
SQL2008,MS SQl Server 2008,120
MSBI08,MS BI Studio 2008,158

Page 6
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

SHRPNT,MS Share Point ,80


ANDRD4,Android 4.0,200
EM001,Instructor,0
EM002,Course Material,0
EM003,Learning Effectiveness,0
EM004,Environment,0
EM005,Job Impact,0
TM001,Attendees,0
TM002,Course Material,0
TM003,Environment,0

Associate_Info
Associate_Id,Salutation,Associate_Name,Associate_Location,Associate_Track,Associate
_Qualification,Associate_Email,Associate_Password

A001,Miss.,GAYATHRI NARAYANAN,Gurgaon,Java,Bachelor of
Technology,[email protected],tne1@123
A002,Mrs.,RADHIKA MOHAN,Kerala,Java,Bachelor of Engineering In Information
Technology,[email protected],tne2@123
A003,Mr.,KISHORE SRINIVAS,Chennai,Java,Bachelor of Engineering In
Computers,[email protected],tne3@123
A004,Mr.,ANAND RANGANATHAN,Mumbai,DotNet,Master of Computer
Applications,[email protected],tne4@123
A005,Miss.,LEELA MENON,Kerala,Mainframe,Bachelor of Engineering In Information
Technology,[email protected],tne5@123
A006,Mrs.,ARTI KRISHNAN,Pune,Testing,Master of Computer
Applications,[email protected],tne6@123
A007,Mr.,PRABHAKAR SHUNMUGHAM,Mumbai,Java,Bachelor of
Technology,[email protected],tne7@123

Questions
Question_Id,Module_Id,Question_Text
Q001,EM001,Instructor knowledgeable and able to handle all your queries
Q002,EM001,All the topics in a particular course handled by the trainer without any gaps
or slippages
Q003,EM002,The course materials presentation, handson, etc. refered during the
training are relevant and useful.
Q004,EM002,The Hands on session adequate enough to grasp the understanding of the
topic.
Q005,EM002,The reference materials suggested for each module are adequate.
Q006,EM003,Knowledge and skills presented in this training are applicatible at your work
Q007,EM003,This training increases my proficiency level
Q008,EM004,The physical environment e.g. classroom space, air-conditioning was
conducive to learning.
Q009,EM004,The software/hardware environment provided was sufficient for the purpose
of the training.
Q010,EM005,This training will improve your job performance.
Q011,EM005,This training align with the business priorities and goals.
Q012,TM001,Participants were receptive and had attitude towards learning.
Q013,TM001,All participats gained the knowledge and the practical skills after this
training.

Page 7
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Q014,TM002,The course materials presentation, handson, etc. available for the session
covers the entire objectives of the course.
Q015,TM002,Complexity of the course is adequate for the particpate level.
Q016,TM002,Case study and practical demos helpful in understanding of the topic
Q017,TM003,The physical environment e.g. classroom space, air-conditioning was
conducive to learning.
Q018,TM003,The software/hardware environment provided was adequate for the
purpose of the training.

Associate_Status
Associate_Id,Module_Id,Batch_Id,Trainer_Id,Start_Date,End_Date
A001,O10SQL,B001,F001,2000-12-15,2000-12-25
A002,O10SQL,B001,F001,2000-12-15,2000-12-25
A003,O10SQL,B001,F001,2000-12-15,2000-12-25
A001,O10PLSQL,B002,F002,2001-2-1,2001-2-12
A002,O10PLSQL,B002,F002,2001-2-1,2001-2-12
A003,O10PLSQL,B002,F002,2001-2-1,2001-2-12
A001,J2SE,B003,F003,2002-8-20,2002-10-25
A002,J2SE,B003,F003,2002-8-20,2002-10-25
A001,J2EE,B004,F004,2005-12-1,2005-12-25
A002,J2EE,B004,F004,2005-12-1,2005-12-25
A003,J2EE,B004,F004,2005-12-1,2005-12-25
A004,J2EE,B004,F004,2005-12-1,2005-12-25
A005,JAVAFX,B005,F006,2005-12-4,2005-12-20
A006,JAVAFX,B005,F006,2005-12-4,2005-12-20
A006,SQL2008,B006,F007,2007-6-21,2007-6-28
A007,SQL2008,B006,F007,2007-6-21,2007-6-28
A002,MSBI08,B007,F006,2009-6-26,2009-6-29
A003,MSBI08,B007,F006,2009-6-26,2009-6-29
A004,MSBI08,B007,F006,2009-6-26,2009-6-29
A002,ANDRD4,B008,F005,2010-6-5,2010-6-28
A005,ANDRD4,B008,F005,2010-6-5,2010-6-28
A003,ANDRD4,B009,F005,2011-8-1,2011-8-20
A006,ANDRD4,B009,F005,2011-8-1,2011-8-20

Deliverables Expected:
All records inserted in tables

Exercise 3
Hands-on Exercise Objective
After completing the hands-on exercises, you will be able to:
Understand how to change data in table

Problem Statement:
Change the password of trainer F004 from fac4@123 to nn4@123

Page 8
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Deliverables Expected:
Updated password of trainer F004.

Exercise 4

Hands-on Exercise Objective


After completing the hands-on exercises, you will be able to:
Understand how to delete data from table.

Problem Statement:
Remove following record form associate_status table
A003,J2EE,B004,F004,2005-12-1,2005-12-25

Deliverables Expected:
Removed record from associate status.

Exercise 5
Hands-on Exercise Objective
After completing the hands-on exercises, you will be able to:
Understand how to perform TOP N records.

Problem Statement:
Fetch first five trainers who have maximum years of experience & display there details.

Deliverables Expected:
Top five experience trainers.

Exercise 6

Hands-on Exercise Objective


After completing the hands-on exercises, you will be able to:
Understand transaction.

Problem Statement:
Begin transaction & insert below to records into Login_Details
'U001' Admin1@123
'U002' Admin2@123

Page 9
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Perform rollback operation & verify whether any records are inserted in table or not.

Deliverables Expected:
Empty table

Exercise 7

Hands-on Exercise Objective


After completing the hands-on exercises, you will be able to:
Understand TCL.

Problem Statement:
Create a dummy user in database. Grant create & select table privilege to him/her.
Repeat the above all queries using login credentials of newly created user.
Revoke the privilege assigned to this newly created user.

Deliverables Expected:
Same result as achieved till now.

Exercise 8

Hands-on Exercise Objective


After completing the hands-on exercises, you will be able to:
Understanding how to drop table.

Problem Statement:
Remove table Login_Details from database.

Deliverables Expected:
No table found message while querying Login_Details table.

Constraints

Exercise 9
Create a table called suppliers that stores supplier ID, name, and address information.

Page 10
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Field Data type Constraint


supplier_id number(10) Not Null
supplier_name varchar2(50) Not Null
address varchar2(50)
city varchar2(50),
state varchar2(25)
zip_code varchar2(10))

Operators

Exercise 10
The prerequisite for the given activity is to create the following tables.

Column Name Data Type


Course_Code Varchar2

Base_fees Number

Special_fees Number

Created_By Varchar2

Updated_By Varchar2

Page 11
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Course Fees
COURSE_CODE BASE_FEES SPECIAL_FEES DISCOUNT
1 180 100 10

2 150 110 10

3 160 170 5

4 150 100 10

6 190 100 40

Course Fees_History
COURSE_CODE BASE_FEES SPECIAL_FEES CREATED_BY Updated _By

1 120 123 Ram Ramesh

2 150 110 Bala Ram

3 160 170 Bala Vinu

4 170 235 Ram Ram

6 190 100 Vinod Vinod

Problem Statement:
Display all the unique courses between course fees and course fees_history.

Exercise 11
Use the following columns to check for uniqueness of Course_Code, BASE_FEES and
SPECIAL_FEES of the courses in both the COURSE_FEES and
COURSE_FEES_HISTORY.

Functions
Case Study Scenario:

Page 12
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

This case study is to develop a Course Management System (CMS) for ABC University. The
following are the two use cases for which the database needs to be designed.
Add Course:
To add the course details into the course management system.
Retrieve Course:
Retrieve the courses stored in the system and display it.
The courses to be added will have the following attributes: Course Code, Course Name, Number
of participants, Course Description, Course Duration, Course start date, and Course Type.

Pre-requisite
Create a table named “COURSE_INFO” & “Student_Info” with following column name,
data type, data size, and following constraints:
COURSE_CODE – PRIMARY KEY
COURSE_NAME – NOT NULL.
STUDENT_ID –PRIMARY KEY

Column Name Data Type Data Size


COURSE_CODE varchar 10
COURSE_NAME varchar 20
COURSE_DESCRIPTION varchar 25
COURSE_START_DATE Date
COURSE_DURATION int
NO_OF_PARTICIPANTS int
COURSE_TYPE Char(3)

Column Name Data Type Data Size

STUDENT_ID varchar 10

FIRST_NAME varchar 20

LAST_NAME varchar 25

ADDRESS varchar 150

Exercise 12
Pre-requisite : Use the Course_Info and Course_Fees table.
• Insert 2 records in course_fees table with base fees as null.
• Insert 2 records in course_fees table with base fees as 300 and 175.

Problem Statement:
Display the minimum and maximum base fees of the courses.

Page 13
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Exercise 13
Display the average infra fees of the courses.

Exercise 14
Pre-requisite: We will use the Course_Info and Course_Fees tables for doing this lend a
hand. Add a new column Infra_Fees in course_fees with type number(5,3). For all the
records in update the Infra_Fees with some values say 45.751, 43.453 etc.
Hints: Use joins wherever needed

Problem Statement:
Develop a query which will display the course name and the number of days between the
current date and course start date in Course_Info table

Exercise 15
Problem Statement:
Develop a query which will concatenate the Course Name and Course Code in the
following format and display all the courses in the course_info table.
“< Course Name><Course Code>”

Exercise 16
Develop a query calculate average of all the base fees, any records whose base fee is
null needs to be considered as zero.

Exercise 17
Pre-requisite: Use the Course_Info and Course_Fees table.
• Insert 2 records in course_fees table with base fees as null.
• Insert 2 records in course_fees table with base fees as 300 and 175.
• Insert 3 records in course_info table each course with course type
CLR,EL, OF

Problem Statement:
Write a query which will display the course type and the appropriate message as
mentioned below.
Course_Type Message

CLR ‘Class Room’


EL ‘ELearning’
OF ‘Offline Reading’

Page 14
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Clauses
• Case Study Scenario:
– This case study is to develop a Course Management System (CMS) for ABC University.
The following are the two use cases for which the database needs to be designed.
• Add Course:
– To add the course details into the course management system.
• Retrieve Course:
– Retrieve the courses stored in the system and display it.
• The courses to be added will have the following attributes: Course Code, Course Name,
Number of participants, Course Description, Course Duration, Course start date, and Course Type.

Exercise 18
Problem Statement: Develop a query which would retrieve the total number of students
enrolled for courses on a specific date grouped by course start date and display course
start date and total number of students.

Exercise 19
Problem Statement: Develop a query which would retrieve the total number of students
enrolled for courses where course_type=“CLR” grouped by course start date and display
course start date and total number of students.

Exercise 20
Problem Statement: Develop a query which would retrieve the total number of students
enrolled for courses where course_type=“CLR” grouped by course start date and display
course start date and total number of students where the total number of students > 10.

Page 15
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Week2

Exercise 21
Develop a query which displays all the courses in increasing order of course duration.

Joins
Case Study Scenario:
This case study is to develop a Course Management System (CMS) for ABC University. The
following are the two use cases for which the database needs to be designed.
Add Course:
To add the course details into the course management system.
Retrieve Course:
Retrieve the courses stored in the system and display it.
The courses to be added will have the following attributes: Course Code, Course Name, Number
of participants, Course Description, Course Duration, Course start date, and Course Type.

Exercise 22
Write a query to fetch student ID, first name, last name, and course code for students
who have enrolled for course having course_code as 167. Student_Info and
student_courses to be queried.

Exercise 23
Write a query to display the discount offered on the courses along with course
descriptions.

Exercise 24
Pre-requisite: Create a student record (student_info_ <employee id>).
Note: Do not create any other detail regarding this student in any other table.

Problem Statement: Write a query to fetch first names of the students along with the
course codes of the courses they have enrolled in.
Note: Even if the course_code does not exist for a student, the record needs to be
fetched.
Get the same output as per the requirement above using:
• Left Join
• Right Join

Subqueries
Page 16
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected
Hands-on Exercise – SQL

Case Study Scenario:


This case study is to develop a Course Management System (CMS) for ABC University. The
following are the two use cases for which the database needs to be designed.
Add Course:
To add the course details into the course management system.
Retrieve Course:
Retrieve the courses stored in the system and display it.
The courses to be added will have the following attributes: Course Code, Course Name, Number
of participants, Course Description, Course Duration, Course start date, and Course Type.

Exercise 25
Pre-Requisite:
— Insert the following records
— Add two new courses in course_info table
— Add the course fees for the two courses in course_Fees with fees amount
< 1500
— Enroll two students to the newly added courses
Problem Statement: Write a query which fetches the student id for students who have
enrolled for at least one course whose fees is less than 1500.

Exercise 26
Write a query which fetches the student id and student name for students who have
enrolled for at least one course whose fees is less than 1500.

Page 17
©Copyright 2020, Cognizant Technology Solutions, All Rights Reserved
C2: Protected

You might also like