This element lets you define an index linked to a table.
It’s possible to define several indexes. One index can reference one or more fields of the table. Index declaration usually follows the definition of the main schema element.
The order of the
<keyfield> elements defined in a
<dbindex> is very important. The first
<keyfield> must be the indexation criterion which the queries are mainly based on.
The name of the index in the database is calculated by concatenating the name of the table and the name of the index. For example: Table name “Sample”, Namespace “Cus”, index name “MyIndex”-> name of the index field during index creation querying: “CusSample_myIndex”.
_operation (string): defines the type of writing in the database.
This attribute is mainly used when extending out-of-the-box schemas.
Accessible values are:
applicableIf (string): condition for taking the index into account - receives an XTK expression.
label (string): index label.
name (MNTOKEN): unique index name.
unique (boolean): if this option is activated (@unique=“true”), the attribute guarantees the uniqueness of the index throughout its fields.
Creation of an index on the “id” field. (the “@unique” attribute on the
<dbindex> element triggers adding of the “UNIQUE” SQL key word when the index is created in the database (query)).
<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);
Creation of a composite index on the “@mail” and “@phoneNumber” fields:
<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);