Enforcing Primary Key, Unique Key, and Check Constraints Automatically

When you create a new constraint with CREATE TABLE or ALTER TABLE, you can specify whether the constraint will be automatically enforced. You can also alter a constraint with ALTER TABLE (using the ALTER CONSTRAINT parameter) and specify whether it will be automatically enforced. You enable or disable individual constraints specifically using the ENABLED or DISABLED options.

In addition, you can create multi-column constraints with CREATE TABLE or ALTER TABLE. All primary key and unique key constraints are defined at the table level. Check constraints are defined at the column or table level.

By checking any system table with an is_enabled column, you can confirm whether a primary key, unique key, or check constraint is currently enabled. The system tables that include an is_enabled column are CONSTRAINT_COLUMNS, TABLE_CONSTRAINTS, and PRIMARY_KEYS.

Automatic enforcement applies to current table content and content you later add to the table.

Important: If validation of the current content fails, Vertica completely rolls back the ALTER TABLE DDL statement that caused the failure.

If you do not specify the ENABLED or DISABLED option when you create a constraint, the system relies on the setting of the configuration parameter for the respective constraint:

In regards to constraint enablement, you can:

Important: When creating a constraint without enabling it, Vertica uses the settings of EnableNewPrimaryKeysByDefault, EnableNewUniqueKeysByDefault, and EnableNewCheckConstraintsByDefault that are in effect at the time of creation.

The following figure summarizes constraint enablement.