Tables, Rows & Columns
The spreadsheet-like grid that relational databases use to organize data.
What is it?
In a relational database, data lives in tables, and each table looks like a spreadsheet.
- Columns define what information is tracked (like name, email, age) and what type of data each holds. - Rows are individual records: one user, one order, one product.
Every row has a value for every column (or the value is explicitly left empty). A users table with columns id, name, and email might have one row per person who signed up.
Explain like I'm 10
A table is like a class attendance sheet. The columns are the headers across the top (name, student ID, grade), and each row is one student's details filled into those columns.
Examples
A users table
CREATE TABLE users (
id INTEGER,
name TEXT,
email TEXT,
age INTEGER
);This defines the table's shape: every row will have exactly these four columns, each holding a specific kind of value.
What the data actually looks like
id | name | email | age
---+---------+---------------------+----
1 | Amara | amara@example.com | 29
2 | Kenji | kenji@example.com | 34
3 | Priya | priya@example.com | 41Each row is one complete record, lined up under the same columns the table defines.
How it works
When a table is created, its designer picks the columns up front: their names and the type of value each holds (text, integer, date, and so on). After that, every row must fit that shape: one value per column, of the right type.
The database stores rows efficiently on disk and tracks the table's structure (its schema), so it always knows what a row should look like.
Why does it exist?
Giving every row the same shape lets the database reason about data reliably. It always knows that, in users, column 3 is an email and is text, without checking each row. That consistency is what makes fast, predictable queries possible.
When to use it
Use rows and columns when your data is many similar records with the same fields: users, orders, products, log entries. That covers most app data.
When not to use it
If every record has a different, unpredictable set of fields, fixed columns get awkward. A flexible, document-style structure (used by some NoSQL databases) may fit better.
Common mistakes
Mixing up columns and rows. A column is a field shared by all records; a row is one record.
Cramming several unrelated pieces of information into one column instead of giving each its own column.
Assuming every row must look identical in the raw file. The database, not the disk layout, guarantees the row shape.
Practice exercises
- Easy:
Design the columns for a 'books' table in a personal library app. List each column name and the kind of value it holds.
- Medium:
Write three example rows (as a small text table) that fit your 'books' table from the previous exercise.
- Hard:
Explain why one combined 'first name and last name' column is usually worse than two separate columns.
Interview questions
What is the difference between a row and a column in a database table?
A column is one field shared by every record (like email). A row is one record, with a value for each column.
What is a table's schema?
The definition of a table's structure: its columns and the type of data each holds.
Why does every row in a table need to follow the same set of columns?
So the database can read and search every row the same way. That's what makes queries fast and predictable.
What does it mean for a column to hold `NULL`, versus an empty string or the number 0?
NULL means 'no value, unknown, or not applicable'. It's a distinct marker, not an empty string (a real, zero-length text value) or 0 (a real number). Comparisons and calculations treat NULL specially.
Why would you mark a column `NOT NULL`?
So the database rejects any row without a real value there. Every row is guaranteed a value, instead of relying on app code to remember to set it.
If a column has no `NOT NULL` constraint, what happens if an INSERT statement omits it?
The database stores NULL there (or the column's DEFAULT value, if one is defined). No error is raised.
What's the difference between a column's `DEFAULT` value and simply allowing `NULL`?
DEFAULT fills in a real value automatically when none is given, so the column still holds actual data. Allowing NULL lets 'no value' be stored. A column can have neither, either, or (less commonly) both.
Why is storing money as an integer number of cents safer than storing it as a floating-point number of dollars?
Binary floating point can't represent many decimal fractions exactly, so 0.10 + 0.20 may not be exactly 0.30. A whole number of cents has no fraction to round wrongly.
Why does declaring `age` as `INTEGER` instead of `TEXT` matter, beyond just being 'a number'?
The database can then reject non-numeric values, compare and sort numerically instead of character by character, and run math like age + 1 without converting first.
What would go wrong if `age` were stored as `TEXT` instead of `INTEGER`?
Sorting would go character by character, so '9' sorts after '10' and '80' (because '1' comes before '9'). Math like age + 1 wouldn't work reliably without converting first.
What breaks if you cram multiple unrelated pieces of information into one column, like a single text value holding a name, age, and city together?
The database allows it (it's just text), but you can no longer filter, sort, or update one piece on its own. Any query that needs just the age or city must first parse the value apart.
Why is splitting 'first name' and 'last name' into two separate columns usually better than one combined column?
You can sort, search, and format by either part (say, alphabetize by last name) without parsing a combined string. Parsing gets error-prone with multi-part names, prefixes, or suffixes.
Can you add a new column to a table that already has rows in it? What happens to those existing rows for the new column?
Yes, with ALTER TABLE ... ADD COLUMN. Existing rows get NULL (or the column's DEFAULT, if set), since there's no way to know what value they should have had.
Why can't two rows in the same table have a different set of columns?
The schema fixes the columns for the whole table. So the database and every query can rely on a column meaning the same thing in every row.
What's a practical downside of making too many columns on a table nullable 'just in case'?
A NULL becomes ambiguous: 'doesn't apply' or 'nobody set it'? Every query on that column must also handle NULL, adding complexity and bugs across the app.
Give an example where `NULL` in a column is the correct design choice rather than a mistake.
middle_name being NULL for someone with no middle name is fine; it really doesn't apply. Compare an email column that should be NOT NULL and is left empty by accident, which should never be allowed.
Does `WHERE middle_name = ''` match rows where `middle_name` was never set (is `NULL`)?
No. An empty string is a real, zero-length value, not NULL. A NULL row won't match = '', or even = NULL. You need IS NULL.
What does it mean that a table's schema is decided 'up front,' and who typically decides it?
Before any data goes in, the table's designer chooses its columns, names, and types with CREATE TABLE. Every row must then fit that shape, though the schema can still change later with commands like ALTER TABLE.
Why might a flexible, document-style structure fit better than fixed columns for some data?
When each record has a different, unpredictable set of fields, fixed columns lead to lots of unused NULL columns or awkward workarounds. A document model lets each record carry only the fields it needs.
In `CREATE TABLE users (id INTEGER, name TEXT, email TEXT, age INTEGER);`, does the order the columns are declared in matter for storing or querying data?
Not for meaning. Every clause (SELECT, WHERE, SET, and so on) refers to columns by name, so order is mostly about readability. It does matter for INSERT ... VALUES with no column list, which matches values by position.
Are `age = NULL` and `age = 0` the same thing for a row?
No. 0 is a known value: the age really is zero. NULL means the age is unknown or never recorded. Treating them as the same implies you know something you don't.
Why does the database, rather than the raw disk layout, guarantee that every row matches the declared columns?
The engine stores rows however is efficient (variable-length encoding, compression, and so on), so rows don't need identical bytes on disk. The guarantee that every row has a value for every column comes from the schema the engine enforces.
What's the risk of designing a `tags` column that holds a comma-separated list of values?
You can't easily filter for 'rows with tag X' using a simple, index-friendly condition. You can't enforce uniqueness or consistent formatting inside the string. Every query has to split it apart first. Use a related table (or an array/JSON type, if supported) instead.
Why does storing a date in a proper `DATE` or `TIMESTAMP` type matter, rather than storing it as `TEXT`?
A real date type lets the database check that the value is a real calendar date, compare and range-filter dates correctly regardless of format, and use date functions like extracting the year. With TEXT, correctness depends on consistent formatting, and nothing stops an invalid value like '13/45/2026'.
Does every database have a native `BOOLEAN` type?
No. SQLite, for example, has no separate boolean storage type and stores true/false as the integers 1 and 0. It still acts like a boolean in queries, but the storage differs by database.
What is a `CHECK` constraint, and how does it relate to schema design?
A rule on a column or table that the database enforces on every insert or update, beyond type and nullability. For example, CHECK (age >= 0) rejects negative ages. This puts a basic business rule in the schema instead of relying on all app code to validate it.