Lesson 1 of 4 12 min read
Tables, rows, columns and data types
Learn how a relational database organises data into tables and how to choose column data types.
In this lesson you will
- Explain tables, rows and columns using a real example
- Choose suitable SQL data types for common kinds of data
- Create a table with CREATE TABLE and add rows with INSERT
Databases, tables, rows and columns
A relational database stores data in tables. Each table describes one kind of thing, such as students, courses or payments.
Each inside the previous: Database contains Table contains Row contains Value
- A column is one attribute that every record has, such as
nameorcity. Each column has a data type. - A row is one record, such as one student.
Here is a students table we'll use throughout this path:
| id | name | city | year | marks | |
|---|---|---|---|---|---|
| 1 | Asha Menon | Kochi | 2 | 88 | asha@example.com |
| 2 | Ravi Kumar | Chennai | 3 | 72 | ravi@example.com |
| 3 | Meera Nair | Kochi | 1 | 95 | meera@example.com |
| 4 | Arjun Das | Bengaluru | 2 | 64 | arjun@example.com |
| 5 | Priya Shah | Mumbai | 3 | 81 | priya@example.com |
| 6 | Kiran Rao | Bengaluru | 1 | 77 | (NULL) |
Kiran has no email recorded. A missing value in SQL is NULL, which means "unknown". It is different from an empty string or zero.
Common data types
| Type | Stores | Example |
|---|---|---|
INTEGER | Whole numbers | year, marks |
NUMERIC(10, 2) | Exact decimals, ideal for money | fee = 12500.00 |
VARCHAR(n) | Text up to n characters | name VARCHAR(100) |
TEXT | Text of any length | A long description |
BOOLEAN | TRUE or FALSE | is_active |
DATE | A calendar date | 2026-11-16 |
TIMESTAMP | A date and time | 2026-11-16 19:30:00 |
Choosing the right type matters. The database rejects values of the wrong type, sorts and compares correctly (dates sort as dates, not as text), and stores data efficiently.
Creating the table
SQL (Structured Query Language) is the language for working with relational databases. CREATE TABLE defines a table's columns and types:
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name VARCHAR(100) NOT NULL,
city VARCHAR(60) NOT NULL,
year INTEGER NOT NULL CHECK (year BETWEEN 1 AND 4),
marks INTEGER CHECK (marks BETWEEN 0 AND 100),
email VARCHAR(255) UNIQUE
);The extra words are constraints, rules the database enforces on every change:
NOT NULLmeans the column must have a value.CHECK (...)rejects values that fail the condition, such asyear = 9.UNIQUEmeans no two rows may share the same value.PRIMARY KEYis covered in the next lesson.
Adding rows
INSERT INTO students (id, name, city, year, marks, email)
VALUES (1, 'Asha Menon', 'Kochi', 2, 88, 'asha@example.com');
INSERT INTO students (id, name, city, year, marks)
VALUES (6, 'Kiran Rao', 'Bengaluru', 1, 77); -- email is left NULLText values use single quotes in SQL. Keywords such as SELECT are case-insensitive, but writing them in capitals makes queries easier to read. -- starts a comment.
Try it
You can practise without installing anything using an online SQL playground such as DB Fiddle (choose PostgreSQL), or install PostgreSQL locally and use the psql command-line tool.
Hands-on exercise
Design a table named courses with columns for an id, a title, a level (beginner or intermediate), a duration in hours and a fee in rupees. Choose a data type and at least one constraint for each column, write the CREATE TABLE statement, and insert three rows. If you have access to a SQL playground, run it and try inserting a row that breaks one of your constraints.
Knowledge check
3 questions • 70% to pass • Practice only, no certificate
Key concepts
- A table describes one kind of thing; columns are attributes and rows are records.
- Every column has a data type; use NUMERIC for money and DATE or TIMESTAMP for dates.
- Constraints such as NOT NULL, CHECK and UNIQUE make the database reject invalid data.
- NULL means unknown and is not the same as zero or an empty string.
