Question Most Common
What are the indexes, advantages + disadvantages?
A
Anonymous
December 15, 2025

Answer

Indexes in SQL are special database structures that speed up data retrieval by allowing quick access to records instead of scanning the entire table. They act like a lookup system and play an important role in improving query performance and database efficiency.

  1. It speed up queries (SELECT, JOIN, WHERE, ORDER BY).
  2. Reduce disk I/O and improve efficiency in large tables.
  3. Ensure data integrity with unique indexes.


Creating an Index

Single Column Indexes

A single-column index is created on just one column. It’s the most basic type of index and helps speed up queries when you frequently search, filter or sort by that column.

Syntax:

CREATE INDEX index_name ON TABLE column;

Example: SQL database and table, on which we implement the Indexes.

Screenshot-2025-11-22-150923

Query:

CREATE INDEX idx_product_id ON Sales (product_id);

Explanation: This creates an index named idx_product_id on the product_id column.


Multi Column Indexes

A multi-column index is created on two or more columns. It improves performance when queries filter or join based on multiple columns together.

Syntax:

CREATE INDEX index ON TABLE (column1, column2,.....);

Query:

CREATE INDEX idx_product_quantity ON Sales (product_id, quantity);

Explanation: This index allows database to quickly filter or join data based on both product_id and quantity columns with a confirming message.


Advantages of Indexes

✅ Faster SELECT queries

✅ Efficient sorting and filtering

✅ Improves JOIN performance

✅ Reduces full table scans

Disadvantages of Indexes

❌ Slower INSERT, UPDATE, DELETE

❌ Extra storage required

❌ Index maintenance overhead

❌ Over-indexing hurts performance

JuniorSeniorDatabase
Loading comments...