Databases and SQL for beginners: from spreadsheets to tables
When a spreadsheet stops being enough, what a relational database is, the five SQL commands you'll use most, and how to choose between SQLite, MySQL and PostgreSQL.
Spreadsheets are great until several people edit the same file, rows reach the hundreds of thousands, or the same customer appears in five places with five spellings. That's when a database helps.
What is a relational database?
A relational database stores data in tables (like sheets) with fixed columns. Each row has a unique primary key, and tables link to each other through keys instead of copying data. For example, an orders table stores a customer_id rather than the customer's full details.
Five SQL commands you'll use most
-- 1. Read data
SELECT name, city FROM customers WHERE city = 'Hyderabad';
-- 2. Summarise
SELECT city, COUNT(*) AS customers FROM customers GROUP BY city;
-- 3. Combine tables
SELECT c.name, o.amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id;
-- 4. Add data
INSERT INTO customers (name, city) VALUES ('Asha Rao', 'Pune');
-- 5. Change data (always with a WHERE!)
UPDATE customers SET city = 'Mumbai' WHERE customer_id = 42;
Which database should you start with?
| Database | Best for |
|---|---|
| SQLite | Learning, small apps and local analysis. It is a single file with no server needed, and it is built into Python. |
| MySQL / MariaDB | Websites and web apps. Usually available on shared hosting (including cPanel hosts). |
| PostgreSQL | Feature-rich, reliable choice for growing business applications and analytics. |
Good habits
- Back up regularly and test that backups restore.
- Give each person or app only the access it needs.
- Never build SQL by pasting user input into strings. Use parameters to prevent SQL injection.
AI shortcut: "My table
orders has columns order_id, customer_id, order_date, amount. Write a SQL query for total sales per month in 2026, and explain it line by line."
Join the discussion
Have a question or a tip to add? Comments are reviewed before they're published.