Collection Contents Index CREATE FUNCTION statement CREATE MESSAGE statement [T-SQL] pdf/chap9.pdf

Reference Manual
   CHAPTER 9. 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 ]

Permissions 

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

Side effects 

Automatic commit.

See also 

DROP statement

Description 

The CREATE INDEX statement creates a sorted index on the specified columns of the named table. Indexes are automatically used to improve the performance of queries issued to the database, and to sort queries with an ORDER BY clause. 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 for both an ascending and a descending ORDER BY, 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 useful mainly for large databases, to circumvent the limit, on operating systems other than Windows NT, of 2 GB per table.

Notes 

Standards and compatibility 

The full syntax for Adaptive Server Enterprise 11.5 is as follows:

CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ]
... INDEX index-name
... ON [ [ database.]owner.]table_name
(column_name [, column_name]...)
... [ WITH {
... { FILLFACTOR | MAX_ROWS_PER_PAGE } = x,
CONSUMERS = x,
... IGNORE_DUP_KEY,
... SORTED_DATA,
[ IGNORE_DUP_ROW | ALLOW_DUP_ROW ]
} ]
... [ ON segment_name ]

Adaptive Server Enterprise indexes can be either clustered or nonclustered. A clustered index almost always retrieves data faster than a nonclustered index. Only one clustered index is permitted per table.

Adaptive Server Anywhere does not support clustered indexes. The CLUSTERED and NONCLUSTERED keywords are allowed by Adaptive Server Anywhere, but no action is taken.

Adaptive Server Anywhere also allows, by ignoring, the following keywords:

Physical placement of an index is carried out differently in Adaptive Server Enterprise and Adaptive Server Anywhere. The ON segment-name clause is supported in Adaptive Server Anywhere, but segment-name refers to a dbspace.

Index names must be unique on a given table for both Adaptive Server Anywhere and Enterprise.

Examples 


Collection Contents Index CREATE FUNCTION statement CREATE MESSAGE statement [T-SQL] pdf/chap9.pdf