KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Creating Composite Primary Keys
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: September 10, 2015

In 4D it is possible to create composite primary keys.

There are a couple ways to perform this.

Method 1: Structure Editor

  1. First highlight the Fields that will be part of set of composite primary keys.
    Note: Press and hold the control key to select multiple non-adjacent fields
  2. Contextually click a highlighted record
  3. Select Create Primary Key

This will create composite primary keys.

Method 2: By Code Using SQL Statements

To create composite primary keys using SQL statements, list the fields in the parenthesis as if creating a typical primary key.

For example:

Begin SQL
   ....
   CONSTRAINT {ConstraintName} PRIMARY KEY({Field1}, {Field2}, ... {FieldN})
   ....
End SQL


Also note that when using composite primary keys they will need a composite index containing the same fields or there will be an indexing error.

Tech Tip: Creating Composite Indexes