| Universal Database (netDB2) Introductory GuideCreate IndexThe CREATE INDEX statement is used to create an index on a DB2 table. 
An index specification: Indexes are used by the database manager to: 
 
 Explanation: UNIQUE If ON table-name is specified, UNIQUE prevents the table from containing two or more rows with the same value of the index key. The uniqueness is enforced at the end of the SQL statement that updates rows or inserts new rows. The uniqueness is also checked during the execution of the CREATE INDEX statement. If the table already contains rows with duplicate key values, the index is not created. When UNIQUE is used, null values are treated as any other values. For example, if the key is a single column that may contain null values, that column may contain no more than one null value. If ON nickname is specified, UNIQUE should be specified only if the data for the index key contains unique values for every row of the data source table. The uniqueness will not be checked.INDEX index-name Names the index or index specification. The name, including the implicit or explicit qualifier, must not identify an index or index specification that already exists.ON table-name or nickname The table-name names a table on which an index is to be created. The table base table (not a view) or a summary table described in the catalog. nickname is the nickname on which an index specification is to be created. The nickname references either a data source table whose index is described by the index specification, or a data source view that is based on such a table.column-name For an index, column-name identifies a column that is to be part of the index key. For an index specification, column-name is the name by which the federated server references a column of a data source table. Each column-name must be an unqualified name that identifies a column of the table. 16 columns or less may be specified. If table-name is a typed table, 15 columns or less may be specified.imust be a base table (not a view) or a summary table.ASC Puts the index entries in ascending order by the column. This is the default.DESC Puts the index entries in descending order by the column.SPECIFICATION ONLY Indicates that this statement will be used to create an index specification that applies to the data source table referenced by nickname.INCLUDE This keyword introduces a clause that specifies additional columns to be appended to the set of index key columns. Any columns included with this clause are not used to enforce uniqueness.The limits for the number of columns and sum of the length attributes apply to all of the columns in the unique key and in the index.INCLUDE is disallowed if nickname is specified.CLUSTER Specifies that the index is the clustering index of the table. The cluster factor of a clustering index is maintained or improved dynamically as data is inserted into the associated table, by attempting to insert new rows physically close to the rows for which the key values of this index are in the same range.PCTFREE integer Specifies what percentage of each index page to leave as free space when building the index. The first entry in a page is added without restriction. When additional entries are placed in an index page at least integer percent of free space is left on each page. The value of integer can range from 0 to 99.MINPCTUSED integer Indicates whether indexes are reorganized online and the threshold for the minimum percentage of space used on an index leaf page If after a key is deleted from an index leaf page, the percentage of space used on the pageis at or below integer percentage, an attempt is made to merge the remaining keys on this page with those of a neighbouring page. If there is sufficient space on one of these pages, the merge is performed and one of the pages is deleted. The value of integer can be from 0 to 99.DISALLOW REVERSE SCANS Specifies that an index only supports forward scans or scanning of the index in the order defined at INDEX CREATE time. This is the default. DISALLOW REVERSE SCANS is disallowed if nickname is specified.ALLOW REVERSE SCANS Specifies that an index can support both forward and reverse scans; that is, in the order defined at INDEX CREATE time and in the opposite (or reverse) order. ALLOW REVERSE SCANS is disallowed if nickname is specified.Example 1: Create an index named UNIQUE_NAM on the PROJECT table. The purpose of the index is to ensure that there are not two entries in the table with the same value for project name (PROJNAME). The index entries are to be in ascending order. 
 
 
Example 2: 
 
 
Example 3: 
 
 |