Post content
Now, let’s move to the next topic: Indexes 🚀 🧠 1. What is an INDEX? An INDEX is used to make data retrieval faster 👉 Think like a book 📚 - Without index → scan every page - With index → jump directly to topic Same happens in databases 💯 ⚡ 2. Why Use Indexes? ✔ Faster SELECT queries ✔ Faster searching ✔ Better performance on large tables ❌ But: - Uses extra storage - INSERT/UPDATE become slightly slower 📊 Visual Understanding ⚡ 3. Create an INDEX CREATE INDEX idx_salary ON employees(salary); 👉 Creates index on salary column 🔍 4. Query Using Indexed Column SELECT FROM employees WHERE salary > 50000; ✔ Faster because of index ❌ 5. Drop an INDEX DROP INDEX idx_salary ON employees; 🔥 6. Primary Key Automatically Creates Index CREATE TABLE employees ( emp_id INT PRIMARY KEY, name VARCHAR(50) ); ✔ PRIMARY KEY → automatically indexed ⚡ 7. Types of Indexes - Primary Index: Created on primary key - Unique Index: Prevent duplicate values - Composite Index: Index on multiple columns 🎯 8. Composite Index Example CREATE INDEX idx_dept_salary ON employees(department, salary); ✔ Useful when filtering both columns together 🎯 9. Practice Tasks 1. Create index on employee name 2. Create index on department column 3. Create composite index on department + salary 4. Query employees using indexed column 5. Drop created index ⚡ Mini Challenge 🔥 👉 Create a unique index on email column 🔥 Indexes improve READ speed but may slow down INSERT / UPDATE Double Tap ❤️ For More