Use this statement to create an index on a specified table.
CREATE [ UNIQUE ] INDEX [ index-name ] ON table-name ( ordered-column-list ) [ WITH MAX HASH SIZE integer ]
ordered-column-list : ( column-name [ ASC | DESC ], ... )
UNIQUE The UNIQUE parameter ensures that there are not two rows in the table with identical values in all the columns in the index. Each index key must be unique or contain a NULL in at least one column.
There is a difference between a unique constraint on a table and a unique index. Columns in a unique index are allowed to be NULL, while columns in a unique constraint are not. Also, a foreign key can reference either a primary key or a column with a unique constraint. A foreign key cannot, however, reference a unique index.
ordered-column-list An ordered list of columns. Column values in the index can be sorted in ascending or descending order.
WITH MAX HASH SIZE Sets the hash size (in bytes) for this index. This value overrides the default MaxHashSize property in effect for the database. To learn the default size, see Accessing UltraLite database properties.
UltraLite automatically creates indexes for primary keys and for unique constraints.
Indexes can improve query performance by providing quick ways for UltraLite to look up specific rows. Conversely, because they have to be maintained, indexes may slow down INSERT, DELETE, and UPDATE statements, as well as synchronization.
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 in a SQL statement again except to remove it with DROP INDEX.
Indexes use space in the database. Also, the additional work required to maintain indexes can affect the performance of data modification operations. For these reasons, you should avoid creating indexes that do not improve query performance.
UltraLite does not process requests or queries referencing the index while the CREATE INDEX statement is being processed. Furthermore, you cannot execute CREATE INDEX when the database includes active queries or uncommitted transactions.
UltraLite can also use execution plans to optimize queries. See Execution plans in UltraLite.
For UltraLite.NET users: You cannot execute this statement unless you also call the Dispose method for all data objects (for example, ULDataReader). See Dispose method.
Statements are not released if schema changes are initiated at the same time. See Schema changes with DDL statements.
The following statement creates a two-column index on the Employees table.
CREATE INDEX employee_name_index ON Employees ( Surname, GivenName );
The following statement creates an index on the SalesOrderItems table for the ProductID column.
CREATE INDEX item_prod ON SalesOrderItems ( ProductID );
|Send feedback about this page via email or DocCommentXchange||Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0|