Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials Computer Science Relational Databases
Computer Science Beginner FREE

Relational Databases

Lesson 1 of 17 Beginner Interactive

Relational databases organize data into tables with rows and columns, linked by keys.

Syntax

COMPUTER-SCIENCE
CREATE TABLE users (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(100) UNIQUE
);

CREATE TABLE orders (
    id INT PRIMARY KEY,
    user_id INT,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
SQL JOIN Types
SQL
-- INNER JOIN
SELECT users.name, orders.amount
FROM users
INNER JOIN orders ON users.id = orders.user_id;

-- LEFT JOIN (all users, even without orders)
SELECT users.name, COALESCE(SUM(orders.amount), 0) AS total
FROM users
LEFT JOIN orders ON users.id = orders.user_id
GROUP BY users.name;

-- Subquery
SELECT name FROM users
WHERE id IN (SELECT user_id FROM orders WHERE amount > 100);

Practice

1
Exercise

What is a foreign key?

Answer
A column in one table that references the primary key of another table, creating a relationship.

Quick Quiz

1

What does SQL stand for?

SQL stands for Structured Query Language.

Interview Questions

Atomicity, Consistency, Isolation, Durability — properties that guarantee reliable database transactions.