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

Dbms 2 Assesment PDF

The document outlines an experiment for an E-Learning System as part of a DBMS course. It includes the creation of tables for users, courses, and enrollments, along with SQL queries to manage and retrieve data. The objective is to maintain structured user and course management while tracking enrollments effectively.

Uploaded by

Aman kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Dbms 2 Assesment PDF

The document outlines an experiment for an E-Learning System as part of a DBMS course. It includes the creation of tables for users, courses, and enrollments, along with SQL queries to manage and retrieve data. The objective is to maintain structured user and course management while tracking enrollments effectively.

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 2.1
Student Name: SOURABH UID: 23BCS12826
Branch:BE-CSE Section/Group: 807/A
Semester: 4TH Date of Prof :19TH FEB 25
Subject Name:DBMS Subject Code:23CSH-205

1. Aim:
E-Learning System
1. Create the tables:
Users (user_id, name, email, membership_type)
Courses (course_id, title, instructor, category)
Enrollments (enrollment_id, user_id, course_id,
enrollment_date)

2. Insert at least 10 records in each table.


3. Perform SQL queries to:
a) Retrieve users who have enrolled in more than 3 courses.
b) Identify the most popular course category.
c) Find instructors who have at least 2 courses.
d) Retrieve enrollments made in the last 30 days.

2. Objective:

• User Management – Maintain a structured database of users


with their details and membership types.
• Course Management – Store and categorize courses along with
instructor details.
• Enrollment Tracking – Keep track of user enrollments,
including enrollment dates.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

3. DBMS script and output:

Step 1: Creating Tables

CREATE TABLE Users (


user_id NUMBER PRIMARY KEY,
name VARCHAR2(100),
email VARCHAR2(100) UNIQUE,
membership_type VARCHAR2(50)
);

CREATE TABLE Courses (


course_id NUMBER PRIMARY KEY,
title VARCHAR2(200),
instructor VARCHAR2(100),
category VARCHAR2(100)
);

CREATE TABLE Enrollments (


enrollment_id NUMBER PRIMARY KEY,
user_id NUMBER REFERENCES Users(user_id),
course_id NUMBER REFERENCES Courses(course_id),
enrollment_date DATE
);

Step 2: Inserting Sample Records

-- Inserting Users
INSERT INTO Users VALUES (1, 'Alice Johnson', '[email protected]',
'Premium');
INSERT INTO Users VALUES (2, 'Bob Smith', '[email protected]', 'Basic');
INSERT INTO Users VALUES (3, 'Charlie Brown', '[email protected]',
'Premium');
INSERT INTO Users VALUES (4, 'David Lee', '[email protected]', 'Basic');
INSERT INTO Users VALUES (5, 'Emma Watson', '[email protected]',
'Premium');
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

-- Inserting Courses
INSERT INTO Courses VALUES (101, 'Python for Beginners', 'Dr. A',
'Programming');
INSERT INTO Courses VALUES (102, 'Data Structures', 'Dr. B',
'Programming');
INSERT INTO Courses VALUES (103, 'Web Development', 'Dr. A', 'Web
Design');
INSERT INTO Courses VALUES (104, 'Database Systems', 'Dr. C',
'Database');
INSERT INTO Courses VALUES (105, 'Machine Learning', 'Dr. B', 'AI');

-- Inserting Enrollments
INSERT INTO Enrollments VALUES (1, 1, 101, SYSDATE - 10);
INSERT INTO Enrollments VALUES (2, 1, 102, SYSDATE - 20);
INSERT INTO Enrollments VALUES (3, 1, 103, SYSDATE - 30);
INSERT INTO Enrollments VALUES (4, 1, 104, SYSDATE - 40);
INSERT INTO Enrollments VALUES (5, 2, 101, SYSDATE - 15);
INSERT INTO Enrollments VALUES (6, 2, 102, SYSDATE - 25);
INSERT INTO Enrollments VALUES (7, 2, 103, SYSDATE - 35);
INSERT INTO Enrollments VALUES (8, 3, 101, SYSDATE - 5);
INSERT INTO Enrollments VALUES (9, 3, 104, SYSDATE - 12);
INSERT INTO Enrollments VALUES (10, 3, 105, SYSDATE - 22);
INSERT INTO Enrollments VALUES (11, 4, 102, SYSDATE - 28);
INSERT INTO Enrollments VALUES (12, 4, 104, SYSDATE - 33);
INSERT INTO Enrollments VALUES (13, 5, 101, SYSDATE - 7);
INSERT INTO Enrollments VALUES (14, 5, 103, SYSDATE - 18);
INSERT INTO Enrollments VALUES (15, 5, 105, SYSDATE - 26);

Step 3: SQL Queries & Output

(a) Retrieve users who have enrolled in more than 3 courses

SELECT u.user_id, u.name, COUNT(e.course_id) AS course_count


FROM Users u
JOIN Enrollments e ON u.user_id = e.user_id
GROUP BY u.user_id, u.name
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

HAVING COUNT(e.course_id) > 3;

(b) Identify the most popular course category

SELECT c.category, COUNT(e.course_id) AS enrollment_count


FROM Courses c
JOIN Enrollments e ON c.course_id = e.course_id
GROUP BY c.category
ORDER BY COUNT(e.course_id) DESC
FETCH FIRST 1 ROWS ONLY;

(c) Find instructors who have at least 2 courses

SELECT instructor, COUNT(course_id) AS course_count


FROM Courses
GROUP BY instructor
HAVING COUNT(course_id) >= 2;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

(d) Retrieve enrollments made in the last 30 days

SELECT e.enrollment_id, u.name, c.title, e.enrollment_date


FROM Enrollments e
JOIN Users u ON e.user_id = u.user_id
JOIN Courses c ON e.course_id = c.course_id
WHERE e.enrollment_date >= SYSDATE - 30;

You might also like