Introduction to Databases

Beginner

⏱️ 10 mins read

What You'll Learn

A database is an organized collection of structured data stored electronically. Relational databases (RDBMS) store data in tables — grids of rows (records) and columns (fields). Tables are linked via Foreign Keys. A Primary Key uniquely identifies each row and cannot be NULL or duplicate. Popular RDBMS: MySQL, PostgreSQL, SQL Server, SQLite.

Syntax

-- Conceptual: no syntax yet
-- Table: Employees
-- ID (PK) | Name      | Department | Salary
-- 1       | Alice     | Eng        | 90000
-- 2       | Bob       | Sales      | 70000

Example

-- Primary Key: uniquely identifies a row
CREATE TABLE employees (
  id         INT PRIMARY KEY,
  name       VARCHAR(100),
  department VARCHAR(50),
  salary     DECIMAL(10,2)
);

Common Mistakes

Confusing a Database with a Spreadsheet. Spreadsheets are for individuals; Databases handle millions of rows, multiple concurrent users, and enforce data rules (constraints, foreign keys).

Interview Tips

Always mention ACID properties when discussing why relational DBs are used. Explain that Primary Keys enable fast lookups via indexes. Be ready to design a simple schema on a whiteboard.

Practice

Design a schema for an e-commerce site. What tables would you create? Which columns would be Primary Keys? Which would be Foreign Keys?