0% found this document useful (0 votes)
21 views12 pages

Index in Database Presentation Group4

An index in a database is a mechanism that allows for quick data retrieval, functioning as a shortcut to avoid full table scans. There are various types of indexes, including single-column, composite, and unique indexes, each serving different purposes for optimizing search and query performance. While indexes enhance data access speed, they also require additional storage and can slow down data modification operations if overused.

Uploaded by

aslamaslamkhan53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views12 pages

Index in Database Presentation Group4

An index in a database is a mechanism that allows for quick data retrieval, functioning as a shortcut to avoid full table scans. There are various types of indexes, including single-column, composite, and unique indexes, each serving different purposes for optimizing search and query performance. While indexes enhance data access speed, they also require additional storage and can slow down data modification operations if overused.

Uploaded by

aslamaslamkhan53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Index in a Database

FA23-BCS-014(HOORABIA SATTAR)
FA23-BCS-041(MUHAMMAD ABDULLAH KHALID)
FA23-BCS-008(ALIZA BAIG)
What is an Index in a
Database?
 • An index is like a shortcut for finding data
quickly.
 • Without an index, the database performs

a full table scan.


 • With an index, it can jump directly to the

needed data.
 • Analogy: Book index or Google search.
Why We Use Indexes
• Fast Searching: Helps in locating data
quickly.
• Better Query Performance:
- WHERE clause filtering
- JOIN operations
- ORDER BY and GROUP BY clauses
Example of index:
Types of index
1. Single-column Index

 Index on one column.


 Speeds up search/filter/sort on that column
 Example:

CREATE INDEX idx_employee_id


ON Employees(EmployeeID);
2. Composite (Multi-column)
Index
 Index on two or more columns.
 Helps in filtering/sorting with combined

columns.
 Column order in index matters.
 Example:

CREATE INDEX idx_name_dept


ON Employees(LastName, Department);
3. Unique Index
 Ensures no duplicate values in indexed
column(s).
 Useful for unique fields like email.
 Example:

CREATE UNIQUE INDEX idx_unique_email


ON Employees(Email);
Creating an Index
 Select the column that is frequently searched or
filtered.Then write the CREATE INDEX command.

 Syntax:

CREATE INDEX index_name


ON table_name (column_name);

 Example:

CREATE INDEX idx_employee_id


ON Employees (EmployeeID);
Dropping an Index
 First, know the name of the index you want to remove
from the database.

 Write the DROP INDEX command to delete the index.

 Syntax:

DROP INDEX index_name;

 Example:

DROP INDEX idx_employee_id;


Note:
Some databases like MySQL, SQL
Server, or Oracle have slightly
different syntax depending on the
DBMS.
Drawbacks of Indexing
 Consumes extra storage.
 Slows down INSERT, UPDATE, DELETE

operations.
 Over-indexing can reduce performance.
Conclusion
 • Indexes make data retrieval faster.
 • Choose indexes wisely for performance.
 • Avoid over-indexing to keep balance.

You might also like