When learning SQL, the first step is to understand how data is organized inside a database.
The three most important building blocks are:
-
Tables
-
Rows (Records)
-
Columns (Fields)
Letโs break these down with clear examples.
1. ๐น What is a Table?
-
A table is like a container for data.
-
Think of it as an Excel sheet inside a database.
-
Each table stores information about a specific type of data.
๐ Example: An Employees table stores details about employees.
It looks like a grid with rows and columns.
Employees Table (Example):
| EmployeeID | Name | Department | Salary |
|---|---|---|---|
| 101 | John | HR | 50,000 |
| 102 | Alice | IT | 70,000 |
| 103 | David | Finance | 65,000 |
-
Table name: Employees
-
Rows = each employee record
-
Columns = employee details (ID, Name, etc.)
2. ๐น What is a Row (Record)?
-
A row is a single entry in the table.
-
It represents one instance of the data type stored in the table.
-
Each row contains all the column values for that record.
๐ Example:
So, the first row in the Employees table means:
-
There is an employee named John,
-
His ID is 101,
-
He works in HR,
-
His salary is 50,000.
3. ๐น What is a Column (Field)?
-
A column defines an attribute or property of the data.
-
Every row must have a value (or sometimes NULL) for each column.
๐ Example Columns in the Employees table:
-
EmployeeID โ unique identifier
-
Name โ employeeโs name
-
Department โ department name
-
Salary โ salary amount
Each column has a data type (e.g., INT, VARCHAR, DATE, etc.).
For example:
-
EmployeeIDโ Integer -
Nameโ Text (VARCHAR) -
Salaryโ Number/Decimal
4. ๐ Putting It All Together
Letโs visualize:
-
Table = Excel file named Employees.xlsx
-
Column = Each Excel column โ โNameโ, โSalaryโ, โDepartmentโ
-
Row = Each Excel row โ โJohn, 101, HR, 50000โ
So in SQL:
-
Table = container of data
-
Row = one record (employee, student, order, etc.)
-
Column = attribute/field of that record
5. ๐ฅ๏ธ SQL Example
Letโs create the Employees table in SQL:
Insert some rows:
Retrieve data (see rows & columns):
โ You now understand:
-
Tables = storage like Excel sheet
-
Rows = records (John, ID 101, etc.)
-
Columns = attributes (Name, Salary, DeptID)
๐ Understanding Tables, Rows, and Columns (with Real-Life Examples)
1. ๐ฆ Use-Case: Online Shopping (E-Commerce)
Think about Amazon or Flipkart.
They need to store details about their products.
Products Table Example:
| ProductID | ProductName | Category | Price | Stock |
|---|---|---|---|---|
| 201 | iPhone 15 | Mobile | 80000 | 50 |
| 202 | Samsung TV | Electronics | 60000 | 20 |
| 203 | Nike Shoes | Fashion | 5000 | 100 |
-
Table:
Products -
Rows: Each row is one product (iPhone, TV, Shoes).
-
Columns: ProductID, Name, Category, Price, Stock.
๐ SQL Example:
This will list all Mobiles and their prices.
2. ๐ฆ Use-Case: Banking
A bank needs to track customers and their accounts.
Customers Table Example:
| CustomerID | Name | AccountType | Balance |
|---|---|---|---|
| 301 | Rahul | Savings | 15000.00 |
| 302 | Priya | Current | 50000.00 |
| 303 | Arjun | Savings | 32000.00 |
-
Table:
Customers -
Rows: Each customer is a record.
-
Columns: ID, Name, Account Type, Balance.
๐ SQL Example:
This query shows all customers who have more than โน20,000.
3. ๐ Use-Case: Education (School / College)
A school keeps records of students.
Students Table Example:
| StudentID | Name | Class | Marks |
|---|---|---|---|
| 401 | Neha | 10 | 89 |
| 402 | Karan | 12 | 76 |
| 403 | Meena | 9 | 92 |
-
Table:
Students -
Rows: Each student = one row.
-
Columns: StudentID, Name, Class, Marks.
๐ SQL Example:
This shows toppers scoring 90 or above.
4. ๐ Use-Case: Ride Booking (Uber/Ola)
A ride-booking app must store trips.
Rides Table Example:
| RideID | CustomerName | Pickup | Drop | Fare |
|---|---|---|---|---|
| 501 | Ankit | Delhi | Noida | 350 |
| 502 | Sonali | Mumbai | Pune | 1200 |
| 503 | Ramesh | Bangalore | Airport | 600 |
-
Table:
Rides -
Rows: Each ride = one row.
-
Columns: RideID, Customer, Pickup, Drop, Fare.
๐ SQL Example:
This lists all high-value rides.
5. ๐ Putting All Use-Cases Together
-
E-Commerce (Products) โ whatโs being sold.
-
Banking (Customers) โ who owns accounts.
-
Education (Students) โ who studies in school.
-
Ride Booking (Rides) โ trips being tracked.
In all these cases:
-
Table = container of data
-
Row = one record
-
Column = attribute of that record