KAHIBARO
Discord Login Register

9.3. Tables, Rows, and Columns

Understanding Tables, Rows, and Columns

In relational databases, almost everything you work with is built on top of tables, rows, and columns. If you understand these three ideas clearly, the rest of SQL and database work becomes much easier.

This chapter will focus only on these basic building blocks, not on advanced topics like keys, relationships, or normalization. Those will come in later chapters.


The Table as a Spreadsheet

A helpful way to think about a table is to imagine a spreadsheet in Excel or Google Sheets.

A table stores multiple records of the same type.

Examples of tables you might have in an application:

Table nameWhat it stores
usersAll user accounts
productsAll products in a store
ordersAll customer orders
blog_postsAll blog articles
commentsAll comments on blog posts

Each table has:

  1. A name (for example users).
  2. A set of columns with defined types and names (for example id, email, created_at).
  3. A set of rows, where each row is one record that fits the column definitions.

Important rule: Every row in a table has exactly the same set of columns, defined once in the table schema. You do not add or remove columns for individual rows.


Columns: Defining the Shape of Your Data

A column represents one attribute or property that every row in the table can have.

For example, in a table of users, typical columns might be:

Column nameExample valuesMeaning
id1, 2, 3Unique identifier for a user
emailalice@example.comUser email address
nameAlice, BobUser's display name
age25, 32, 19User's age in years
created_at2026-08-27 10:15:23When the user was created

Every column has at least:

  1. A name (identifier).
  2. A data type (for example integer, text, date).
  3. Often constraints (for example cannot be null, must be unique).
    Constraints are covered in another chapter, so we will only mention them briefly here.

Think of a column as a named field definition that says: "Every user record will have an email, and it must be text."

Example: Product Table Columns

Let us imagine an products table for an online store.

Possible columns:

Column nameData typeExample valuesDescription
idinteger1, 2, 3Product identifier
nametextT-shirt, LaptopProduct name
pricenumeric19.99, 1200.00Product price
in_stockinteger0, 10, 500How many items are in stock
created_attimestamp2026-08-27 09:00:00When the product was first added
is_activebooleantrue, falseWhether the product is visible for sale

Key idea: A column describes one kind of data, and its data type controls what values are allowed and how they are stored.


Rows: Individual Records

A row is a single record, an instance of the thing the table represents.

In the products table example, each row is one product.

Let us look at some example rows for a users table.

Example: `users` Table Data

Columns:

Rows:

idemailnameagecreated_at
1alice@example.comAlice252026-08-26 09:15:00
2bob@example.comBob322026-08-26 10:30:00
3charlie@example.comCharlie192026-08-27 08:05:00

Each row here is one user account.

Reading a Row as a Record

Row 2:

In programming terms, this row is similar to a dictionary or object:

python
user = {
    "id": 2,
    "email": "bob@example.com",
    "name": "Bob",
    "age": 32,
    "created_at": "2026-08-26 10:30:00"
}

Different languages show this differently, but the idea is always:

Putting It Together: A Table as a Collection of Identical Records

A table is really just:

Visually, you can think of it as:

Column 1Column 2Column 3
Row 1valuevaluevalue
Row 2valuevaluevalue
Row 3valuevaluevalue

In a database:

Examples of Common Tables

Let us go through concrete examples from a typical web application.

Example 1: `users` Table

Use case: Store information about users who sign up.

ColumnData typeExample value
idinteger42
emailtextuser@example.com
passwordtexthashed_password_here
nametextJane Doe
is_activebooleantrue
created_attimestamp2026-08-25 12:00:00

Example rows:

idemailpasswordnameis_activecreated_at
1alice@example.com<hash>Alicetrue2026-08-20 09:00:00
2bob@example.com<hash>Bobfalse2026-08-21 10:15:00

Note: Password hashing and security will be explained in authentication chapters. Here the important part is that each user is one row.

Example 2: `orders` Table

Use case: Store orders placed in an e-commerce system.

ColumnData typeExample value
idinteger101
user_idinteger1
total_amountnumeric59.97
statustextpending, paid
created_attimestamp2026-08-27 11:30:00

Example rows:

iduser_idtotal_amountstatuscreated_at
101159.97pending2026-08-27 11:30:00
102219.99paid2026-08-27 11:45:30

Here again:

Relations between orders.user_id and users.id are part of relationships and foreign keys, which have their own chapters later.


