SQL: Structured Query Language

Let’s start with Basic SQL (Structured Query Language), the language used to work with relational databases.


1. Basic concepts

  • A database is a collection of tables.
  • A table is like an Excel sheet: it has columns (fields) and rows (records).
  • SQL is used to create, query, insert, update and delete data.

Example of a Clients table:

ID_ClientNameCityAge
1Anna PuigBarcelona28
2Marc SoléGirona35
3Laia RiusTarragona22

2. Basic queries (SELECT)

The most important command is SELECT, which is used to read data:

-- Select all columns
SELECT * FROM Clients;

-- Select only some columns
SELECT Name, City FROM Clients;

-- Filter data (only those from Girona)
SELECT * FROM Clients
WHERE City = 'Girona';

-- Order data by age
SELECT * FROM Clients
ORDER BY Age DESC;   -- DESC = descending

3. Insert data (INSERT)

INSERT INTO Clients (ID_Client, Name, City, Age)
VALUES (4, 'Jordi Pons', 'Lleida', 30);

4. Update data (UPDATE)

UPDATE Clients
SET City = 'Madrid'
WHERE ID_Client = 2;

5. Delete data (DELETE)

DELETE FROM Clients
WHERE ID_Client = 3;

6. Create a table (CREATE TABLE)

CREATE TABLE Clients (
  ID_Client INT PRIMARY KEY,
  Name VARCHAR(50),
  City VARCHAR(50),
  Age INT
);

Ways to practice SQL:

1. Easy and quick option (no heavy install): SQLite + VS Code

  • SQLite is a very lightweight database (just one .db file).

  • You can install in VS Code the SQLite Viewer or SQLTools extension.

  • Perfect to start writing and running queries.

2. Intermediate option: MySQL or PostgreSQL installed on your computer

  • Edit the code in VS Code and run it with a client such as DBeaver or TablePlus.

  • Useful if you want to practice with more real and complex databases.

3. Advanced option: Docker + PostgreSQL/MySQL

  • VS Code connected to the database with extensions.

  • Ideal if later you want to build data or web projects.


Examples to practice