Getting Started with SQL: Building a Student-Course Database in Oracle Live SQL
If you're new to SQL or just exploring Oracle Live SQL, this post walks you through creating a simple relational database with students, courses, and instructors. We'll cover table creation, relationships, and basic queries—all in a hands-on way.
Step 1: Create Your Tables
Start by defining the core entities: Students, Courses, and Enrollments.
sql
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT
);
CREATE TABLE Courses (
CourseID INT PRIMARY KEY,
CourseName VARCHAR(100)
);
CREATE TABLE Enrollments (
EnrollmentID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
Step 2: Add Instructors (Optional but Useful)
To make it more realistic, let’s add an Instructors table and link it to Courses.
sql
CREATE TABLE Instructors (
InstructorID INT PRIMARY KEY,
InstructorName VARCHAR(100),
Department VARCHAR(50)
);
ALTER TABLE Courses
ADD InstructorID INT;
ALTER TABLE Courses
ADD FOREIGN KEY (InstructorID) REFERENCES Instructors(InstructorID);
Step 3: Insert Sample Data
Populate your tables with sample data to test relationships and queries.
sql
INSERT INTO Students VALUES (501, 'Anjan', 21);
INSERT INTO Courses VALUES (C102, 'Data Mining');
INSERT INTO Enrollments VALUES (1, 501, C102);
Step 4: Run a JOIN Query
Now let’s retrieve meaningful data using JOIN:
sql
SELECT s.StudentID, s.Name, c.CourseName, i.InstructorName
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
JOIN Courses c ON e.CourseID = c.CourseID
JOIN Instructors i ON c.InstructorID = i.InstructorID;
Why This Matters
This mini-project helps you:
Understand foreign key relationships
Practice JOIN operations
Build a foundation for real-world database design
Final Thoughts
Oracle Live SQL is a great playground for learning and experimenting. Whether you're prepping for interviews or building your first app backend, mastering SQL is a skill that pays off.
Top comments (0)