All table keys except the primary key are mapped to indexes in the corresponding SQL Server table. While not mandatory, indexes help improve the performance of queries against the table. It is a good idea to declare an index on fields that are often used in search criteria on the table. For example, the Lease Contract Header table has a field, Customer No.. It is likely that we will use this field for filtering to find all contracts for a certain customer. Probably,we don't even want to select all contracts belonging to a customer, but only active ones. In this case, we will run code similar to this:
LeaseContractHeader.SETRANGE("Customer No.",'10000');
LeaseContractHeader.SETFILTER("Starting Date",'<=',WORKDATE);
LeaseContractHeader.SETFILTER("Ending Date",'>=',WORKDATE);
LeaseContractHeader.FINDSET;
With a large number of records in the table, an index on the Customer No., Starting Date, and Ending Date fields will boost the query.
To create a secondary index on a table, follow the same steps as for declaring the primary key.