← Zurück zum Kurs: SQL and databases from scratch

What a relational database is

Video folgt in Kürze

Almost everything you use every day stores information in a database: your bank, the online shop, the social network, the map on your phone. A database is an organized place where data is kept so it can be searched, changed and protected without losing anything. During these 8 weeks you will learn SQL, the language used to talk to most of those databases. You do not need to know how to program: only curiosity and the will to practice.

Tables, rows and columns

A relational database organizes information in tables, similar to the sheets of a spreadsheet. Each table is about one kind of thing: customers, products, orders. Each column is a characteristic of that thing (name, price, date) and has a fixed data type: text, integer, decimal, date. Each row is one concrete record, for example one particular customer. The difference from a spreadsheet is that the database enforces rules: you cannot write text where a number belongs, and you can force certain data not to be missing.

  • Table: a set of data about one topic (for example, customers).
  • Row (record): one concrete element of the table.
  • Column (field): a property with a fixed data type.
  • Primary key: a column that identifies each row uniquely.
  • Relationship: a link between tables through a shared column.

Why it is called relational

The word relational comes from the relationships between tables. Instead of repeating the customer's data in every order, we store the customer once and each order points to them with a number. So if the customer moves to another city, it is fixed in a single place. When we need to see orders and customers together, SQL joins them on the fly. This idea, which we will study in depth in week 4, is the reason relational databases have dominated for more than fifty years.

What SQL is and which engines exist

SQL (Structured Query Language) is the standard language to query and modify relational databases. It is declarative: you do not explain step by step how to get the result, you say which result you want and the engine decides how to compute it. There are many engines: PostgreSQL, MySQL, SQLite, SQL Server, Oracle. All of them understand a common core of SQL, but each adds variants (dialects). In this course we use PostgreSQL 17, a free, very complete and widely used engine; when something important differs in MySQL or SQLite, we will tell you.

sql
-- A query that does not need any table
SELECT 1 + 1 AS result;

-- Text and the current date
SELECT 'Hello, SQL!' AS greeting, CURRENT_DATE AS today;

SELECT means give me. Then comes what we want to see, and AS gives the result column a name (an alias). The final semicolon marks the end of the statement. Comments start with two dashes and the engine ignores them. Notice that SELECT needs no table to compute a sum or show a text: it is handy for trying ideas quickly.

The shop we will use all course long

We will always work on the same database: a small computer and stationery shop. It has four tables connected to each other. Knowing it well lets you focus on SQL and not on understanding new data every week. In the next lesson we will install it.

  • customers: who buys (name, email, city, signup date).
  • products: what is sold (name, category, price, stock).
  • orders: each order (customer, date, status).
  • order_items: the lines of each order (product, quantity, unit price).
sql
-- Which server version am I talking to? (PostgreSQL)
SELECT version();

-- Other engines: SELECT sqlite_version(); in SQLite, SELECT VERSION(); in MySQL

✎ Meine Notizen

Nur in diesem Browser gespeichert. Melde dich an, um es im Konto zu behalten.0/5000 Zeichen

Weiter →