The CREATE INDEX statement is used to create an index on a DB2 Everyplace table.
Invocation
This statement can be used in an application program using the DB2 CLI functions or issued through the CLP.
Syntax
>>-CREATE--INDEX--index-name--ON--table-name--------------------> .-,-----------------------------------------. V .-ASC--. | >--(----+-column-name-----------------+--+------+-+--)--------->< +-UCASE--(--| expression |--)-+ '-DESC-' '-LCASE--(--| expression |--)-'
Description
Each column name must be an unqualified name that identifies a column of the table. Use eight columns or fewer; the column names cannot be repeated (SQLSTATE 42711).
The length of each specified column must not be greater than 1024 bytes.
The LCASE or LOWER function returns a string in which all the SBCS characters have been converted to lowercase characters. That is, the characters A-Z will be translated to the characters a-z, and characters with diacritical marks will be translated to their lowercase equivalents if they exist.
The argument must be an expression whose value is a CHAR or VARCHAR data type.
The result of the function has the same data type and length attribute as the argument. If the argument can be null, the result can be null; if the argument is null, the result is the null value.
Ensure that the characters in the value of column JOB in the EMPLOYEE table are returned in lowercase characters. For example:
SELECT LCASE(JOB) FROM EMPLOYEE WHERE EMPNO = '000020';
Rules
CREATE INDEX IDX1 ON EMPLOYEE (JOB ASC) CREATE INDEX IDX1 ON EMPLOYEE (JOB DESC)In general, indexes should be created without specifying the order direction. Fewer indexes typically incurs lower index maintenance cost.
CREATE INDEX J1 ON T (A, B, C, D, E, F, G, K)There is no need to create another index on T (A,B,C,D).
CREATE INDEX <index name> ON <table name> ($dirty)
See *** for more information about the dirty bit.
Example
Create an index named JOB_BY_DPT on the EMPLOYEE table. Arrange the index entries in ascending order by job title (JOB) within each department (WORKDEPT).
CREATE INDEX JOB_BY_DPT ON EMPLOYEE (WORKDEPT, JOB)
Related reference