Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (1 vote)
457 views3 pages

Case Study Mysql

The document describes a database design challenge to store information about university courses, students, and their enrollment in courses. It provides requirements to create tables for courses and students with various fields and constraints. An additional enrollments table is needed to record the relationship between students and courses. The task is to design the database tables following the requirements and constraints, insert sample data, and write queries to update a student's email and retrieve courses based on certain criteria.

Uploaded by

Asad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
457 views3 pages

Case Study Mysql

The document describes a database design challenge to store information about university courses, students, and their enrollment in courses. It provides requirements to create tables for courses and students with various fields and constraints. An additional enrollments table is needed to record the relationship between students and courses. The task is to design the database tables following the requirements and constraints, insert sample data, and write queries to update a student's email and retrieve courses based on certain criteria.

Uploaded by

Asad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Scenario: Database Design Challenge

Background: You are a database administrator working for a fictional university, and the university
wants to manage information about courses, students, and their enrollment in courses. Your task is
to design a database to store this information efficiently.
Requirements:
1. Create two tables: one for storing information about courses and another for storing
information about students.
2. Each table should have its own primary key.
3. Implement necessary constraints to ensure data integrity.
Table 1: Courses
Fields:
 CourseID (Primary Key)
 CourseName
 Instructor
 Credits (should not be negative)
Table 2: Students
Fields:
 StudentID (Primary Key)
 FirstName
 LastName
 Email (should be unique)
 DateOfBirth (should not be in the future)
Additional Constraints:
1. The CourseID in the Courses table should be a 4-digit number.
2. The StudentID in the Students table should be a 5-digit number.
3. The Email in the Students table should follow a standard email format (e.g.,
[email protected]).
4. Ensure that the enrollment of students in courses is recorded in a separate table, called
Enrollments.
5. The Enrollments table should have the following fields:
 EnrollmentID (Primary Key)
 StudentID (Foreign Key referencing Students table)
 CourseID (Foreign Key referencing Courses table)
 EnrollmentDate (should not be in the future)
Case Study Tasks:
1. Update the email address of a student.
2. Retrieve courses with more than 3 credits or instructed by Prof. Smith.
Step 1: Make Tables
-- Create Courses table
CREATE TABLE Courses (
CourseID INT PRIMARY KEY CHECK (CourseID >= 1000 AND CourseID <= 9999),
CourseName VARCHAR(255),
Instructor VARCHAR(255),
Credits INT CHECK (Credits >= 0)
);

-- Create Students table


CREATE TABLE Students (
StudentID INT PRIMARY KEY CHECK (StudentID >= 10000 AND StudentID <= 99999),
FirstName VARCHAR(255),
LastName VARCHAR(255),
Email VARCHAR(255) UNIQUE CHECK (Email LIKE '%@%.%'),
DateOfBirth DATE CHECK (DateOfBirth <= CURRENT_DATE)
);

-- Create Enrollments table


CREATE TABLE Enrollments (
EnrollmentID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
EnrollmentDate DATE CHECK (EnrollmentDate <= CURRENT_DATE),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);

-- Insert data into Courses table


INSERT INTO Courses (CourseID, CourseName, Instructor, Credits) VALUES
(1001, 'Introduction to Computer Science', 'Prof. Smith', 3),
(1002, 'Database Management', 'Prof. Johnson', 4),
(1003, 'Web Development', 'Prof. Williams', 3);

-- Insert data into Students table


INSERT INTO Students (StudentID, FirstName, LastName, Email, DateOfBirth) VALUES
(10000, 'John', 'Doe', '[email protected]', '1998-05-15'),
(10001, 'Jane', 'Smith', '[email protected]', '1997-08-20'),
(10002, 'Bob', 'Johnson', '[email protected]', '1999-02-10');

-- Insert data into Enrollments table


INSERT INTO Enrollments (EnrollmentID, StudentID, CourseID, EnrollmentDate) VALUES
(1, 10000, 1001, '2023-01-15'),
(2, 10001, 1002, '2023-02-20'),
(3, 10002, 1003, '2023-03-10');
-- Query 1: Update the email address of a student
UPDATE Students
SET Email = '[email protected]'
WHERE StudentID = 10000;

-- Query 5: Retrieve courses with more than 3 credits or instructed by Prof. Smith
SELECT CourseName, Credits, Instructor
FROM Courses
WHERE Credits > 3 OR Instructor = 'Prof. Smith'
ORDER BY Credits DESC;

You might also like