Hello Dev Community! π
Today I want to share my hands-on practice with SQL using Oracle Live SQL. I created a simple Students database schema and explored various SQL commands to strengthen my database skills. π§βπ»
π Step 1: Creating the Students Table
I started by creating a table called Students with important constraints:
CREATE TABLE Students (
StudentID NUMBER PRIMARY KEY,
Name VARCHAR2(50) NOT NULL,
Dept VARCHAR2(30),
DOB DATE,
Email VARCHAR2(50) UNIQUE
);
π Key Points:
PRIMARY KEY ensures each student has a unique ID.
NOT NULL prevents empty names.
UNIQUE on Email avoids duplicates.
π Step 2: Adding a Phone Number Column
Later, I altered the table to include a PhoneNo column that can store 10-digit numbers:
ALTER TABLE Students
ADD PhoneNo NUMBER(10);
This way, each student record can also include a contact number.
β Step 3: Inserting Data
I inserted sample records into the table, making sure each student belongs to a different department:
INSERT INTO Students (StudentID, Name, Dept, DOB, Email)
VALUES (1, 'Arjun Kumar', 'Computer Science', TO_DATE('2003-05-15', 'YYYY-MM-DD'), 'arjun.kumar@example.com');
INSERT INTO Students (StudentID, Name, Dept, DOB, Email)
VALUES (2, 'Meera Sharma', 'Electronics', TO_DATE('2002-11-20', 'YYYY-MM-DD'), 'meera.sharma@example.com');
INSERT INTO Students (StudentID, Name, Dept, DOB, Email)
VALUES (3, 'Rahul Singh', 'Mechanical', TO_DATE('2004-02-10', 'YYYY-MM-DD'), 'rahul.singh@example.com');
π Step 4: Playing with Queries
I experimented with some interesting queries:
β Display names in UPPERCASE & email length
SELECT
UPPER(Name) AS StudentName,
LENGTH(Email) AS EmailLength
FROM Students;
β Show each department with student count (only if more than 2 students)
SELECT Dept, COUNT() AS StudentCount
FROM Students
GROUP BY Dept
HAVING COUNT() > 2;
π― Key Learnings
How to create and alter tables with constraints
Using aggregate functions with GROUP BY and HAVING
Applying string functions like UPPER() and LENGTH()
Writing meaningful queries to analyze data
π Final Thoughts
This small project was a great way to solidify my SQL fundamentals. Practicing on Oracle Live SQL helped me understand how constraints, functions, and queries work in real scenarios.
π‘ Next, I plan to extend this schema by adding a Courses table and explore JOIN operations.
π What do you think about this simple schema?
Would love to hear your suggestions and improvements!
SQL #Oracle #Database #Learning #DevCommunity #100DaysOfCode
Would you like me to also add an ER diagram illustration for the blog (like Students table structure) so the post looks more visual on dev.to?
Top comments (0)