π College Database Management System β Oracle LiveSQL
This project demonstrates how to design and query a simple College Database using Oracle SQL on LiveSQL
.
We create tables, insert data, apply constraints, run queries, and even build views & stored procedures.
- Schema Design
We define four tables:
Faculty β stores teacher details.
Students β student records with department, DOB, email & phone.
Courses β subject details with credits (1β5 only).
Enrollments β junction table mapping students β courses with grades.
CREATE TABLE Faculty (
FacultyID NUMBER PRIMARY KEY,
FacultyName VARCHAR2(50) NOT NULL,
Dept VARCHAR2(30),
Email VARCHAR2(50) UNIQUE
);
CREATE TABLE Students (
StudentID NUMBER PRIMARY KEY,
Name VARCHAR2(50) NOT NULL,
Dept VARCHAR2(30),
DOB DATE,
Email VARCHAR2(50) UNIQUE,
PhoneNo NUMBER(10)
);
CREATE TABLE Courses (
CourseID NUMBER PRIMARY KEY,
CourseName VARCHAR2(50) NOT NULL,
Credits NUMBER(2) CHECK (Credits BETWEEN 1 AND 5)
);
CREATE TABLE Enrollments (
EnrollID NUMBER PRIMARY KEY,
StudentID NUMBER REFERENCES Students(StudentID),
CourseID NUMBER REFERENCES Courses(CourseID),
Grade CHAR(2)
);
β Here we use PRIMARY KEY, UNIQUE, and CHECK constraints to ensure data integrity.
- Inserting Data
We add sample students, courses, and enrollments.
-- Students
INSERT INTO Students VALUES (1, 'Arjun', 'CSE', DATE '2004-05-15', 'arjun@college.com', 9876543210);
INSERT INTO Students VALUES (2, 'Meera', 'ECE', DATE '2003-11-20', 'meera@college.com', 9876543211);
INSERT INTO Students VALUES (3, 'Rahul', 'Mechanical', DATE '2004-02-10', 'rahul@college.com', 9876543212);
-- Courses
INSERT INTO Courses VALUES (101, 'Database Systems', 4);
INSERT INTO Courses VALUES (102, 'Operating Systems', 3);
INSERT INTO Courses VALUES (103, 'Networks', 2);
-- Enrollments
INSERT INTO Enrollments VALUES (1, 1, 101, 'A');
INSERT INTO Enrollments VALUES (2, 2, 102, 'B');
INSERT INTO Enrollments VALUES (3, 3, 103, 'A');
INSERT INTO Enrollments VALUES (4, 1, 102, 'C');
- Queries
Now, letβs explore the data.
a) String Functions & Aggregates
SELECT UPPER(Name) AS StudentNameUpper, LENGTH(Email) AS EmailLength
FROM Students;
π Converts names to uppercase & shows email length.
SELECT AVG(Credits) AS AvgCredits, (SELECT COUNT(*) FROM Students) AS TotalStudents
FROM Courses;
π Finds average course credits & total number of students.
b) Joins
SELECT s.Name, c.CourseName, e.Grade
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
JOIN Courses c ON e.CourseID = c.CourseID;
π Displays each student with their enrolled course and grade.
c) Group By + Having
SELECT Dept, COUNT() AS StudentCount
FROM Students
GROUP BY Dept
HAVING COUNT() > 0;
π Shows number of students per department (only departments with students).
- Views CREATE OR REPLACE VIEW StudentCoursesView AS SELECT s.Name, c.CourseName, e.Grade FROM Students s JOIN Enrollments e ON s.StudentID = e.StudentID JOIN Courses c ON e.CourseID = c.CourseID;
π A view gives a reusable query showing student β course β grade.
- Stored Procedure CREATE OR REPLACE PROCEDURE UpdateGrade( p_StudentID IN NUMBER, p_CourseID IN NUMBER, p_NewGrade IN CHAR ) AS BEGIN UPDATE Enrollments SET Grade = p_NewGrade WHERE StudentID = p_StudentID AND CourseID = p_CourseID; COMMIT; END;
π Procedure to update a studentβs grade in a course easily.
β Conclusion
This LiveSQL use case covers:
βοΈ Table creation with constraints
βοΈ Data insertion
βοΈ String, aggregate & join queries
βοΈ Group By with Having
βοΈ Views for easy access
βοΈ Stored procedure for updates
A neat mini College Database Management System! π
Top comments (0)