0% found this document useful (0 votes)
2 views5 pages

Intro To DBS Assignment No2

The document outlines an assignment for a student named Abdul Rahman regarding SQL operations in MySQL Workbench, specifically focusing on creating a database for online courses. It includes tasks for retrieving, inserting, updating, and deleting data related to courses, instructors, and sessions, along with specific SQL statements for each scenario. Additionally, the assignment requires generating an ERD and attaching it to the solution file.

Uploaded by

gooogly755
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 (0 votes)
2 views5 pages

Intro To DBS Assignment No2

The document outlines an assignment for a student named Abdul Rahman regarding SQL operations in MySQL Workbench, specifically focusing on creating a database for online courses. It includes tasks for retrieving, inserting, updating, and deleting data related to courses, instructors, and sessions, along with specific SQL statements for each scenario. Additionally, the assignment requires generating an ERD and attaching it to the solution file.

Uploaded by

gooogly755
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/ 5

Intro to DBS Assignment no: 2

Student Name : Abdul Rahman Date : 06/05/2025

Student Id: 20231-35231 Submitted to : Miss Noor Ul Huda

1. First, execute the SQL create and insert statements on MySQL Workbench.

Note: Create a Database with the name Online_Courses_DB

2. After creating the database structure and tables, generate ERD and attach it to your
solution file.

Q1. Write SQL statements for the following scenarios:

1. Retrieving Data
Scenario A: Retrieve all courses offered by HarvardX.
Scenario B: Retrieve the names of instructors teaching the course "Introduction to
Computer Science"
Scenario C: List courses along with the number of participants for each session in
2013
Scenario D: Get the average percentage of students who earned certificates across
all course sessions for "MITx"
2. Inserting Data
Scenario A: Insert a new course offered by "MITx"
Scenario B: Add a new instructor and assign them to a course ("Introduction to
Algorithms")
Scenario C: Add a new session for an existing course
3. Updating Data
Scenario A: Update the course title for course 6.002x to “Advanced Circuits and
Electronics”
Scenario B: Increase the number of participants in a specific session by 200
4. Deleting Data
Scenario A: Delete a course and its associated sessions
Scenario B: Remove an instructor from teaching a specific course
Scenario C: Delete all course sessions for courses in a given year (e.g., 2012)
Scenario D: Remove an instructor who no longer teaches any courses

-- Q.no.1
-- Task 1 Retrieving data :

SELECT c.course_id, c.course_number, c.course_title

FROM Courses c

JOIN Institutions i ON c.institution_id = i.institution_id

WHERE i.institution_name = 'HarvardX';

SELECT DISTINCT ins.instructor_name

FROM Instructors ins

JOIN Course_Instructors ci ON ins.instructor_id = ci.instructor_id

JOIN Courses c ON ci.course_id = c.course_id

WHERE c.course_title = 'Introduction to Computer Science';

SELECT c.course_title, cs.session_id, cs.participants

FROM Courses c

JOIN Course_Sessions cs ON c.course_id = cs.course_id

WHERE cs.year = 2; -- 2 corresponds to 2013 in your data

SELECT AVG(cs.percent_certified) AS avg_certification_rate

FROM Course_Sessions cs

JOIN Courses c ON cs.course_id = c.course_id

JOIN Institutions i ON c.institution_id = i.institution_id

WHERE i.institution_name = 'MITx';

-- Task 2 Inserting Data :

INSERT INTO Courses (course_number, course_title, course_subject, institution_id)

VALUES ('6.046x', 'Introduction to Algorithms', 'Computer Science', 1);


-- Add the new instructor

INSERT INTO Instructors (instructor_name)

VALUES ('Charles Leiserson');

INSERT INTO Course_Instructors (course_id, instructor_id)

VALUES (16, LAST_INSERT_ID());

INSERT INTO Course_Sessions (

course_id, launch_date, year, honor_code_certificates, participants,

audited, certified, percent_certified, percent_played_video, percent_posted_in_forum,

percent_grade_higher_than_zero, total_course_hours, median_hours_for_certification,

median_age, percent_male, percent_female, percent_bachelors_degree_or_higher

VALUES (

1, '2024-09-01', 3, 0, 15000, 3000, 300, 2.00, 70.00, 5.00,

15.00, 300.00, 60.00, 26.5, 85.0, 15.0, 65.0

);

-- Task 3 : Updating Data

UPDATE Courses

SET course_title = 'Advanced Circuits and Electronics'

WHERE course_number = '6.002x';

UPDATE Course_Sessions

SET participants = participants + 200


WHERE session_id = 1;

-- Task 4 : Deleting Data

DELETE FROM Course_Sessions WHERE course_id = 16;

DELETE FROM Course_Instructors WHERE course_id = 16;

DELETE FROM Courses WHERE course_id = 16;

DELETE FROM Course_Instructors

WHERE course_id = 2 AND instructor_id = 3;

DELETE FROM Course_Sessions

WHERE year = 1;

DELETE FROM Instructors

WHERE instructor_id NOT IN (

SELECT DISTINCT instructor_id FROM Course_Instructors

);

You might also like