0% found this document useful (0 votes)
5 views

DBMS

Uploaded by

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

DBMS

Uploaded by

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

DBMS

What is Indexing ?
Types of Indexing and the difference between them.
2-3 SQL queries to find the nth largest salary , maximum salary of each department etc.
Difference between primary and unique constraints in SQL.
What is Normalization ?
Why it is needed ?
Types of Normalizations and there conditions.

What is Indexing?

Indexing in a DBMS is a technique used to speed up the retrieval of records from a


database table. An index is a data structure, often in the form of a tree or a hash table,
that allows the database to find records more quickly than it could by scanning the
entire table. By creating an index on one or more columns of a table, the database can
locate rows with specific column values efficiently.

Types of Indexing and Their Differences

There are several types of indexing in DBMS, each suited to different scenarios and
types of queries. The main types are:

1. Primary Index
2. Secondary Index
3. Clustered Index
4. Non-clustered Index
5. Unique Index
6. Bitmap Index
7. Hash Index

Let's discuss each of these in detail:

1. Primary Index

 Definition: A primary index is created on the primary key of a table. The primary
key is a unique identifier for each record in the table.
 Characteristics:
 Unique: No two rows can have the same primary key value.
 Automatically created when the primary key is defined.
 Usually, the primary index is stored in a sorted order.
 Use Case: Efficiently retrieving rows based on the primary key.

2. Secondary Index
 Definition: A secondary index is created on non-primary key columns. It is used
to improve the performance of queries that do not involve the primary key.
 Characteristics:
 Can be created on multiple columns.
 Not necessarily unique.
 Used in addition to the primary index.
 Use Case: Improving query performance on non-primary key columns, such as
searching by name or date.

3. Clustered Index

 Definition: In a clustered index, the table rows are physically stored in the order
of the indexed column(s). A table can have only one clustered index.
 Characteristics:
 Sorts the actual data rows.
 Often the primary key index is clustered.
 Faster retrieval of range-based queries due to physical ordering.
 Use Case: When data retrieval based on a range of values is frequent, such as
date ranges.

4. Non-clustered Index

 Definition: A non-clustered index does not alter the physical order of the rows.
Instead, it creates a separate object within the table that points back to the
original table rows after sorting.
 Characteristics:
 Can be multiple non-clustered indexes on a table.
 Contains pointers to the actual data rows.
 Slower than clustered indexes for retrieving ranges.
 Use Case: When searching for specific values rather than ranges, like finding a
specific email address.

5. Unique Index

 Definition: A unique index ensures that the indexed column(s) contain unique
values. It is similar to a primary key but can be created on any column(s).
 Characteristics:
 Enforces uniqueness constraint on the column(s).
 Can be created on multiple columns.
 Prevents duplicate values.
 Use Case: Enforcing uniqueness on columns other than the primary key, like an
email or social security number.

6. Bitmap Index

 Definition: A bitmap index uses bitmaps (arrays of bits) and is very efficient for
columns with a low cardinality (few distinct values).
 Characteristics:
 Efficient storage and retrieval for low cardinality columns.
 Bitwise operations allow for fast query processing.
 Not suitable for columns with high cardinality.
 Use Case: Ideal for columns like gender, marital status, or boolean values.

7. Hash Index

 Definition: A hash index uses a hash function to convert column values into a
hash code, which points to the location of the data.
 Characteristics:
 Efficient for equality searches.
 Not suitable for range queries as hash codes do not preserve order.
 Collisions can occur and need to be handled.
 Use Case: Fast lookups for equality conditions, like searching by exact user ID.

Summary

 Primary Index: Created on primary key, unique, often clustered.


 Secondary Index: Created on non-primary key columns, can be multiple, non-
unique.
 Clustered Index: Physically orders the data, only one per table, faster for range
queries.
 Non-clustered Index: Logical order, can be multiple, includes pointers to actual
data.
 Unique Index: Ensures uniqueness on column(s), can be multiple.
 Bitmap Index: Efficient for low cardinality columns, uses bitmaps.
 Hash Index: Uses hash function, efficient for equality searches, not suitable for
ranges.

Each type of index serves specific needs and use cases, and the choice of which to use
depends on the nature of the data and the types of queries performed.

You might also like