To ensure that no duplicate values are entered in specific columns that do not participate in the primary key, you can create a unique constraint. A unique constraint automatically creates a corresponding unique index.
Does the SF also give this option?
Best answer by Anne Buit
This is currently not possible. We always enforce a uniqueness rule by creating an unique index. Both implementation options within the database are virtually the same - the user may not provide duplicate values and an index is created to quickly verify uniqueness.
To my knowledge, there are no functional or technical benefits to allow the Software Factory to transform the uniqueness rule to a unique constraint over of a unique index.
Vice-versa, a benefit of the unique index is that it allows us to apply a filtering (exclude null values).
Translations for the messages shown when failing to meet the unique index requirements are provided by the platform. A unique constraint would cause different messages to be thrown by the database, requiring maintenance on additional translations as well.
However, I do see that it might be better to allow developers to define the uniqueness rules in the model at constraints or perhaps a completely separate segment, rather than with the ‘regular’ indexes (regardless of how this is transformed into database objects).
Is there a reason for using unique constraints over unique indexes that I’m overlooking or is it more a matter of preference?