Single-field primary key requires the NotBlank property (AC0002)
In tables that define a primary key consisting of a single field of type Code or Text, the primary key field must explicitly set the NotBlank property. This ensures that empty values cannot be used as primary keys, which would violate database integrity principles.
Explicitly declaring NotBlank makes the design intent clear and prevents runtime errors when attempting to insert records with blank primary key values.
A code fix is available for this diagnostic.
Example
The following table has a single Code field as primary key without the NotBlank property:
table 50100 MyTable
{
fields
{
field(1; MyField; Code[20]) // NotBlank property should be set explicitly for tables with a single-field primary key. [AC0002]
{
}
}
keys
{
key(Key1; MyField)
{
Clustered = true;
}
}
}
To fix this, explicitly set the NotBlank property:
table 50100 MyTable
{
fields
{
field(1; MyField; Code[20])
{
NotBlank = true;
}
}
keys
{
key(Key1; MyField)
{
Clustered = true;
}
}
}
See also
- AC0003 - Set NotBlank property to false when ‘No. Series’ TableRelation exists