You are on page 1of 10

METTL_MYSQL _PRACTICE_LAB

<EMPLOYEE_ID>.COURSE_INFO

Column Name Data Type Data Size

COURSE_CODE varchar2 10 Primary Key

COURSE_NAME varchar2 20

COURSE_DESCRIPTION varchar2 25 0

COURSE_START_DATE Date

COURSE_DURATION Number

NO_OF_PARTICIPANTS Number

COURSE_TYPE Char(3)

<EMPLOYEE_ID>.STUDENT_INFO

Column Name Data Type Data


Size

STUDENT_ID varchar2 10 Primary


Key

FIRST_NAME varchar2 20

LAST_NAME varchar2 25

ADDRESS varchar2 150

<EMPLOYEE_ID>.STUDENT_COURSES

Column Name Data Type Data


Size

STUDENT_ID varchar2 10 Foreign


Key

COURSE_CODE varchar2 20 Foreign


Key
METTL_MYSQL _PRACTICE_LAB

<EMPLOYEE_ID>. COURSE_FEES

Column Name Data Type Data


Size

COURSE_CODE varchar2 10 Foreign


key

BASE_FEES Number 10

SPECIAL_FEES Number 10

DISCOUNT Number 5

Objective: Associates should use the DDL statements and create the tables, constraints identified. Also
they should use the appropriate DML statements to load the table with student information.
Problem # 1 Creating Tables : Create following tables using Oracle Client and DDLs.
i. Create Student_Info_<employee_id> table This table is used for storing the student
personal information.
a. Reg_Number Primary Key - Varchar
b. Student_Name - Varchar(30) not null
c. Branch Varchar
d. Contact_Number Varchar
e. Date_of_Birth-Date, not null
f. Date_of_Joining-Date Default value system date.
g. Address-Varchar(250)
h. Email_id-Varchar(250)

ii. Create Subject_Master_<employee_id> table This table is used for storing the subjects
information which are delivered in the university.
a. Subject_Code- Primarykey-varchar2(10)
b. Subject_Name- Varchar, not null
c. Weightage- Number(3), not null

iii. Create Student_Marks_<employee_id>table -- This table holds the marks obtained by a


student in a particular subject in a semester. The marks are stored as records in this table. For
example if a student S1 scores 50% in networks and 70% in microprocessor in semester 4. The
table will have two records

Reg Number Subject Code Semester Marks


S1 NWS 4 50
S1 MIC 4 70

Any new subject addition does not need a change in table design all it needs a new subject
code and a new row in this table.
METTL_MYSQL _PRACTICE_LAB
a. Reg_Number-Foreignkey (Student_Info)-Varchar
b. Subject_Code-Foreignkey (Subject_Master)-varchar2(10)
c. Semester-Number(3) not null
d. Marks-Number (3) default value 0

iv. Create Student_Result_<employee_id> table -- For storing the student results.


a. Reg_Number-Foreignkey-Varchar
b. Semester-Number(3) Not null
c. GPA-Number (5,3)- Not Null
d. Is_Eligible_Scholarship char(3) Default value is Yes
NOTE: Reg_Number and Semester Number should be composite primary keys.

Problem # 2 Working with constraints:


a) Create a constraint which does not allow repeated entries of subjects having the same Subject
Name.
b) Create a constraint which does not allow two students having the same Contact Number.
c) Create a constraint which does not allow date of birth after date of joining.
d) Create a constraint that does not allow value greater than 100 be inserted into Marks.
e) Create a constraint which mandates GPA values to be less than or equal to 10.
f) Create a constraint which mandates that value for Is_Eligible_Scholarship is either Y or N.

Problem # 3 Loading tables using DML:


a) Load student information into Student_Info table.
b) Load information on subjects into Subject_Master table.
c) Load marks obtained by students in each subject in each semester into Student_Marks table.
d) Load the GPA of the student obtained in each semester into Student_Result table along with the
information whether the student is eligible for scholarship or not.

