What is SQL and What are Databases?
Introduction
Before you write a query, two ideas: what a database is, and what SQL is.
What this page covers:
- what a database is, and why data goes into one
- how a relational database keeps data in tables
- what a database management system does, and which ones are in use
- what SQL is, and the families of its commands
- your first queries, on the course's database
- the rules of SQL's syntax
What is a Database?
A database is an organized collection of data that a computer keeps and hands back on request. Oracle's own definition: "A database is an organized collection of structured information, or data, typically stored electronically in a computer system."
Think of a filing cabinet: drawers hold folders, and labels make them easy to find. A database does the same for data, and lets you search, sort and change it.
Real-World Examples
| Application | What it stores |
|---|---|
| Online shopping | Products, customers, orders, payments |
| Social media | Profiles, posts, comments, likes |
| Banking | Accounts, transactions, customer details |
| Healthcare | Patients, appointments, prescriptions |
| Streaming | Films, shows, preferences, watch history |
Why Use a Database?
Without a database, data lives in spreadsheets or text files. That works while the data is small, and then it starts to go wrong:
- the same data copied into several files
- copies that disagree when one is updated and another is not
- slow searches through large files
- no control over who can see or change what
- hard to share between programs
With a database, you get:
- one place for each piece of data
- rules that keep the data consistent
- fast searches: a database is built to find rows quickly
- access control: who may read or change what
- many users at once

