07 ohp slide handout 1 - indexes

2
* 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' 1 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * 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); 3 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * 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 2 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * 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; 4 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

Upload: anne-lee

Post on 12-Apr-2017

140 views

Category:

Software


0 download

TRANSCRIPT

* 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'

1 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* 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);

3 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* 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

2 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* 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;

4 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* 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)

5 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* 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;

6 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________