1. Explore the concept of domains in SQL databases and their significance in enforcing data integrity constraints. Describe the steps involved in creating and utilizing domain constraints using the CHECK clause. Provide real-world examples where domain constraints are essential for ensuring the validity and consistency of data. Additionally, discuss the benefits and limitations of using domains compared to traditional CHECK constraints.
2. The following is a Student Table from a database. Write your SQL queries to answer the following questions:
Student_ID
Name
Age
Gender
Grade
1
Sarah
18
Female
90
2
Mohamed
19
Male
85
3
Ahmed
17
Male
77
4
Maryam
18
Female
92
5
Saeed
20
Male
87
Retrieve the Name and Age of students with a Grade greater than 89.
Retrieve the count of Male students in the student table.
Retrieve the average Grade of all students.
Update the Grade of the student with Student_ID 3 to 90.
Delete the record of the student named “Ahmed”.
Insert a new student into the table
3. Consider a database schema with the following tables:
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
GPA FLOAT );
CREATE TABLE Courses (
CourseID INT PRIMARY KEY,
CourseName VARCHAR(50) );
CREATE TABLE Enrollments (
EnrollmentID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
Grade FLOAT,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID));
Solve the following SQL problems by nesting queries.
Write an SQL query to find the names of students who are enrolled in the course ‘Mathematics’ and have a GPA greater than 3.5.
Assuming the same database schema, write an SQL query to find the average GPA of students who have enrolled in the course ‘Physics’.
Extend the previous query to find the average GPA of students who have enrolled in the course ‘Physics’ and whose age is less than 25.