1. * Property of STI
Page 1 of 6
Indexes
F0004
What is an Index?
An index is a data structure used in
database systems to perform faster
lookup.
Indexes can greatly improve the
performance of searches on the
indexed column or columns.
Example:
SELECT companyname
FROM supplier
WHERE supplierid = 'NBS'
2. * Property of STI
Page 2 of 6
Indexes
F0004
When to Create an Index?
Factors that can be considered to
determine if you should create an
index are as follows:
• Keys and unique columns
• Frequency of search
• Size of table
• Number of updates
• Space considerations
• Data distribution
3. * Property of STI
Page 3 of 6
Indexes
F0004
CREATE INDEX
The syntax is shown below:
CREATE [UNIQUE] INDEX
<indexname> ON <table
name>(<column list>)
This syntax creates an index on the
values of the attribute in <column
list> from table <table name>.
Example:
CREATE UNIQUE INDEX
supplierindex ON
suppliers(supplierid);
4. * Property of STI
Page 4 of 6
Indexes
F0004
DROP INDEX
The syntax is shown below:
DROP INDEX <index name>
This syntax removes an index
specified by the <index name>.
Example:
DROP INDEX supplierindex;
5. * Property of STI
Page 5 of 6
Indexes
F0004
Composite Index
A composite index is an index that
can contain one, two, or more
columns. The syntax is shown
below:
CREATE [UNIQUE] INDEX
<indexname> ON <table
name>(<column1>,
<column1>, …<columnN>)
Example:
CREATE INDEX name
ON student (stud_lname,
stud_fname)
6. * Property of STI
Page 6 of 6
Indexes
F0004
Composite Index
In creating composite index, the
order of columns should be the
same as the order of the columns
in the table.
Composite indexes are useful for
searching on all columns in the
index or on the first columns only.
Example:
CREATE INDEX fname_lname
ON student stud_fname,
stud_lname;
CREATE INDEX lname_fname
ON student stud_lname,
stud_fname;