Understanding Relational Databases
The most widely used kind of database is the relational database. DB-Engines, which ranks database systems by how much they are used and talked about, gives relational systems 70% of all its ranking scores in November 2026.
A relational database keeps data in tables of rows and columns.
Tables, Rows, and Columns
Imagine a small customers table:
| customer_id | customer_name | city | |
|---|---|---|---|
| 1 | Alice Johnson | alice@email.com | New York |
| 2 | Bob Smith | bob@email.com | Los Angeles |
| 3 | Carol Davis | carol@email.com | Chicago |
Key terms:
- Table: a collection of related data, like this customers table
- Column (field): one property of every row, like
customer_nameoremail - Row (record): one entry, like Alice Johnson's
- Primary key: a column whose value is different in every row, so it names one row, like
customer_id
The course's own olist_customers_dataset is such a table: its customer_id is different in each of its 99,441 rows.
Why "Relational"?
The name comes from mathematics, not from links between tables. PostgreSQL's documentation calls a relation "a mathematical term for table".
Tables are linked another way: by a column they share. In the imagined data below, customer_id in the orders table points at a row of the customers table:
Customers:
| customer_id | customer_name |
|---|---|
| 1 | Alice Johnson |
| 2 | Bob Smith |
Orders:
| order_id | customer_id | product | amount |
|---|---|---|---|
| 101 | 1 | Laptop | 999.99 |
| 102 | 1 | Mouse | 29.99 |
| 103 | 2 | Keyboard | 79.99 |
Customer 1, Alice, has two orders, and customer 2, Bob, has one. In the course's data, each row of olist_orders_dataset carries the customer_id of one row of olist_customers_dataset.
What is RDBMS?
An RDBMS, a relational database management system, is the software that keeps relational databases and answers SQL. It provides:
- storage and retrieval: it writes data to disk and finds it again
- query processing: it reads SQL and works out how to run it
- transactions: a group of changes happens completely or not at all
- security: who may connect, and what each may do, in systems that have users
- backup and recovery: copies to come back to after a loss
Popular RDBMS Systems
| RDBMS | What it is | Where you meet it |
|---|---|---|
| MySQL | Open source and widely used | Web applications |
| PostgreSQL | Open source, with a large set of features | Applications and analysis |
| SQLite | A library: the whole database is one file, with no server | Phones, computers, programs that carry their data, and this course |
| Microsoft SQL Server | Microsoft's database; on Windows, and on Linux since SQL Server 2017 | Companies built on Microsoft's software |
| Oracle Database | Oracle's database | Large companies |
| MariaDB | Open source, made by the original developers of MySQL | Where MySQL is used |
How Data is Stored
In an RDBMS, data lives in tables, and a database holds many tables. The course's database holds 9, among them olist_customers_dataset, olist_orders_dataset, olist_order_items_dataset and olist_products_dataset; Course Resources lists all of them and draws how they connect.
Each table has a schema: its columns' names, their types and the rules on them.
What is SQL?
SQL (Structured Query Language) is the language of relational databases. Oracle describes it as "a programming language used by nearly all relational databases to query, manipulate, and define data, and to provide access control". You use it to ask a database for data and to tell it to change data.
Key Facts About SQL
- A standard: ISO/IEC 9075, revised from time to time; its latest version is SQL:2023 (Course Resources has more on it).
- Declarative: you say what you want, not how to get it. In SQLite's documentation: "When programming in SQL you tell the system what you want to compute, not how to compute it."
- Keywords in any case:
SELECTandselectare the same keyword.
What Can SQL Do?
| Capability | What it does | An example |
|---|---|---|
| Query data | Find rows in tables | the customers in São Paulo |
| Insert data | Add rows | a new customer |
| Update data | Change rows | a customer's new email |
| Delete data | Remove rows | a customer who left |
| Create structures | Make tables and indexes | a new orders table |
| Manage access | Give and take back permissions | read access for an analyst, in databases with users |
SQL is Declarative
In a programming language you write the steps, here in pseudocode:
Create an empty list
For each customer in customers:
If the customer's city is sao paulo:
Add the customer to the list
Return the list
In SQL you describe the result:
SELECT *
FROM olist_customers_dataset
WHERE customer_city = 'sao paulo'
LIMIT 5;The database works out how to find those rows. In SQLite's words, "The task of figuring out the how is delegated to the query planner".
Categories of SQL Commands
SQL's commands are usually sorted into five families. SQL Commands takes each one in turn; here is the map.
1. DQL: Data Query Language
Reads data.
| Command | Purpose |
|---|---|
SELECT | Fetch rows from one or more tables |
SELECT customer_city, customer_state
FROM olist_customers_dataset
LIMIT 5;2. DML: Data Manipulation Language
Changes the rows of a table.
| Command | Purpose |
|---|---|
INSERT | Add rows |
UPDATE | Change rows |
DELETE | Remove rows |
Each Run starts with a fresh database of your own, so this block makes its small table first, then changes it:
-- each Run starts with a fresh database, so the block makes its table first
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY,
customer_name TEXT,
email TEXT
);
INSERT INTO customers (customer_name, email)
VALUES ('John Doe', 'john@email.com'),
('Ana Lima', 'ana@email.com'),
('Rui Costa', 'rui@email.com');
UPDATE customers SET email = 'newemail@email.com' WHERE customer_id = 1;
DELETE FROM customers WHERE customer_id = 3;
SELECT * FROM customers;It shows 2 rows: customer 1's email has changed, and customer 3 is gone.
3. DDL: Data Definition Language
Defines the tables themselves.
| Command | Purpose |
|---|---|
CREATE | Make a table, an index or a view |
ALTER | Change a table |
DROP | Remove a table, an index or a view |
TRUNCATE | Empty a table, in PostgreSQL, MySQL and SQL Server |
CREATE TABLE products (product_id INTEGER, product_name TEXT, price DECIMAL);
ALTER TABLE products ADD COLUMN stock_quantity INTEGER;
-- the table's columns now
SELECT name, type FROM pragma_table_info('products');The last statement lists the table's columns, and stock_quantity is there after the ALTER. SQLite has no TRUNCATE: it answers near "TRUNCATE": syntax error. There, DELETE FROM products; empties the table, and when the table has no triggers, SQLite erases its content at once instead of visiting each row.
4. DCL: Data Control Language
Controls who may do what.
| Command | Purpose |
|---|---|
GRANT | Give a user a permission |
REVOKE | Take it back |
In PostgreSQL:
GRANT SELECT ON customers TO analyst_user;
REVOKE SELECT ON customers FROM analyst_user;
SQLite has no users, so it has neither command; here it answers near "GRANT": syntax error. Its documentation explains: "Since SQLite reads and writes an ordinary disk file, the only access permissions that can be applied are the normal file access permissions of the underlying operating system."
5. TCL: Transaction Control Language
Groups changes so they happen together or not at all.
| Command | Purpose |
|---|---|
BEGIN | Start a transaction |
COMMIT | Keep its changes |
ROLLBACK | Undo them |
SAVEPOINT | Mark a point to undo back to |
CREATE TABLE accounts (account_id INTEGER PRIMARY KEY, balance INTEGER);
INSERT INTO accounts VALUES (1, 500), (2, 200);
BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;
UPDATE accounts SET balance = balance + 100 WHERE account_id = 2;
COMMIT;
SELECT * FROM accounts;The two updates move 100 from account 1 to account 2, together: account 1 now holds 400 and account 2 holds 300.
Your First SQL Query
The most basic command is SELECT. Its pattern:
SELECT column1, column2
FROM table_name;
SELECTstarts the querycolumn1, column2are the columns you wantFROMnames the tabletable_nameis that table;ends the statement
Select All Columns
An asterisk * means every column:
SELECT * FROM olist_customers_dataset;It asks for all 99,441 rows; the page shows the first 30 and says the result was cut.
Select Specific Columns
Name the columns you want, and only those come back:
SELECT customer_city, customer_state FROM olist_customers_dataset;Practice
Now it's your turn. Press Run Code to run each query on the course's database, then change it and run it again.
Exercise 1: View All Customers
Select all columns from olist_customers_dataset, limited to 10 rows, to see a sample.
-- Select all columns from the customers table
-- Use LIMIT to restrict the number of rows returned
SELECT *
FROM olist_customers_dataset
LIMIT 10;Exercise 2: Select Specific Columns
Now select only the customer_city and customer_state columns.
-- Select only the city and state columns
SELECT customer_city, customer_state
FROM olist_customers_dataset
LIMIT 10;Exercise 3: Explore the Orders Table
Look at another table, olist_orders_dataset.
-- Explore the orders table
SELECT *
FROM olist_orders_dataset
LIMIT 10;SQL Syntax Rules
1. Case
Keywords can be written in any case. These three are the same query:
SELECT customer_city FROM olist_customers_dataset;
select customer_city from olist_customers_dataset;
Select customer_city From olist_customers_dataset;
In SQLite, table and column names are not case-sensitive either. This finds the same table and column, and the page names the column as you wrote it:
SELECT CUSTOMER_CITY FROM OLIST_CUSTOMERS_DATASET LIMIT 3;Other databases differ. PostgreSQL folds a name without quotes to lower case, and takes a name in double quotes exactly as written: CUSTOMERS finds a table named customers, and "Customer_City" finds no column. In MySQL, the operating system plays a part in whether database and table names are case-sensitive, because "databases correspond to directories within the data directory", while column names are "not case-sensitive on any platform".
Good practice: keywords in capitals, names in lower case.
2. Whitespace
SQL ignores extra spaces and line breaks. These two are the same query:
SELECT customer_city,customer_state FROM olist_customers_dataset;
SELECT
customer_city,
customer_state
FROM
olist_customers_dataset;
Good practice: line breaks and indents that show the query's parts.
3. Ending a Statement
A semicolon ; ends a statement. A single SELECT runs without one on this site. Two statements need one between them, and the page shows the rows of the last one:
SELECT customer_city FROM olist_customers_dataset LIMIT 3;
SELECT order_status FROM olist_orders_dataset LIMIT 3;Here the page shows order statuses, not cities.
4. Comments
Two dashes start a comment that runs to the end of the line, and /* and */ wrap a comment over several lines. The database skips both:
-- This is a comment
SELECT customer_city FROM olist_customers_dataset LIMIT 3; -- This also works
/*
This is a
multi-line comment
*/
SELECT customer_state FROM olist_customers_dataset LIMIT 3;5. Text Values
Text goes in single quotes:
SELECT customer_id, customer_city
FROM olist_customers_dataset
WHERE customer_city = 'sao paulo'
LIMIT 3;Double quotes are for names. SQLite bends this rule: a double-quoted word that matches no column is read as text, a behaviour its documentation calls a "misfeature". PostgreSQL reports a missing column instead. Use single quotes for text.
Summary
Key Takeaways
- Database: an organized collection of data that a computer keeps.
- Relational database: data in tables of rows and columns; "relation" is the mathematical word for a table.
- RDBMS: the software that keeps relational databases, such as SQLite, PostgreSQL, MySQL, SQL Server and Oracle.
- SQL: the standard language of relational databases, ISO/IEC 9075.
- The families of SQL commands: DQL (SELECT) reads; DML (INSERT, UPDATE, DELETE) changes rows; DDL (CREATE, ALTER, DROP) defines tables; DCL (GRANT, REVOKE) controls access, and SQLite has none of it; TCL (BEGIN, COMMIT, ROLLBACK) groups changes.
- The basic query:
SELECTthe columns,FROMthe table.
What's Next?
Later lessons build on this: filtering rows with WHERE, sorting with ORDER BY, grouping with GROUP BY, and combining tables with joins.
Additional Resources
- SQLite Documentation: the reference for the engine this course uses
- Part I. Tutorial of PostgreSQL's documentation
Database Used in This Course
The course works on the Brazilian E-Commerce Public Dataset. Course Resources lists its 9 tables, what a row of each one is, and how they connect.