MASTER SQL IN 3D SPACE
Step into a spatial universe where Relational Databases are not boring flat tables, but vibrant, interconnected 3D holographic structures powered by Babylon.js WebGL.
The Anatomy of a Table
In SQL, everything begins with relations. A Table is a 3D coordinate grid of memory: Columns define attributes and types, while Rows (Tuples) represent distinct physical data cubes floating in the database cluster.
CREATE TABLE starships (
id INT PRIMARY KEY,
name VARCHAR(50),
class VARCHAR(30),
warp_speed FLOAT,
shields INT
);
SELECT: Spatial Column Laser
SELECT does not copy data; it acts as a spatial prism beam extracting only the requested dimensional axes.
Querying SELECT name, warp_speed isolates specific coordinate planes, collapsing unneeded attributes.
SELECT name, warp_speed, shields
FROM starships;
WHERE: The Laser Scanner
The WHERE clause sweeps through rows like a particle laser. Cubes satisfying the boolean predicate ignite with radiant energy; non-matching cubes dissolve into holographic wireframes.
SELECT * FROM starships
WHERE shields >= 75;
JOIN: Entangled Light Bridges
Relational power unlocks when two distinct 3D tables connect. Foreign keys ignite laser links across space.
Choose a JOIN topology below to witness how INNER, LEFT, RIGHT, and FULL OUTER morph the resulting platform!
SELECT pilots.name, starships.name
FROM pilots
INNER JOIN starships
ON pilots.ship_id = starships.id;
GROUP BY & Aggregation Gravitons
GROUP BY compresses discrete records into dense gravity wells.
Mathematical operators (COUNT, SUM, AVG, MAX) measure energy within each cluster, while HAVING filters entire collapsed pillars.
SELECT class,
COUNT(*) AS ship_count,
AVG(warp_speed) AS avg_speed
FROM starships
GROUP BY class;
B-Tree Indexes: Warping Query Space
Without an index, the database must perform a grueling Full Table Scan $O(N)$ checking every block in storage. A B-Tree Index creates a 3D branching hyperlane, finding the target record in logarithmic $O(\log N)$ leaps!
Mission 1: The High Shield Vanguard
Write a query to retrieve all starships with shields >= 80 and warp_speed > 7.0.
WHERE shields >= 80 AND warp_speed > 7.0