Lab 06 (1) (1)
Lab 06 (1) (1)
Lab Manual 06
Session: Fall-2024
Instructor: SHEZA SHABIR
Index in SQL:
An index is a database object that speeds up data retrieval operations on a table. It works like an
index in a book, allowing the database to locate data quickly without scanning the entire table.
Faster Query Performance: Queries that use WHERE, JOIN, or sorting (ORDER BY)
can execute much faster with an index.
Efficient Data Access: Reduces the time it takes to locate and retrieve data from a table.
Improved Sorting: Indexes are helpful when ordering data.
Example:
Transaction Table:
The transaction_date values are extracted and organized in a way that makes
searching faster.
These values are stored in a sorted order, depending on the index type (e.g., B-tree).
Pointers to the Original Table Are Kept:
Alongside each transaction_date value, the index stores a "pointer" that refers to the
actual row in the original table. This pointer uses the primary key (like transaction_id)
to locate the row.
Types of Indexes:
1. Single-column Index
3. Unique Index
4. Full-text Index
Definition: Used for fast searching of text within large text or document fields.
Purpose: Optimized for searching words/phrases in large text fields (like product
descriptions).
Example:
6. Non-clustered Index
SET STATISTICS IO ON; -- Shows I/O details like logical reads, physical reads, etc.
SET STATISTICS TIME ON; -- Shows CPU time and elapsed execution time