CREATE INDEX文は、表の1つ以上の列にTツリー索引を作成して、新しい索引に名前を割り当てます。Tツリー索引は、インメモリー・アプリケーション向けに設計された索引構造です。Tツリーには、次の特徴があります。
TimesTenインスタンスでアクセス制御が有効な場合、この文にはDDL権限が必要です。
CREATE [UNIQUE] INDEX [Owner.]IndexName ON
[Owner.]TableName ( { ColumnName [ASC | DESC] }
[, ... ] )
CREATE INDEX文には、次のパラメータがあります。
冗長な索引を作成してみます。HRスキーマのREGIONS表により、Region_Idに一意の索引が作成されます。Region_Idに2つ目の一意の索引を作成してみます。警告メッセージが表示されます。ttRedundantIndexCheckをコールして警告メッセージを表示します。
Regions表に対してttIsqlコマンドのINDEXESを発行します。一意のTツリー索引Regionsが表示されます。
Command> INDEXES REGIONS;
Indexes on table SAMPLEUSER.REGIONS:
REGIONS: unique T-tree index on columns:
REGION_ID
(referenced by foreign key index COUNTR_REG_FK on table SAMPLEUSER.COUNTRIES)
1 index found.
1 table found.
表Regionsに一意の索引Iを作成し、Region_Id列に索引を作成してみます。警告メッセージが表示されます。
Command> CREATE UNIQUE INDEX I ON Regions (Region_Id);
Warning 2232: New index I is identical to existing index REGIONS; consider dropping index I
ttRedundantIndexCheckをコールして、この索引に対する警告メッセージを表示します。
Command> CALL ttRedundantIndexCheck ('REGIONS');
< Index SAMPLEUSER.REGIONS.I is identical to index SAMPLEUSER.REGIONS.REGIONS; consider dropping index SAMPLEUSER.REGIONS.I >
1 row found.
Redundancy表を作成し、Co11列およびCol2列を定義します。Col1およびCol2に2つのユーザー索引を作成します。2つ目の索引R2を作成しようとするとエラー・メッセージが表示されます。索引R1が作成されます。索引R2は作成されません。
Command> CREATE TABLE Redundancy (Col1 CHAR (30), Col2 VARCHAR2 (30));
Command> CREATE INDEX R1 ON Redundancy (Col1, Col2);
Command> CREATE INDEX R2 ON Redundancy (Col1, Col2);
2231: New index R2 would be identical to existing index R1
The command failed.
Redundancy表に対してttIsqlコマンドのINDEXESを発行し、索引R1のみが作成されていることを表示します。
Command> INDEXES Redundancy;
Indexes on table SAMPLEUSER.REDUNDANCY:
R1: non-unique T-tree index on columns:
COL1
COL2
1 index found.
1 table found.
この一意索引によって、部品の番号はすべて一意になります。
CREATE UNIQUE INDEX Purchasing.PartNumIndex
ON Purchasing.Parts (PartNumber);
employees1表に、german_indexという名前の言語索引を作成します。2つ以上の言語ソートが必要な場合は、2つ目の言語索引を作成します。
Command> CREATE TABLE employees1 (ID CHARACTER (21),
id2 character (21));
Command> CREATE INDEX german_index ON employees1
(NLSSORT(id, 'NLS_SORT=GERMAN'));
Command> CREATE INDEX german_index2 ON employees1
NLSSORT(id2, 'nls_sort=german_ci'));
Command> indexes employees1;
Indexes on table SAMPLEUSER.EMPLOYEES1:
GERMAN_INDEX: non-unique T-tree index on columns:
NLSSORT(ID,'NLS_SORT=GERMAN')
GERMAN_INDEX2: non-unique T-tree index on columns:
NLSSORT(ID2,'nls_sort=german_ci')
2 indexes found.
1 table found.