Column Data Types and How They Shape Rows

Columns are not just names, they also have types, which define what kind of data can be stored.

Common types:

TypeExample columnExample value
integerage30
numeric or decimalprice19.99
textname"Alice"
booleanis_activetrue or false
datebirth_date2020-01-01
timestampcreated_at2026-08-27 10:15:00

When you insert a new row:

Example:

Rule: The values in each row must follow the types defined by the columns. The table structure controls what is allowed.


Naming Tables and Columns

Good naming makes your database much easier to understand.

Table naming tips

Column naming tips

Example of consistent naming:

ColumnMeaning
idPrimary identifier
created_atWhen the row was created
updated_atWhen the row was last updated
deleted_atWhen the row was deleted, if any
is_activeWhether the row is currently active

Good names help you, your teammates, and your future self understand your data quickly.


How Tables, Rows, and Columns Map to Code

As a backend developer, you rarely deal with raw rows and columns only, you also map them to code structures.

Mapping to Objects (OOP)

In many languages:

Example in Python style (not using any ORM yet):

python
class User:
    def __init__(self, id, email, name, age, created_at):
        self.id = id
        self.email = email
        self.name = name
        self.age = age
        self.created_at = created_at
# One row in the database:
# id | email              | name  | age | created_at
# 1  | alice@example.com  | Alice | 25  | 2026-08-26 09:15:00
user = User(
    id=1,
    email="alice@example.com",
    name="Alice",
    age=25,
    created_at="2026-08-26 09:15:00"
)

So when you query the users table, each row often becomes a User object in your code.

ORMs (Object Relational Mappers) make this mapping automatic, and you will learn about them in later chapters.


Visualizing Tables in SQL

You will learn SQL commands like CREATE TABLE in the SQL chapters. For now, here is a very simple example to visualize how columns and rows connect to SQL syntax.

Define a table with columns:

sql
CREATE TABLE users (
    id          SERIAL,
    email       TEXT,
    name        TEXT,
    age         INTEGER,
    created_at  TIMESTAMP
);

This defines the table structure:

Insert rows:

sql
INSERT INTO users (email, name, age, created_at)
VALUES
  ('alice@example.com', 'Alice', 25, '2026-08-26 09:15:00'),
  ('bob@example.com', 'Bob', 32, '2026-08-26 10:30:00');

Now the table has two rows, exactly like the earlier diagram.

Selecting rows:

sql
SELECT id, email, name, age, created_at
FROM users;

This returns the rows as a result set, again showing how rows and columns appear.

You will study all these commands in detail in the SQL chapters. Here, the goal is just to connect the mental model:

Common Mistakes When Thinking About Tables

Beginners often run into confusion when designing tables. Here are some issues related directly to tables, rows, and columns.

1. Using One Column for Multiple Values

Bad idea:

Why this is a problem:

Better approach:

2. Too Many Optional Columns

Bad idea:

Often this signals that the design might be improved by splitting into more focused tables.

3. Inconsistent Column Names Across Tables

Example:

This creates confusion and bugs. Try to use the same patterns everywhere.


How Backend Features Reflect in Tables

Different features of your application will often need their own tables.

Here are some examples, focusing on how you would shape the tables with rows and columns.

User Authentication Feature

You might need:

Columns:

ColumnDescription
idUser ID
emailUser email
passwordPassword hash
created_atWhen the account was created

Each login or registration event will add or update rows in this table.

Blog Feature

You might need:

posts table columns:

ColumnDescription
idPost ID
titlePost title
contentPost content
author_idID of the user who wrote it
created_atWhen the post was created

comments table columns:

ColumnDescription
idComment ID
post_idWhich post this comment belongs to
author_idID of the user who wrote the comment
contentComment text
created_atWhen the comment was created

Again, each row is one post or one comment. The connection between post_id, author_id and other tables is part of relationships, covered later.


Summary

Let us recap the most important points about tables, rows, and columns.

  • A table stores many records of the same type.
  • Columns define the structure of the table, including names and data types.
  • Rows are individual records, each with one value per column.
  • All rows in a table share the same set of columns.
  • Good names and correct types make your data easier to work with.

Once you fully understand this model, you will be ready to learn how to:

In the next chapters, you will build on this knowledge to create more complex and powerful database structures.

Views: 8

Comments

Please login to add a comment.

Don't have an account? Register now!