Define Primary and Secondary Keys

You can use a maximum of 16 distinct fields to define a primary key. The number of fields used in the primary key limits the number of fields in the secondary keys. Fields used by one key can also be used in another key; however, no more than 16 unique fields can be used to create primary or secondary keys.

This means that if your primary key includes four distinct fields, your secondary keys can include these four fields, and at most 16 other fields. Correspondingly, if your primary key consists of 20 distinct fields, then your secondary keys must consist only of combinations of these fields.

When you create a table in Table Designer, by default Dynamics NAV uses the field with the lowest field number as the primary key. Use the following procedure to define a different primary key.

Note

The maximum record size in Dynamics NAV is 8000 bytes. Adding a primary key to a table when the record size limit is close to this limit will prevent the table from compiling.

To define a primary key

  1. On the Tools menu, choose Object Designer.

  2. Choose Table.

  3. Select a table from the list and then choose Design.

  4. Select the first empty line and then from the View menu, choose Keys.

    The Keys window appears.

  5. In the first line of the Keys window, enter the primary key as a comma-delimited list; for example, "ID Number, Name".

Note

In the development environment, it is technically possible to create a primary key based on up to 20 fields. However, only the first 16 are used.

Defining Secondary Keys

Up to 40 keys can be defined for a table. The first key defined is the primary key. All the other keys are secondary keys and are optional. Secondary keys are used to view records in an order that is different from the order defined by the primary key fields.

To define a secondary key

  1. On the Tools menu, choose Object Designer.

  2. Choose Table.

  3. Select a table from the list and then choose Design.

  4. Select the first empty line and then from the View menu, choose Keys.

    The Keys window appears.

  5. The first line shows the primary key. Enter the secondary keys on the following lines as comma-separated lists; for example: Name, Address.

See Also

Table Keys
How to: View or Modify Properties on a Key