Lesson 1 of 8 · 6 min

What is a database?

Tables, rows and columns, primary and foreign keys, relational versus NoSQL databases, and what SQL actually is.

On this page
  1. Tables, rows and columns
  2. Keys
  3. Why not one big table?
  4. Relationships
  5. What is SQL?
  6. Relational or NoSQL?
  7. Check yourself

A database is an organised store of data that many programs and people can read and change at the same time, safely. A database management system (DBMS) is the software that does it: PostgreSQL, MySQL, SQLite, SQL Server, Oracle.

Tables, rows and columns

A relational database keeps data in tables. A table looks like a spreadsheet with strict rules:

customers

id name email city
1 Asha Rao asha@example.com Bengaluru
2 Imran Shaikh imran@example.com Pune
3 Neha Gupta neha@example.com Bengaluru
  • Each column has a name and a data type. city always holds text; id always holds a whole number.
  • Each row is one record: one customer.
  • The order of rows has no meaning. If you want them sorted, you ask for it.

Keys

A primary key uniquely identifies each row. Here it is id. No two customers can share an id, and it can never be empty.

A foreign key is a column that points at a primary key in another table. That is how tables relate:

orders

id customer_id ordered_at status
101 1 2026-11-01 shipped
102 3 2026-11-03 pending
103 1 2026-11-05 pending

orders.customer_id refers to customers.id. Asha (id 1) has two orders. The database can enforce that every customer_id matches a real customer, so you never get an order for someone who doesn't exist.

Why not one big table?

You could store the customer's name and email on every order. But then changing an email means updating every order, and if you miss one, your data disagrees with itself. Splitting data into related tables means each fact is stored once. That idea is called normalisation, and lesson 8 covers it properly.

Relationships

  • One to many: one customer has many orders. The foreign key goes on the "many" side (orders.customer_id).
  • Many to many: an order has many products, and a product appears in many orders. You need a third table in between, order_items, with a foreign key to each.
  • One to one: a user and their profile settings. Less common; often just extra columns.

What is SQL?

SQL (Structured Query Language) is the language you use to talk to a relational database. It is declarative: you describe the result you want, and the database works out how to get it.

SELECT name, email
FROM customers
WHERE city = 'Bengaluru';

That reads almost like English: "give me the name and email of customers in Bengaluru".

SQL has a few groups of commands:

Group Commands Purpose
Data definition CREATE, ALTER, DROP Define tables and their structure
Data query SELECT Read data
Data manipulation INSERT, UPDATE, DELETE Change data
Transactions BEGIN, COMMIT, ROLLBACK Group changes so they all happen or none do

Relational or NoSQL?

NoSQL databases (MongoDB, Redis, DynamoDB, Cassandra) store data as documents, key-value pairs or wide columns. They trade some of the guarantees of relational databases for flexibility or scale in specific situations.

For most applications, a relational database is the right default. It keeps data consistent, it handles relationships well, and SQL is a skill that transfers between every relational database and many analytics tools.

Check yourself

  1. In the orders table above, which column is the foreign key, and what does it point to?
  2. Why is storing the customer's email on every order a bad idea?
  3. A blog has posts and tags. A post has many tags, and a tag is on many posts. What kind of relationship is that, and what extra table does it need?

More from Databases and SQL