Hey there learners! ๐ In this chapter, we're going to break down some of the most essential concepts that form the backbone of any SQL database:
✅ Tables ✅ Rows ✅ Columns ✅ Data Types
Understanding these will make writing and reading SQL so much easier — so let’s dive right in!
๐งฑ What is a Table?
In SQL, a table is where data is stored. Think of it like a digital version of an Excel sheet. Each table is made up of rows and columns . Every table should represent a single entity — like students, orders, products, etc.
๐ What are Columns?
Columns define the structure of the table. Each column represents a specific attribute of the entity.
For example, in a students table, your columns might be:
id (a unique number for each student)- name
- age
- course
- marks
Each column has a data type , which we'll cover below.
๐ What are Rows?
Rows are the actual data entries. Each row is one record .
Let’s look at this example of a students table:
| id | name | age | course | marks |
|---|---|---|---|---|
| 1 | Rahul | 21 | SQL | 85 |
| 2 | Priya | 22 | SQL | 92 |
| 3 | Aman | 20 | SQL | 78 |
| 4 | Sneha | 23 | SQL | 88 |
| 5 | Karan | 21 | SQL | 95 |
Each row here represents a student and their data.
๐ง Understanding Data Types in SQL
Every column in a table must be assigned a data type. Data types define what kind of data the column will store — like text, numbers, or dates.
Here are some common SQL data types:
| Data Type | Description | Example |
|---|---|---|
INT |
Integer numbers (no decimal) | 21 , 100 , 0 |
VARCHAR(n) |
Variable-length text (up to n characters) | 'Priya' , 'SQL' |
TEXT |
Long text | 'This is a note.' |
DATE |
A date value | '2025-04-10' |
DECIMAL |
Numbers with decimal places | 85.75 , 99.99 |
BOOLEAN |
True/False values | TRUE , FALSE |
✅ Tip: Choosing the right data type helps keep your database efficient and accurate.
๐งช Creating the students Table with Data Types
Let’s define our students table using SQL and assign data types:
CREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(50), age INT, course VARCHAR(30), marks DECIMAL(5,2));
id is an integer and the primary key (must be unique).name is a string up to 50 characters.age is a whole number.course is also a short text.marks allows decimals like 85.75.
๐ฏ Why All This Matters
- Tables keep your data organized .
- Columns ensure your data is structured .
- Rows store the real data .
- Data types help maintain accuracy and efficiency .
Once you understand these basics, writing SQL becomes more fun and powerful.
✅ Summary
| Term | Meaning |
|---|---|
| Table | A collection of related data |
| Column | A single type of information |
| Row | A single entry or record |
| Data Type | Specifies what kind of data can go into each column |