Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Iqra University Islamabad Campus

Quiz 02 - Solution
Database Management Systems/ Introduction To Database Systems, Spring 2024
Teacher Name: Sadia Zar Class: BS (SE/AI) Date: April 16, 2024, Total Marks: 10
-------------------------------------------------------------------------------------------------------- -----------------------------------------
Instructions: Copied or shown Quizes will be marked zero. Late submissions are not
entertained in any case.

Question 01: Consider the following database schema:

Write the SQL Queries for the following statements:

1. Retrieve the names and ages of all students.

SELECT sname, age


FROM Student;

2. Retrieve the names and ages of students who are older than 25:

SELECT sname, age


FROM Student WHERE age > 25;

3. Retrieve the names and ages of students who are enrolled in a class called 'Physics101'

SELECT Student.sname, Student.age


FROM Student
INNER JOIN Enrollment ON Student.snum = Enrollment.snum
INNER JOIN Course ON Enrollment.cno = Course.cno
WHERE Course.cname = 'Physics101';

4. Retrieve the name and age of students who are at junior level (slevel) and are enrolled in the
department with ID 102

SELECT sname, age


FROM Student
WHERE slevel = 'junior'
AND deptid = 102;

5. Retrieve the names and ages of students who are at least 18 years old and not older than 25

SELECT sname, age


FROM Student
WHERE age >= 18 AND age <= 25;

6. Retrieve the names and ages of students who are not in the sophomore level (slevel !=
'Sophomore')

SELECT sname, age


FROM Student
WHERE slevel != 'Sophomore';

7. Add a new student named "John" with age 20, enrolled in department with ID 101, and at
sophomore level.

INSERT INTO Student (sname, age, deptid, slevel)


VALUES ('John', 20, 101, 'Sophomore');

8. Delete the record of a student with student number 1234.

DELETE FROM Student


WHERE snum = 1234;

9. Drop the table Enrolled.

DROP TABLE Enrolled;

10. Add a new column 'email' to the Student table.

ALTER TABLE Student


ADD email VARCHAR(255);

You might also like