KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to combine multiple fields into one unique primary key
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: October 25, 2002

Compatibility 4D 6.7.x/6.8.x

1- You can begin by creating 3 fields to work with:

Field1 - [Table 1]FirstName - alpha 20
Field2 - [Table 1]LastName - alpha 20
Field3 - [Table 1]PK1 - alpha 40 - unique - indexed

2- Enable the database events and create a trigger like this:

Case of
: (Database event=On Saving New Record Event )
[Table 1]PK1:=[Table 1]FirstName+[Table 1]LastName

: (Database event=On Saving Existing Record Event )
[Table 1]PK1:=[Table 1]FirstName+[Table 1]LastName
End case

When you save your record, it should look like this.

Field1 - FirstName
Field2 - LastName
Field3 - FirstNameLastName

You can learn more about triggers at: https://www.4d.com/ACIDOC/V6U/V6U00052.HTM