DEV Community

Cover image for SQL
BHARANIKA D 24CB005
BHARANIKA D 24CB005

Posted on

SQL

πŸš€ SQL Lab Experiments with Oracle LiveSQL

Hi everyone πŸ‘‹,

I worked on my SQL lab using Oracle LiveSQL. Below are the codes I practiced, step by step – from table creation to queries.

πŸ”Ή Step 1 – Create Tables
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
StudentName VARCHAR(100),
Dept VARCHAR(50),
Email VARCHAR(100)
);

CREATE TABLE Courses (
CourseID INT PRIMARY KEY,
CourseName VARCHAR(100),
Credits INT
);

CREATE TABLE Enrollments (
EnrollID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
Grade CHAR(2),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);

πŸ”Ή Step 2 – Insert Data
INSERT INTO Students (StudentID, StudentName, Dept, Email)
VALUES (3, 'Rahul Verma', 'CSE', 'rahul@college.com');

INSERT INTO Courses (CourseID, CourseName, Credits)
VALUES (103, 'Networks', 3);

INSERT INTO Enrollments (EnrollID, StudentID, CourseID, Grade)
VALUES (3, 3, 103, 'A');

πŸ”Ή Step 3 – Queries

  1. Select all students SELECT * FROM Students;

  1. Select all courses
    SELECT * FROM Courses;

  2. Select all enrollments
    SELECT * FROM Enrollments;

  1. Join Students & Enrollments
    SELECT S.StudentName, E.Grade
    FROM Students S
    JOIN Enrollments E ON S.StudentID = E.StudentID;

  2. Join Students, Courses & Enrollments
    SELECT S.Name, C.CourseName, E.Grade
    FROM Enrollments E
    JOIN Students S ON E.StudentID = S.StudentID
    JOIN Courses C ON E.CourseID = C.CourseID;

  1. Find students in CSE dept
    SELECT StudentName
    FROM Students
    WHERE Dept = 'CSE';

  2. Count total students
    SELECT COUNT(*) AS TotalStudents
    FROM Students;

  3. Student count by department
    SELECT Dept, COUNT(*) AS StudentCount
    FROM Students
    GROUP BY Dept;

  1. Create a view
    CREATE OR REPLACE VIEW StudentCoursesView AS
    SELECT S.StudentName, C.CourseName, E.Grade
    FROM Enrollments E
    JOIN Students S ON E.StudentID = S.StudentID
    JOIN Courses C ON E.CourseID = C.CourseID;

  2. Stored procedure to update grade
    CREATE OR REPLACE PROCEDURE UpdateGrade (
    p_StudentID IN INT,
    p_CourseID IN INT,
    p_NewGrade IN CHAR
    ) AS
    BEGIN
    UPDATE Enrollments

  • SET Grade = p_NewGrade WHERE StudentID = p_StudentID AND CourseID = p_CourseID; END; /

βœ… Final Output Example

One student: Rahul Verma (CSE)

One course: Networks

Enrollment: Grade A (later updated to B)

πŸ’‘ This was my SQL lab practice using Oracle LiveSQL. Simple, clean, and working!

Top comments (0)