Skip to main content
Question Most Common

What is an Index in SQL ? Explain their advantages, and disadvantages.

A
Anonymous
December 15, 2025

Answer

An index in SQL is a database object that speeds up data retrieval from a table. It works like the index at the back of a book: instead of reading every page to find a topic, you look it up and go straight to the right pages.


A database index lets the engine find specific rows without scanning the whole table. It matters most on large tables with thousands or millions of records.


Single-column index

A single-column index is created on one column. It helps when that column is often used in WHERE, JOIN, or ORDER BY.

Suppose the Sales table holds thousands of transactions and you often search by product_id:

CREATE INDEX idx_product_id
ON Sales (product_id);

This creates an index named idx_product_id on the product_id column.


Now consider this query:

SELECT *
FROM Sales
WHERE product_id = 101;

Without the index, the database may have to scan the entire Sales table to find matching rows. With it, the database can use the index to locate those rows directly and scan far less data.


Multi-column index (composite index)

A multi-column index, also called a composite index, is created on two or more columns. It helps when queries often filter or sort on those columns together.

CREATE INDEX idx_product_quantity
ON Sales (product_id, quantity);

This indexes both product_id and quantity. For this query:


SELECT *
FROM Sales
WHERE product_id = 101
AND quantity > 10;

the database can use the composite index to find sales of product 101 with a quantity above 10.

Column order matters. An index on (product_id, quantity) generally helps queries that filter on product_id, or on both columns. It is usually less effective for queries that filter only on quantity.


Unique index

A unique index rejects duplicate values in the indexed column or combination of columns.

CREATE UNIQUE INDEX idx_employee_email
ON Employees (email);

This stops two employees from sharing the same email address, subject to how the database handles NULL values. A unique index enforces data integrity and also supports fast lookups.


Advantages

Indexes speed up lookups and WHERE filtering, and they can improve joins between large tables. They can also reduce sorting work for some ORDER BY queries. All of this comes from avoiding full table scans where the index is usable.


Disadvantages

Every INSERT, UPDATE, and DELETE has to maintain the indexes too, so writes get slower. Indexes also take up storage and need some monitoring and maintenance. Adding indexes that no query uses increases write overhead without guaranteeing faster reads.


Practical example in Appian

Suppose an Appian application manages 100,000 financial transactions. A dashboard often retrieves pending transactions with this query:

SELECT *
FROM Transactions
WHERE status = 'Pending'
AND assigned_group = 'Finance';

If those two columns are usually filtered together, a composite index is worth considering:

CREATE INDEX idx_status_group
ON Transactions (status, assigned_group);

This may help the database find the relevant transactions faster, but the actual benefit depends on how many rows match, the table size, and the query execution plan.

In Appian, indexes help when tuning queries against large tables and views, including the data sources behind non-synced record types.


Interview takeaway

An index is a database structure that helps retrieve records faster. It can cover one column or several, and a unique index also prevents duplicates. Indexes generally improve reads but add storage and slow down writes, so base them on real query patterns: index columns that are frequently searched, filtered, joined, or sorted, and skip the rest.

Check yourself

Question 1 of 3, on what the answer above covers.

  1. 1.
    What is the main purpose of an index on a database table?
JuniorSeniorDatabase