Understanding Tables, Rows, and Columns in Databases 📊

Understanding Tables, Rows, and Columns in Databases 📊
1️⃣ What is a Table in a Database?
A table is a structured collection of data in a relational database. It consists of rows (records) and columns (fields). Each table represents a specific entity, such as users, products, or orders.
Example: "Students" Table
ID Name Age Email
1 Alice 22 alice@example.com
2 Bob 24 bob@example.com
3 Charlie 21 charlie@example.com
2️⃣ Understanding Rows and Columns
✅ Columns (Fields)
Definition: A column is a single attribute or field in a table.
Each column has a data type (e.g., INT, VARCHAR, DATE).
Columns define what data can be stored in a table.
📌 Example:
ID (Integer) – Unique identifier
Name (String) – Stores names
Age (Integer) – Stores age
Email (String) – Stores email addresses
✅ Rows (Records)
Definition: A row represents a single record in the table.
Each row contains values for each column.
📌 Example:
Row 1: (1, 'Alice', 22, 'alice@example.com')
Row 2: (2, 'Bob', 24, 'bob@example.com')
3️⃣ Basic Database Terminology
🔹 Database – A collection of tables storing related data.
🔹 Table – A structured set of data (rows and columns).
🔹 Column (Field) – A specific attribute of the data.
🔹 Row (Record) – A single entry in a table.
🔹 Primary Key (PK) – A unique identifier for each row (e.g., ID).
🔹 Foreign Key (FK) – A column that links two tables.
🔹 SQL (Structured Query Language) – The language used to interact with databases.
4️⃣ SQL Commands to Work with Tables
✅ Creating a Table
sql
Copy
Edit
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
age INT,
email VARCHAR(100) UNIQUE
);
✅ Inserting Data (Adding Rows)
sql
Copy
Edit
INSERT INTO students (name, age, email)
VALUES ('Alice', 22, 'alice@example.com');
✅ Retrieving Data
sql
Copy
Edit
SELECT * FROM students;
✅ Updating Data
sql
Copy
Edit
UPDATE students SET age = 23 WHERE id = 1;
✅ Deleting a Row
sql
Copy
Edit
DELETE FROM students WHERE id = 1;
🎯 Summary
✔ Tables store data in rows and columns.
✔ Columns define data types and attributes.
✔ Rows hold individual records.
✔ Primary Keys uniquely identify records.
✔ SQL is used to manage and manipulate data.
Date: 2025-03-28 00:00:00.000000