Database Tutorial
Database Tutorial
Ensure the design includes entities such as:- Students- Programs- Courses- Enrolment
Q2.
DDL Questions Section 1:
CREATE Command
Write an SQL query to create a table named `Student` with there levant fields and key constraints.
Write an SQL query to create a `Contact` table to store multiple phone numbers for students. The
table should have the relevant fields and key constraints.
Write an SQL query to create a `Program` table with there levant fields and key constraints.
Ensure the table supports subclasses for Undergraduate, Postgraduate, and Diploma programs.
Write an SQL query to create an `Enrolment` table with there levant fields and key constraints.
Write an SQL query to create a `Mentorship` table to store information about the mentoring
relationships between students. Ensure it captures the recursive relationship constraints.
Write an SQL query to create a backup table named `Student_bkp` with the same structure as the
`Student` table.
Section 2:
ALTER Command
Write an SQL query to add a column named `Email` VARCHAR(100)to the `Student` table.
Write an SQL query to modify the `ProgramName` column in the `Program` table to have a maximum
length of 150 characters.
Write an SQL query to rename the `ContactNumber` column in the `Contact` table to
`PhoneNumber`(VARCHAR(15)).
Write an SQL query to add both a primary key constraint and a foreign key constraint to the `Enrolment`
table:-
Q3.
DML Questions Section 1:
INSERT Command
Write an SQL query to insert a single record into the `Student` table with your Personal Details (your
self).
Write SQL queries to insert 9 more rows of data into the `Student` table.
Ensure:- Students have Sri Lankan names and addresses.-
Include various dates of birth and mentor relationships where applicable.
Write SQL queries to insert 10 rows of data into the `Contact` table for the students.
Ensure:-
Each student has multiple phone numbers, including mobile and landline numbers.
Write SQL queries to insert 7 rows of data into the `Program` table.
Ensure:-
Programs are categorized as Undergraduate, Postgraduate, or Diploma.-
Include realistic program names and durations.
Write SQL queries to insert 10 rows of data into the `Enrolment` table.
Ensure:-
Each enrolment is associated with a specific student and program.-
Include enrolment dates and statuses.
Write SQL queries to insert all rows from the `Student` table into a backup table `Student_bkp` using
`INSERT INTO SELECT`.
Section 2:
UPDATE Command
Write an SQL query to update the `Address` of a specific student by appending "Sri Lanka" to their
existing address.
Write an SQL query to change the `ProgramName` of a specific program to "Advanced Diploma in IT".
Write an SQL query to assign a new mentor to a specific student (update etheir `MentorID`).
Write an SQL query to update the `ContactNumber` of a specific student in the `Contact` table to a new
mobile number(e.g., `+94771234567`).
Section 3:
DELETE Command
Create a backup tables of enrolments (enrolments_bkp)
Write an SQL query to delete all students who are not enrolled in any program.
Section 4:
SELECT Command
Write an SQL query to retrieve all students who are minors(age below18)along with their mentor
details.
Write an SQL query to fetch all programs along with the total number of students enrolled in each
program.
Write an SQL query to retrieve all enrolments fora specific student, sorted by enrolment date in
descending order
. Write an SQL query to fetch the total number of students enrolled in each program, grouped by
`ProgramID`.
Write an SQL query to retrieve the maximum, minimum, and average age of students enrolled in the
university.
Write an SQL query to fetch all students whose names start with the letter "K".
Write an SQL query to count the total number of phone numbers for eachstudent.
Write an SQL query to fetch the details of programs that have students enrolled in the Undergraduate
category only.
Write an SQL query to retrieve the to p3 students with the highest number of enrolments.
Write an SQL query to retrieve all students who are enrolled in programs lasting more than 2 years.