dbindex:==keyfield
<element>
<keyfield>
此元素可讓您定義連結至表格的索引。
可以定義多個索引。 一個索引可以引用表的一個或多個欄位。 索引聲明通常遵循主模式元素的定義。
<dbindex>
中定義的<keyfield>
元素的順序非常重要。 第一個<keyfield>
必須是查詢主要基於的索引標準。
資料庫中索引的名稱是通過串連表的名稱和索引的名稱來計算的。 例如:建立索引查詢期間索引欄位的表名「Sample」、名稱空間「Cus」、索引名「MyIndex」->名稱:"CusSample_myIndex"。
_operation(string):定義資料庫中的寫入類型。
此屬性主要用於擴展現成可用的架構。
可存取的值包括:
appliableIf(字串):條件——接收XTK運算式。
標籤(字串):索引標籤。
名稱(MNTOKEN):唯一索引名。
唯一(布林):如果激活此選項(@unique="true"),則屬性保證索引在其欄位中的唯一性。
在「id」欄位上建立索引。 (<dbindex>
元素上的"@unique"屬性在資料庫(查詢)中建立索引時觸發添加"UNIQUE" SQL關鍵字。)
<element label="Sample" name="Sample">
<dbindex name="myIndex" label="My index on the ID field" unique="true" applicableIf="HasPackage('nms:social')">
<keyfield xpath="@id"/>
</dbindex>
<attribute name="id" type="long"/>
</element>
ALTER TABLE CusSample ADD iSampleId INTEGER;
UPDATE CusSample SET iSampleId = 0;
ALTER TABLE CusSample ALTER COLUMN iSampleId SET Default 0;
ALTER TABLE CusSample ALTER COLUMN iSampleId SET NOT NULL;
CREATE UNIQUE INDEX CusSample_myIndex ON CusSample(iSampleId);
在「@mail」和「@phoneNumber」欄位上建立複合索引:
<element label="NewSchemaUser" name="NewSchemaUser">
<dbindex name="myIndex" label="My composite index">
<keyfield xpath="@email"/>
<keyfield xpath="@phone"/>
</dbindex>
<attribute name="email" type="string"/>
<attribute name="phone" type="string"/>
</element>
CREATE INDEX DocNewSchemaUser_myIndex ON DocNewSchemaUser(sEmail, sPhone);