Skip to main content

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.

How a relational database is organised

Each inside the previous: Database contains Table contains Row contains Value

  • A column is one attribute that every record has, such as name or city. 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:

idnamecityyearmarksemail
1Asha MenonKochi288asha@example.com
2Ravi KumarChennai372ravi@example.com
3Meera NairKochi195meera@example.com
4Arjun DasBengaluru264arjun@example.com
5Priya ShahMumbai381priya@example.com
6Kiran RaoBengaluru177(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

TypeStoresExample
INTEGERWhole numbersyear, marks
NUMERIC(10, 2)Exact decimals, ideal for moneyfee = 12500.00
VARCHAR(n)Text up to n charactersname VARCHAR(100)
TEXTText of any lengthA long description
BOOLEANTRUE or FALSEis_active
DATEA calendar date2026-11-16
TIMESTAMPA date and time2026-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:

SQL
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 NULL means the column must have a value.
  • CHECK (...) rejects values that fail the condition, such as year = 9.
  • UNIQUE means no two rows may share the same value.
  • PRIMARY KEY is covered in the next lesson.

Adding rows

SQL
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 NULL

Text 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

  1. 1.Which data type is best for storing a course fee such as 12500.50?
  2. 2.What does the NOT NULL constraint do?
  3. 3.How is the text Kochi written as a value in SQL?
0 of 3 answered

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.