
What is a Table in SQL? | Rows, Columns, and Data Types Explained
Every database is made up of tables, and understanding how they work is the key to mastering SQL.
In this episode, you’ll learn:
- What a table is in SQL
- The difference between rows and columns
- What data types and primary keys are
Let’s dive in!
What is a Table in SQL?
A table in SQL is like a spreadsheet that holds related data. It’s made of:
- Columns (fields or attributes)
- Rows (records or entries)
Simple Definition:
A table stores data in a structured format using rows and columns, where each row is a record and each column holds specific information.
Table Structure Example
Here’s a basic SQL table for storing student data:
Table: students
id | name | course | marks |
1 | Ayesha | Math | 85 |
2 | Ali | Physics | 78 |
3 | Zara | English | 90 |
- Each row represents one student
- Each column holds one type of information (e.g., name, marks)
Rows vs Columns
Element | Description |
Row | A single record (e.g., data of one student) |
Column | A specific attribute (e.g., course, marks) |
Columns define the structure of the table, while rows hold the actual data.
What is a Primary Key?
A Primary Key is a column (or set of columns) that uniquely identifies each row in a table.
In our example:
id INT PRIMARY KEY
The id column is the primary key—it ensures that no two students have the same ID.
Primary keys help:
- Avoid duplicate records
- Improve search speed
- Connect tables through relationships
Common Data Types in SQL Tables
Each column must have a data type—this defines what kind of data can be stored.
Data Type | Used For | Example Values |
INT | Whole numbers | 1, 50, 999 |
VARCHAR(n) | Text (n = max characters) | ‘Ali’, ‘Physics’ |
DATE | Calendar dates | ‘2025-06-30’ |
FLOAT | Decimal numbers | 85.5, 3.14 |
BOOLEAN | True/False values | TRUE, FALSE |
Example:
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50),
course VARCHAR(50),
marks INT
);
This creates a table with 4 columns and specifies the data type of each.
Summary
- Tables store data in rows and columns
- Rows = individual records
- Columns = fields/attributes
- Primary keys uniquely identify each row
- Data types define what kind of info each column can hold
Related:
- Basic SQL Commands | SELECT, INSERT, UPDATE, DELETE
- SQL Basics for Beginners | What is SQL and How It Works