Introduction to SQL · Lesson 1 of 30
What Is SQL? Databases, Tables and Keys
Every app you use stores data somewhere: your bank balance, your orders, your messages, your exam results. Most of that data lives in relational databases, and the language used to work with them is SQL (Structured Query Language, pronounced "S-Q-L" or "sequel"). It's one of the few skills asked for in almost every tech role – developers, data analysts, testers, data engineers and even product managers use it daily.
In this lesson
- What a database and a DBMS are
- Tables, rows and columns
- Primary keys, foreign keys and relationships
- The groups of SQL commands, and popular databases
Database, DBMS and SQL
How the pieces fit
- Your app or yousends SQL: SELECT name FROM customers WHERE city = 'Pune'
- DBMS (MySQL, PostgreSQL, SQL Server…)parses, plans and runs the query safely
- Databasethe stored data – tables on disk, indexes, logs
- A database is an organised collection of data.
- A DBMS (database management system) is the software that stores it and answers requests. A relational DBMS (RDBMS) stores data in related tables.
- SQL is the standard language for asking an RDBMS to read or change data. You describe what you want; the database works out how to get it.
Tables, rows and columns
A table looks like a spreadsheet with strict rules. Each column has a name and a data type; each row is one record.
SELECT customer_id, name, city FROM customers LIMIT 4;
+-------------+------------+-----------+ | customer_id | name | city | +-------------+------------+-----------+ | 1 | Asha Verma | Pune | | 2 | Ravi Kumar | Delhi | | 3 | Meera Nair | Kochi | | 4 | Kiran Rao | Bengaluru | +-------------+------------+-----------+
| Term | Also called | Example |
|---|---|---|
| Table | relation | customers |
| Row | record, tuple | Asha Verma from Pune |
| Column | field, attribute | city |
| Data type | domain | VARCHAR(40), INT, DATE |
Keys and relationships
A primary key uniquely identifies each row – no two customers share a customer_id, and it can't be empty. A foreign key is a column that points to the primary key of another table, linking the tables together.
SELECT order_id, customer_id, order_date, status FROM orders LIMIT 3;
+----------+-------------+------------+-----------+ | order_id | customer_id | order_date | status | +----------+-------------+------------+-----------+ | 101 | 1 | 2025-08-02 | delivered | | 102 | 2 | 2025-08-05 | delivered | | 103 | 1 | 2025-08-19 | delivered | +----------+-------------+------------+-----------+
orders.customer_id is a foreign key: order 101 and order 103 both belong to customer 1, Asha. Instead of copying Asha's name and email into every order, the database stores them once and links to them – that's the core idea of a relational database.
One customer, many orders (a one-to-many relationship)
- customerscustomer_id 1 = Asha Verma (primary key)
- orders101 and 103 have customer_id 1 (foreign key)
- A JOIN brings them together"Asha placed orders 101 and 103" – chapter 5
The SQL command groups
| Group | Purpose | Commands |
|---|---|---|
| DQL – query | read data | SELECT |
| DML – manipulation | change rows | INSERT, UPDATE, DELETE |
| DDL – definition | create and change structure | CREATE, ALTER, DROP, TRUNCATE |
| DCL – control | permissions | GRANT, REVOKE |
| TCL – transactions | group changes safely | COMMIT, ROLLBACK, SAVEPOINT |
Popular databases
SQL is a standard, so what you learn works almost everywhere. Each product adds small differences ("dialects").
| Database | Where you'll meet it |
|---|---|
| MySQL / MariaDB | web apps, WordPress, startups – this course uses MySQL 8 |
| PostgreSQL | modern back-ends, analytics; very standards-compliant |
| SQL Server | enterprises using Microsoft technology |
| Oracle | banks, telecoms, large enterprises |
| SQLite | mobile apps, browsers, small tools – a database in one file |
SQL vs NoSQL
NoSQL databases (MongoDB, Redis, DynamoDB) store documents, key-values or graphs instead of fixed tables. They suit some workloads, but relational databases and SQL remain the default for most business data – and SQL skills transfer to analytics tools like BigQuery, Snowflake and Spark SQL.
Practice
Quick check
What is the difference between a database and a DBMS?
The database is the stored data; the DBMS is the software (like MySQL) that manages it and runs your queries.
Can two rows have the same primary key?
No – a primary key must be unique and not NULL.
What does a foreign key do?
It links a row to a row in another table by referring to that table's primary key, and the database enforces that the referenced row exists.
Which command group does UPDATE belong to?
DML – data manipulation.
Summary
- A relational database stores data in tables of rows and columns; SQL is the language to query and change it.
- Primary keys identify rows; foreign keys link tables into relationships.
- SQL commands group into DQL, DML, DDL, DCL and TCL; the same SQL works across MySQL, PostgreSQL and others.
Finished this lesson?
Mark it complete to track your progress, then carry on with the next lesson.