Contents IndexCREATE FUNCTION statement CREATE PROCEDURE statement

User's Guide
   Part VI. SQL Anywhere Reference
     Chapter 43. Watcom-SQL Statements
      CREATE INDEX statement

Function

To create an index on a specified table. Indexes are used to improve database performance.

Syntax

     CREATE [ UNIQUE ] INDEX index-name
          ... ON [ owner.]table-name
          ... ( column-name [ ASC | DESC ], ... )
          ... [ { IN|ON} dbspace-name ]

Usage

Anywhere.

Permissions

Must be the owner of the table or have DBA authority.

Side effects

Automatic commit.

See also

Description

The CREATE INDEX statement creates a sorted index on the specified columns of the named table. Indexes are automatically used by SQL Anywhere to improve the performance of queries issued to the database as well as for sorting queries where an ORDER BY clause is specified. Once an index is created, it is never referenced again except to delete it using the DROP INDEX statement.

UNIQUE constraint The UNIQUE constraint ensures that there will not be two rows in the table with identical values in all the columns in the index.

Ascending or descending sorting Columns are sorted in ascending (increasing) order unless descending (DESC) is explicitly specified. An index will be used by SQL Anywhere for both an ascending and a descending ORDER BY, no matter whether the index was ascending or descending. However, if an ORDER BY is performed with mixed ascending and descending attributes, an index will be used only if the index was created with the same ascending and descending attributes.

Index placement By default, the index is placed in the same database file as its table. You can place the index in a separate database file by specifying a dbspace name in which to put the index. This feature is of use mainly for large databases, to circumvent the limit of 2 GB per table.

Notes

Examples

Contents IndexCREATE FUNCTION statement CREATE PROCEDURE statement