Bde.DBTables.TTable.AddIndex

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure AddIndex(const Name, Fields: string; Options: TIndexOptions;  const DescFields: string = '');

C++

void __fastcall AddIndex(const System::UnicodeString Name, const System::UnicodeString Fields, Data::Db::TIndexOptions Options, const System::UnicodeString DescFields = System::UnicodeString());

Properties

Type Visibility Source Unit Parent
procedure
function
public
Bde.DBTables.pas
Bde.DBTables.hpp
Bde.DBTables TTable

Description

Creates a new index for the table.

Call AddIndex to create a new index for the already existing table associated with the dataset component. The index created with this procedure is added to the database table underlying the dataset component.

Name is the name of the new index. Name must contain an index name that is valid for the particular database type used (naming rules vary from one database type to another.)

Fields contains the names of the fields on which the new index will be based. If more than one field is used, separate the field names in the list with semicolons.

Options is a set of attributes for the index. The Options parameter may contain any one, multiple, or none of the TIndexOptions constants:

  • ixPrimary
  • ixUnique
  • ixDescending
  • ixCaseInsensitive
  • ixExpression

Not all database systems will necessarily support all of these options. Even within a particular table type, any given option may only be supported in certain versions of a table type. Consult the documentation for the particular database system used to determine which options are and are not supported. See the topic for the TIndexOptions type for definitions of individual constants and the implications of their use.

DescFields is a string containing a list of field names, separated by semicolons.

The fields specified in DescFields are the fields in the new index for which the ordering will be descending. Fields in the index definition but not in the DescFields list use the default ascending ordering. It is possible that a single index can have fields using both ascending and descending ordering.


Table1.AddIndex('MostPaid', 'CustNo;SaleDate;AmountPaid', [ixCaseInsensitive], 'SaleDate;AmountPaid');


TIndexOptions Options;
Options << ixCaseInsensitive;
Table1->AddIndex("MostPaid", "CustNo;SaleDate;AmountPaid", Options, "SaleDate;AmountPaid");


Warning: Attempting to create an index using options that are not applicable to the table type causes AddIndex to raise an exception.

dBASE tables only support primary indexes and true unique indexes when the table level is 7 or higher (concurrent with Visual dBASE 7). dBASE tables do not support case-insensitive indexes at all. You must use the ixExpression constant when the index is based on multiple fields or uses dBASE Data Manipulation Language (DML) functions (that is, for expression indexes). Multifield dBASE indexes cannot be created simply with a list of field names (separated by semicolons) in the Fields parameter of AddIndex. The ixExpression constant is only applicable to dBASE tables.

Paradox tables support the ixDescending option for secondary indexes if the table level is 7 or higher and ixUnique if the table level is 5 or higher. The ixDescending and ixCaseInsensitive constants are not applicable to primary indexes.

For other table types, see the vendor-supplied documentation for the particular database system to find out details on what index options are applicable.

See Also