4D v14.3

Primary key manager

Home

 
4D v14.3
Primary key manager

Primary key manager  


 

 

The "Primary key manager" is an assistant intended to facilitate the resolution of errors related to the presence of tables without primary keys, particularly in the context of a journaled database:

You can use this assistant to:

  • diagnose the compatibility of each database table with the 4D journaling mechanism,
  • propose a correction for each table found that is not compatible, more particularly by creating a primary key.

Note: The Primary Key Manager is also available as a v13 component that you can use to prepare 4D v13 databases for conversion to v14.

There are two ways to display the Primary key manager window:

  • from the  Primary key error window: click on the Run assistant button to display the assistant window.
    Note:
    The Primary key manager is displayed in Design mode. If the database starts in Application mode, the assistant does not appear right away and you will need to switch to Design mode.
  • from the Structure editor: click on the button in the tool bar of this window to display the assistant.

The Primary key manager window displays a line for every table in the database:

Note: The assistant does not take tables placed in the Trash into account..

The icon at the head of each line indicates whether the table requires the attention of the user:

OKA valid primary key is set for the table.
No primary key, eligible field(s)The table does not have a primary key but contains at least one field that could become the primary key.
No primary key, no eligible fieldsThe table does not have a primary key and does not have any fields that could become one (you will have to create a primary key field).
WarningThe table does not have a primary key but it is not journaled ("Include in Log File" option disabled for the table). It is possible to hide tables that have this status by unchecking the option to display warnings.

For each journaled table that does not have a primary key, the assistant displays a menu to set the action to be performed. You can choose from the following options:

  • Ignore: does not modify the table. The errors are not corrected and the status of the table is not changed. Use this option if you wish to intervene later, or if you want to create the primary key outside of the assistant. This option is necessary in particular when you want to create a primary key based on several fields in the table.
  • Use existing field (only shown for tables with at least one field eligible to be a primary key): designates one of the table fields as the primary key. When you choose this option, the assistant suggests the most appropriate field by default.
    If you want to use another field or if the assistant fails to identify a particularly suitable field (the assistant displays "Select a field"), click on the second menu in the row to display the list of eligible fields.
  • Create a new field: creates a new primary key field in the table. This field will have the same characteristics as the one added by default when a new table is created (see Default primary key field).
    By default, the assistant proposes to create a field of the Longint type, named "ID". You can modify the name and type of default primary key fields using the Structure Page in the Preferences of the 4D application. You can access this page of the Preferences by clicking on the button in the Primary key manager window.
    You can also change the name and/or type of the field directly in the Primary key manager window.
  • Do not log this table: unchecks the "Include in Log File" option for the table. You can choose this option in the case of temporary tables (see Include in Log File). After you validate this dialog box, a "Warning" status is assigned to the table.

Once you have made your settings, click on Apply... to apply the changes to the database or Close to close the dialog box without modifying the database.
When you click on Apply..., a confirmation dialog box appears listing the operations to be performed, then you can either confirm or cancel the operation:

If you have designated existing fields as primary keys, 4D checks each table to make sure that its existing data respects the rules concerning uniqueness and null values for this type of field. If, for example, a field contains duplicate values or null values, an error is generated: 

You will need to find and remove these anomalies before you can enable journaling for the data.

Note: In order to facilitate the correction of errors related to primary keys, the primary key values are displayed in the Activity analysis page of the Maintenance and Security Center.

 
PROPERTIES 

Product: 4D
Theme: Creating a database structure

 
ARTICLE USAGE

4D Design Reference ( 4D v14 R2)
4D Design Reference ( 4D v14 R3)
4D Design Reference ( 4D v14.3)
4D Design Reference ( 4D v14 R4)