$RAXA9RO
$RAXA9RO
INDEX
EXERCISE 1: MySQL Company Database I....................................................................................................1
EXERCISE 6: Triggers....................................................................................................................................35
EXERCISE 7: MongoDB.................................................................................................................................39
EXERCISE 1
Date: 10/02/2025
DDL COMMANDS
DML COMMANDS
Table structure of
locations:-
Table: countries
Table: locations
Table: jobs
Table: dependents
Table: employees
Result: -
Queries are executed and output is verified.
4) Hire date of employees with last name 5) Employees who are shipping clerk
“Grant” or “Whalen”
EXERCISE 2
Date: 25/02/2025
SQL QUERIES: -
1) Write a query to display all the
countries.
select country_name as Countries from
countries;
3) Write a query to display the data of employee whose last name is “Fay”.
select * from employees where last_name="Fay";
4) Write a query to find the hire date for employees whose last name is
“Grant” or “Whalen”.
select hire_date from employees where last_name in ("Grant","Whalen");
6) Write a query to get all the employees who work for department 8.
select concat(first_name," ",last_name) as Employee_Name, department_id from
employees where department_id="8";
8) Write a query to display all the employees whose last name starts with “K”.
select concat(first_name," ",last_name) as Employee_Name from employees where
last_name like "K%";
9) Display name of the employees whose hire dates are between 1995 and 1997.
select concat(first_name," ",last_name) as Employee_Name, hire_date from employees
where year(hire_date) between 1995 and 1997;
10) Write a query to display jobs where the maximum salary is less than 5000.
select job_title from jobs where max_salary<=5000;
8) Employees with last name starting 9) Employees whose hire dates are
with K” between 1995 and 1997.
Result: -
Queries are executed and output is verified.
ER Diagram:
EXERCISE 3: Join
Date: 25/02/2025
A UNIVERSITY database for maintaining information concerning students, courses,
and grades in a university environment is given below.
The STUDENT file stores data on each student, the COURSE file stores data on
each course, the SECTION file stores data in each section of a course, the
GRADE_REPORT file stores the grades that students receive in the various section
they have completed, and the PREREQUISITE files stores the prerequisites of each
course.
SQL QUERIES: -
1) Write appropriate MYQL DDL statements to define UNIVERSITY database.
- Create Database
create database UNIVERSITY;
use UNIVERSITY;
- Create Table: STUDENT
create table STUDENT (Name varchar(10), Student_number int(2) primary key, Class int(2),
Major varchar(20));
- Create Table: COURSE
create table COURSE (Course_name varchar(30),Course_number varchar(20) primary key,
Credit_hours int(2), Department varchar(15));
Table: COURSE
3) All Courses and grades of Smith 4) Names and grades of students who took
‘Database’ course offered in fall 2008.
4) List the names of students who took the section of ‘Database’ course offered in
fall 2008 and their grades in that section.
select s.Name,g.Grade from STUDENT s join GRADE_REPORT g on s.Student_number =
g.Student_number inner join SECTION se on g.Section_identifier= se.Section_identifier
inner join COURSE c on se.Course_number=c.Course_number where c.Course_name=
"Database" and se.Semester="Fall" and se.Year=08 ;
6) Create a view to retrieve the names of all senior students majoring in ‘CS’
(computer science).
create view seniors as select * from STUDENT where class=2;
select Name from seniors;
7) Retrieve the names of all courses taught by Professor King in 2007 and 2008.
select c.Course_name from COURSE c join SECTION s on c.Course_number =
s.Course_number where s.Instructor="King";
8) For each section taught by Professor King, retrieve the course number,
semester, year, and number of students who tool the section.
select s.Course_number,s.Semester,s.Year,count(g.Student_number) as No_of_students from
SECTION s join GRADE_REPORT g on s.Section_identifier=g.Section_identifier where
s.Instructor="King" group by g.Section_identifier;
9) Retrieve the name and transcript of each senior student (Class=2) majoring in
CS. A transcript includes course name, course number, credit hours, semester,
year and grade for each course completed by the student.
select s.Name,c.Course_name,c.Course_number,se.Semester,se.Year,g.Grade from student s
join grade_report g on s.Student_number = g.Student_number join section se on
g.Section_identifier = se.Section_identifier join course c on se.Course_number =
c.Course_number where s.Class=2 and s.Major="CS";
Result: -
Queries are executed and output is verified.
1) Even or Odd
2) Grade
EXERCISE 4: PLSQL
Date: 11/03/2024
PLSQL
Create PLSQL procedures and write appropriate SQL queries to call the procedures.
SQL Query
call even_odd(7);
then
set des="Grade is C";
elseif g > 60
then
set des="Grade is D";
4) WeekDay
else
set des="Grade is E";
end if;
select g as Marks,des as Grade;
END
SQL Query
call grade(87);
SQL Query
call pos_neg_zero (-7);
set dat=Weekday(d);
select d as Date, dat as WeekDay;
END
SQL Query
call day("2024-3-16");
5) Factorial
SQL Query
call fact(7);
Result: -
Procedure and queries are executed and output is verified.
Inserted Values
Invalid Values
Result: -
Procedure and queries are executed and output is verified.
Table: Product
Table: Product
EXERCISE 6: Triggers
Date: 02/04/2024
Triggers
Create three tables named:
Product (PdtId, Pname, Price, Qtyinstock)
Sale(saleId,Deliveryaddress)
Saleitem(saleId,PdtId,Qty)
Create a trigger called updateAvailabeQuantity that updates the quantity in stock in
the product table, for every product sold. The trigger should be executed after each
insert operation on the Saleitem table: for the product with given PtdId(the one
inserted into saleitem), update the available quantity in Product table to old quantity
minus sold quantity.
CREATE TABLE Saleitem(saleId INT, PdtId INT, Qty INT,FOREIGN KEY (saleId)
REFERENCES Sale(saleId), FOREIGN KEY (PdtId) REFERENCES
Product(PdtId) ,PRIMARY KEY(saleId,PdtId));
Table: Saleitem
Result: -
Triggers and queries are executed and output is verified.
EXERCISE 7: MongoDB
Date: 04/03/2025
MongoDB
Create a database named college and then create a collection named studlist. Insert
values to the collection.
MongoDB QUERIES: -
- Create database and collection:
import pymongo
conn=pymongo.MongoClient("mongodb://localhost:27017/")
db=conn['college']
col=db['studlist']
1) Display name (both fname and lname) and mark of all female students in
MCA.
x=db.studlist.find({"gender":"female","course":"MCA"},{"name":1,"mark":1})
for i in x:
print("\nName: "+i['name']['fname']+" "+i['name']['lname']+"\nMark: ",i['mark'])
2) Display the details of student who secured highest mark in the course MCA.
x=db.studlist.find({"course":"MCA"}).sort("mark",-1).limit(1)
for i in x:
for j in i.keys():
print(j+": ",i[j])
for i in x:
print(i['name']['fname']+" "+i['name']['lname'])
4) Top 3 students in Mechanical Department. 5) Female students with marks more than 90.
5) Display the details of female students [fname, lname, grade, mark, contact]
who achieved a mark more than 90.
x=db.studlist.find({"mark":{"$gt":90},"gender":"female"})
for i in x:
print("\nName: "+i['name']['fname']+" "+i['name']['lname']+ "\n Grade: "+i['grade']+"\
nMarks: ",i['mark'],"\nContact no: ", i['phone']['no'])
6) Display the details of students who secured mark, more than 80 but less than
90.
x=db.studlist.find({"mark":{"$gt":80,"$lt":90}})
for i in x:
print("\nName: "+i['name']['fname']+" "+i['name']['lname']+"\n Grade: "+i['grade']+"\
nMarks: ",i['mark'],"\nContact no: ", i['phone']['no'])
9) Display all students who does not belong to neither Kollam nor
Thiruvananthapuram.
x=db.studlist.find({"address.city":{"$nin":['Kollam',"Thiruvananthapuram"]}})
for i in x:
Result: -
Queries are executed and output is verified.