Topic 1 of 52 · Beginner
Databases, Tables & SQL
What a relational database is and how SQL talks to it.
Concept
A relational database stores data in tables. Each table has columns (the fields, each with a type) and rows (one record each). Tables are linked through key values.
SQL (Structured Query Language) is the declarative language used to define, read and change that data. You describe what you want and the database decides how to fetch it.
SQL commands are grouped into DDL (CREATE, ALTER, DROP), DML (INSERT, UPDATE, DELETE), DQL (SELECT), DCL (GRANT, REVOKE) and TCL (COMMIT, ROLLBACK).
Cheat sheet
| Group | Commands | Purpose |
|---|---|---|
| DDL | CREATE, ALTER, DROP, TRUNCATE | Define structure |
| DML | INSERT, UPDATE, DELETE | Change rows |
| DQL | SELECT | Read rows |
| DCL | GRANT, REVOKE | Permissions |
| TCL | COMMIT, ROLLBACK, SAVEPOINT | Transactions |
Code (SQL · MySQL 8)
CREATE DATABASE shop;
USE shop;
SHOW TABLES;
SELECT VERSION();Remember
- A table = columns (schema) + rows (data).
- SQL is declarative: say what, not how.
- Keywords are case-insensitive; string values usually are not.
Interview questions
What is the difference between a DBMS and an RDBMS?
A DBMS stores and manages data in any form. An RDBMS stores data in related tables, enforces keys and constraints, and is queried with SQL.
Name the SQL sub-languages.
DDL, DML, DQL, DCL and TCL — define structure, change data, query data, control access and control transactions.
Lesson test
Take an 8-question test on “Databases, Tables & SQL” — concepts, output prediction, bug spotting and interview questions.