Database Tables
How a Table Organizes Information
Database tables are the basic containers for data in a relational database. A table stores information about one type of thing, such as customers, products or invoices, in a grid of rows and columns.
Each column, sometimes called a field, represents one attribute of that thing. A customers table might have columns for customer ID, name, email address and sign-up date. Each row, also called a record, holds one customer's values for those columns. A table with 5,000 customers has 5,000 rows.
Tables live inside a database, and a database usually contains many tables that relate to one another. A small blog, for example, might have separate tables for posts, comments, users and categories.
Data Types and Empty Values
Every column has a data type that defines what kind of value it can hold. Common types include:
- Integers for whole numbers, such as a quantity or an ID.
- Decimals for exact numbers with fractions, often used for money amounts.
- Text, stored as fixed or variable length, for names and descriptions.
- Dates and times for sign-up dates and timestamps.
- Booleans for true or false flags, such as whether an account is active.
Data types protect data quality. A date column can reject a value such as "next Tuesday", and an integer column refuses letters. Exact type names and sizes differ between database systems, so the same idea may be written differently in each.
A column can also be set to allow or refuse NULL. NULL means that no value was recorded, which is different from zero or an empty string. Together, these column definitions make up the table's part of the database schema.
An Example: Linking an Orders Table to Customers
Imagine an orders table. Each row is one order, and its columns hold the order number, the order date, the total amount and a customer ID. The customer ID does not contain the customer's details. It points to a row in the customers table, which is how the two tables are linked. Linking tables this way depends on keys, explained in primary keys and foreign keys.
Frequently asked questions
What is the difference between a row and a column?
A row is a single record, such as one customer. A column is one attribute across all records, such as every customer's email address. In practice, rows are added and removed as things happen, while columns are defined in advance when the table is designed.
Is a database table the same as a spreadsheet?
They look alike, but a database table has a fixed structure, strict data types and rules that the DBMS enforces. Spreadsheets are flexible and usually edited by hand. Database tables are built to be read and changed by applications and queries, often by many users at once.