Skip to main content

Create a Dependent Key

Last updated 19/03/2024

To create a dependent key, you must have an inheritance scenario in your database. The common fields are stored in the parent table and the children tables will inherit these fields from the parent table. After you have named your table and added the primary key, perform the following steps to create a dependent key. If you have not added a table in Five before, please refer to the chapter Add a Table.

Scenario

The diagram below shows the common fields are stored in the Entity table and it has an EntityType field. This field will be used to store whether the type is a customer or a contact. The Customer and Contact tables are the children tables and can both inherit the fields from the Entity table. The primary key in the children tables become the foreign key to the parent table.

Inheritance
Figure 1 - Inheritance
Prerequisites
  • Add the parent table.
  • Add the common fields in the parent table.
  • Add a Type field in the parent table.

Add the Child Table

1. Click the Add Item button.

2. Click the lookup icon in the Database field and select a database.

info
If you only have one database for your application, Five will automatically populate it in the Database field. If you are working in Local, you cannot have multiple databases in one application, so you will not see the Database field.

3. Type an ID for the child table in the Data Source ID field.

4. Type a name in the Table Name field.


Add a child table
Figure 2 - Add a child table

Add the Primary Key Field

5. Click the Fields tab.


Fields tab
Figure 3 - Fields tab

6. Click the Add Fields button.


Add Fields button
Figure 4 - Add Fields button

7. Type an ID in the Field ID field.

8. Click the lookup icon in the Data Type field and select GUID.

9. Click the Generated switch.

10. Click the Required switch.

11. Click the lookup icon in the Default Display Type field and select _Lookup.


Add the primary key field
Figure 5 - Add the primary key field

12. Click the Save button in the form app bar.


Save button
Figure 6 - Save button

Add the Primary Key

13. Click the Indices tab.


Indices tab
Figure 7 - Indices tab

14. Click the Add Indices button.


Add Indices button
Figure 8 - Add Indices button

15. Type an ID in the Index ID field.

16. Click the lookup icon in the Key Type field and select Primary.


Add the primary key
Figure 9 - Add the primary key

17. Click the Index Fields tab.


Index Fields tab
Figure 10 - Index Fields tab

18. Click the Add Index Fields button.


Add Index Fields button
Figure 11 - Add Index Fields button

19. Click the lookup icon in the Field field and select the primary key field from the current table.


Add index field
Figure 12 - Add index field

20. Click the Save button in the form app bar.


Save button
Figure 13 - Save button

21. Click the Save button in the form app bar above the list.


Save button
Figure 14 - Save button

Add the Dependent Index

22. Click the Add Indices button.


Add Indices button
Figure 15 - Add Indices button

23. Type an ID in the Index ID field.

24. Click the lookup icon in the Key Type field and select Dependent.

25. Click the lookup icon in the Foreign Data Source field and select the parent data source.

info
Five will automatically populate the Dependent Index field with the primary key for the selected data source.

Add the dependent key
Figure 16 - Add the dependent key

26. Click the Index Fields tab.


Index Fields tab
Figure 17 - Index Fields tab

27. Click the Add Index Fields button.


Add Index Fields button
Figure 18 - Add Index Fields button

28. Click the lookup icon in the Field field and select the primary key field on the current table.


Add index field
Figure 19 - Add index field

29. Click all three Save buttons in the stacked form app bars.


Save buttons
Figure 20 - Save buttons

30. Click the Save button in the Table Upgrade window.


Save the table upgrade
Figure 21 - Save the table upgrade