Student_Info Table_<employee_id>:
Reg_Nu Student_Na Branch Contact_Num Date_of Date_of_ Address Email_id
mber me ber _Birth Joining
MC1013 James MCA 9714589787 12-jan- 08-jul- No james.mc
01 1984 2010 10,South a@yahoo.
Block,Nive com
a
BEC111 Manio ECE 8912457875 23-feb- 25-jun- 8/12,Park manioma
402 1983 2011 View,Sieer @gmail.co
a m
BEEI10 Mike EI 8974567897 10-feb- 25-aug- Cross mike.jame
1204 1983 2010 villa,NY s@ymail.c
om
MB1113 Paulson MBA 8547986123 13-dec- 08-aug- Lake paul.son
05 1984 2010 view,NJ @rediffma
il.com
METTL_MYSQL _PRACTICE_LAB
Subject_Master table_<employee_id>: Green ones are semester 1 and blue ones are semester 2
subjects.
Subject_Cod Subject_Name Weightage
e
EE01DCF DCF 30
EC02MUP Microprocessor 40
MC06DIP Digital Image 30
Processing
MB03MAR Marketing 20
Techniques
EI05IP Instrumentation 40
Precision
CPSC02DS Data Structures 40

Student_Marks_<employee_id>: The marks needs to be loaded as follows.


For students James and Manio records needs to be inserted for semester 1 for the first three subjects in
the subject_master tables.
For the remaining students the marks needs to be inserted for all the subjects for the all the semesters.
Reg Subject Code Semest Marks
Number er
MC1013 EE01DCF 1 75
01
MC1013 EC02MUP 1 65
01
MC1013 MC06DIP 1 70
01
BEC111 EE01DCF 1 55
402
BEC111 EC02MUP 1 80
402
BEC111 MC06DIP 1 60
402

BEEI10 EE01DCF 1 85
1204
BEEI10 EC02MUP 1 78
1204
BEEI10 MC06DIP 1 80
1204
BEEI10 MB03MAR 2 75
1204
BEEI10 EI05IP 2 65
1204
METTL_MYSQL _PRACTICE_LAB
BEEI10 CPSC02DS 2 75
1204
MB1113 EE01DCF 1 65
05
MB1113 EC02MUP 1 68
05
MB1113 MC06DIP 1 63
05
MB1113 MB03MAR 2 85
05
MB1113 EI05IP 2 74
05
MB1113 CPSC02DS 2 62
05

Student_Results_<employee_id>: The 5 student results needs to be calculated for the semester and
stored. For data per se load the table with some arbitrary GPA.
Reg Number Semester CGPA Is_Eligible_Sc
holarship
MC101301 1 7.5 Y
BEC111402 1 7.1 Y

BEEI101204 1 8.3 Y
BEEI101204 2 6.9 N
MB111305 1 6.5 N
MB111305 2 6.8 N

Problem # 4 Perform the following operations:


a) Change the registration number of the James as MC101212.
b) Change the subject code for the subject Data structures as DS0112.
c) Enter details of a new subject into table Subject_Master_<employee_id> without weightage.
What is the output you noticed?
d) Change the contact number of Paulson as 8912457875.
e) Change the marks for James for DCF subject as 120. What is the output you noticed?
f) Change the GPA for Mike as 11. What is the output you noticed?

Objective: Associates would need to retrieve records using DQL statements as mentioned in the
problem statement below.

1. Write a query which fetches and displays all the students who have an email id.

2. Write a query which displays the number of students in each branch.


METTL_MYSQL _PRACTICE_LAB
3. Write a query which displays the marks and register number of all students who has scored
marks > 50% .

4. Write a query which displays the student name, registration number and their GPA in descending
order of GPA.

5. Write a query which displays the student information in ascending order of the students name.

6. Write a query which displays the information of students in ascending order of their age.

7. Write a query which will retrieve the registration number, student name, subject name , semester
# and the respective marks of the subject.

8. Write a query which displays the students registration number, student name, marks and
semester# for all semesters ordered by registration number and semester#.

9. Write a query to display the student name , registration number , subject code, subject name,
marks and semester # of all the students who have scored more than 50%.

