Previous Topic

Next Topic

Create Index

Valid in: SQL, ESQL

The Create Index statement creates an index on an existing table.

Previous Topic

Next Topic

Syntax

The Create Index statement has the following format:

[EXEC SQL] CREATE [UNIQUE] INDEX [schema.]index_name
              ON [schema.]table_name
              (column_name {, column_name})[UNIQUE]
              [WITH with-clause]

To build a set of indexes on the same table in parallel:

[EXEC SQL] CREATE [UNIQUE] INDEX [schema.]index_name
              ON [schema.] table_name
              (column_name [ASC|DESC]{, column_name..})[UNIQUE]
              [WITH with-clause]){, ([schema.]index_name }

or

[EXEC SQL] CREATE [UNIQUE] INDEX ([schema.] index_name

              ON table_name

              (column_name [ASC|DESC]{, column_name..})

              [UNIQUE]) {,([schema.]index_name…}

              [WITH with-clause]

Note: When using parallel index syntax, concurrent access is not allowed on readonly tables.

Note: If II_DECIMAL is set to comma, be sure that when SQL syntax requires a comma (such as a list of table columns or SQL functions with several parameters), that the comma is followed by a space. For example:

select col1, ifnull(col2, 0), left(col4, 22) from t1:

Previous Topic

Next Topic

Description

The index contains the columns specified. Any number of indexes can be created for a table, but each index can contain no more than 32 columns. The contents of indexes are sorted in ascending order by default.

Indexes can improve query processing. To obtain the greatest benefit, create indexes that contain all of the columns that are generally queried. The index must be keyed on a subset of those columns.

By default, the index is keyed on the columns in the column list, in the order they are specified. If the key option is specified, the index is keyed on the columns specified in the key list, in the order specified. For example, if you issue the statement:

create index nameidx on employee
        (last, first, phone);

you create an index called, nameidx, on the employee table that is keyed on the columns last, first, and phone in that order.

However, if you issue the statement:

create index nameidx on employee
(last, first, phone)
       with key = (last, first);

the index is keyed only on the two columns, last and first.

The columns specified in the key column list must be a subset of the columns in the main column list. A long varchar column cannot be specified as part of a key.


© 2007 Ingres Corporation. All rights reserved.