What SQL is and what a database does

Lesson 1 of 10 · 10 min0/3 checked in practice
Objective

By the end of this lesson you can explain what a database and SQL are, and run a statement that shows every row of a table.

Why it matters: Almost every organisation keeps its records (customers, sales, payments, staff) in databases, and SQL is the common language for asking them questions. Analysts, finance teams, product managers and developers all use it daily.

Dataset: Starter shop. Examples run in the editor on the right.

A database is an organised, permanent store of records. Think of the records a small shop keeps: who its customers are, what it sells, and who bought what. On paper that would be three ledgers. In a database it's three tables.

A table looks like a spreadsheet tab: it has named columns across the top (for example customer_name and city) and one row for each record (one row per customer). Unlike a spreadsheet, a database is strict: every column holds one kind of value, every table has a fixed name, and the database keeps the data consistent even when thousands of people use it at once.

The program that stores the tables and answers questions about them is a database management system (DBMS). In SQL Quest you use PostgreSQL, one of the most widely used database systems in the world. It runs right in your browser, on a copy of the data, so you can't break anything.

SQL: the language you ask in

SQL (Structured Query Language, said ess-cue-ell or sequel) is how you talk to a relational database. One complete instruction is a statement. The statements you'll write most often are queries: questions that read data and return an answer, without changing anything.

SQL is declarative: you describe what you want, not how to fetch it. You don't tell PostgreSQL which file to open or how to loop through rows. You say "show me every customer", and the database works out the fastest way to do it.

Here is a complete statement. Run it: it is the classic first look at a table.

ExampleLook at the whole customers table
SELECT *
FROM customers;

PostgreSQL reads the customers table and returns every row and every column. The result has 12 rows (one per customer) and 5 columns. Nothing in the table changes: a query only reads.

Read that statement word by word:

  • SELECT means return some columns.
  • * (asterisk) is shorthand for all of the columns.
  • FROM customers says which table to read.
  • ; ends the statement.

The answer comes back as a result: a temporary table built just for your question. You'll learn to choose specific columns in a later lesson. For now, SELECT * FROM table_name; is your window into any table.

SELECT *
FROM table_name;
Show every column and every row of one table. Replace table_name with a real table, such as products.

The starter database: Corner Market

Your first lessons use Corner Market, a fictional online shop with three small tables you can read in full:

tableone row is…
customersa person registered with the shop
productsan item the shop sells
ordersone order: a customer buying one product

The schema panel next to the editor lists these tables and their columns. Keep it open: professionals look at the schema constantly.

ExampleWhat does the shop sell?
SELECT *
FROM products;

Returns the 10 products with all five of their columns: an id number, the name, the category, the price in SAR and the units in stock. One row per product.

Quick check
Quick check

You run SELECT * FROM orders; twice in a row. What happens to the orders table?

Now practise
3 exercises on real data, checked in your browser (practice).