NOTE, the subject code and the subject name should be displayed in this particular format Subject
Code- Subject Name.

10. Write a query to display the registration number and GPA of each student in such a way that the
students who are eligible for scholarship are displayed first.

11. Write a query to display the registration number, student name, semester number and GPA of
students such that students with high GPA are displayed on top.

12. Write a query to display registration number, student name, the marks of the students, and the
weighted marks.

Weighted Marks= marks * weightage %/100.

13. Write a query to display all the students whose name starts with M.

14. Writer a query which retrieves student name, registration number and student marks whose
marks is between 60 and 100.

15. Write a query which retrieves student_name, registration number and student marks whose name
does not start with Character J.
METTL_MYSQL _PRACTICE_LAB
16. Write a query which retrieves student name , registration number and marks of those subjects
whose subject code is either EE01DCF or EC02MUP.

Rule: Do not use OR operator

17. Write a query which retrieves all the students whose name ends with on.

18. Write a query which retrieves the student name , registration number and their respective marks
in all semesters whose has an email address.

19. Write a query to display student information such as name, branch in capital letters.

20. Write a query to displays all details in subject_master in small letters.

21. Write a query to display the student name and branch in the following format, <Student
Name>with <registration number> is studying in Branch <branch>.

22. Write two separate queries to display the registration number date of birth of all the students in
the following formats

2011/07/23

July 23, 2011

23. Write a query to display age of each student along with name, contact number and email id.

Age = Number of months between DOB and current date /12.

24. Write a query to display the registration number, student name and average marks secured by
students in each semester.

25. Pick the maximum mark from the students_marks and display the student registration number
and name of those students who have secured the maximum mark.

Rule: Use sub query.

26. Pick the maximum marks secured in the subject EI05IP and display the student name and
registration number of the student who has secured it.
METTL_MYSQL _PRACTICE_LAB
Rule: Use sub query.

27. Write a query to display total number of candidates eligible for scholarship.

28. Write a query to display the details of students who have secured maximum GPA in each
semester. Hint: Use GROUPBY

29. Write a query to display the student name, registration number and GPA who are eligible for
scholarship.

30. Write a query to display the average GPA for each semester. Display the semester number and
the average.

Hint: Average = Total GPA of all students in a semester/total number of students in a semester

Rule: Use AVG function

31. Create a view STUDENT_GPA_<employee_id> which has the following details student name,
registration number, semester number and GPA.

32. From the view STUDENT_GPA _<employee_id> display student name, registration number,
semester number and GPA, whose GPA is greater than 5.

33. Create a view STUDENT_AVERAGE_GPA_<employee_id> which has the following details.


Student name, registration number and average GPA he has scored across semesters.

34. From the view STUDENT_AVERAGE_GPA_<employee_id> diplay Student name, registration


number and average GPA whose average GPA is greater than 7.

35. Write a query which will display all the student records , if the student email id is null it should be
displayed as no valid email address.

36. Write a query which will display the student name, branch,registration number , semester number
and result.Display the full name of EEE as well as ECE branch as mentioned below,

If EEE then Electrical and Electronic Engineering

If ECE then Electronics and Communication Engineering.

Note: CASE Syntax in MYSQL(if else): VERY IMP


METTL_MYSQL _PRACTICE_LAB
CASE case_value
WHEN when_value THEN statement_list
[WHEN when_value THEN statement_list] ...
[ELSE statement_list]
END CASE

Table: employeeDetails

SELECT daysName, CASE daysName

WHEN "Sunday" THEN "Holiday"

WHEN "Monday" THEN "Working Day"

WHEN "Tuesday" THEN "Working Day"

WHEN "Wednesday" THEN "Working Day"

WHEN "Thrusday" THEN "Working Day"

WHEN "Friday" THEN "Working Day"

WHEN "Saturday" THEN "Holiday"

ELSE "Illegal Argument"

END AS "Status"

from employeeDetails;

OUTPUT:
METTL_MYSQL _PRACTICE_LAB

You might also like