A database can contain hundreds or thousands of tables. 6️⃣ What is a… — SQL Programming Resources — TG.ME

A database can contain hundreds or thousands of tables.

6️⃣ What is a Row?

A row represents one record. 1 | Rahul | IT | 80000 = 1 row = 1 record.

7️⃣ What is a Column?

A column represents an attribute or field.

Row → Record

Column → Attribute.

8️⃣ What is a Primary Key?

A Primary Key uniquely identifies each row in a table. e.g., employee_id = 101 cannot repeat.

Properties:

Must be unique

Cannot normally be NULL

Identifies a specific record

9️⃣ What is a Foreign Key?

A Foreign Key creates a relationship between tables. orders.customer_id is a Foreign Key referring to customers.customer_id.

🔟 Primary Key vs Foreign Key

PRIMARY KEY → Uniquely identifies a record

FOREIGN KEY → Connects one table to another

1️⃣1️⃣ What is NULL?

NULL means the value is missing, unknown, or not available. It does NOT mean 0, empty string, or "NULL" text.

Correct query: SELECT * FROM employees WHERE manager_id IS NULL;

Wrong: WHERE manager_id = NULL;

1️⃣2️⃣ What are Data Types?

INT → 101

DECIMAL(10,2) → 85000.50

VARCHAR(100) → 'Rahul Sharma'

DATE → 2026-08-25

TIMESTAMP → 2026-08-25 10:30:00

1️⃣3️⃣ One Database Can Have Multiple Tables

DATABASE → Customers, Products, Employees → Orders → Payments

The power of SQL comes from being able to analyze these related tables together.

1️⃣4️⃣ Example: E-Commerce Database

customers, products, orders, order_items — Now business can ask: Which city generated highest revenue? Who are top 10 customers? Which products sell the most?

🧠 Your First SQL Query

SELECT * FROM customers;

SELECT → Retrieve data, * → All columns, FROM → From this table

SELECT customer_id, customer_name, city FROM customers;

💡 Q: What is difference between a Primary Key and a Foreign Key?

A: A Primary Key uniquely identifies each record within its own table, while a Foreign Key is used to reference a key in another table and establish a relationship between tables.

If you understand how data is structured and how tables relate to each other, learning JOIN, GROUP BY, CTE, and Window Functions becomes much easier.

Double Tap ❤️ For Part-2
❤11
August 27, 2026 1.3K 7