5. Constraints
Number of columns in primary key must not exceed the threshold
Code: NumOfPKColumnsExceed
Rule Description: The number of columns in the primary key is limited to avoid performance issues caused by complex primary keys.
Warning Level: Warning
Review Object: CREATE TABLE
Trigger Condition: The number of columns in the primary key exceeds the set threshold (e.g., 1).
Configurable: Yes
Example: The expression can be configured as 1
, indicating that the primary key can have at most 1 column.
Supported Database Types: ALL
Data type restrictions for primary key columns
Code: DataTypeLimitOfPrimaryKey
Rule Description: The data types of primary key columns should be restricted, with integer types generally recommended for performance optimization.
Warning Level: Warning
Review Object: CREATE TABLE
Trigger Condition: Non-recommended data types are used for primary key columns.
Configurable: Yes
Example: The expression can be configured as unsigned int/unsigned bigint
, indicating that primary key columns should use these unsigned integer types.
Supported Database Types: ALL
Auto-increment columns prohibited for primary keys
Code: IncColumn4PrimaryKeyDisallowed
Rule Description: Applying the auto-increment attribute to primary key columns is prohibited to avoid potential data integrity issues.
Warning Level: Warning
Review Object: CREATE TABLE
Trigger Condition: Primary key columns are defined as auto-increment.
Configurable: Yes
Example: The expression can be configured as unsigned int/unsigned bigint
, indicating that these types are not allowed as auto-increment primary key columns.
Supported Database Types: ALL
Auto-increment columns should be used for primary keys
Code: IncColumn4PrimaryKeyRequired
Rule Description: The use of auto-increment attributes on primary keys is encouraged to simplify data insertion operations and maintain the continuity of the primary key.
Warning Level: Warning
Review Object: CREATE TABLE
Trigger Condition: The primary key is not defined as auto-increment.
Configurable: Yes
Example: The expression can be configured as unsigned int/unsigned bigint
, indicating that primary keys should use these types with auto-increment attributes.
Supported Database Types: ALL
Foreign keys are prohibited
Code: ForeignKeyDisallowed
Rule Description: The creation of foreign key constraints is prohibited because foreign keys increase the complexity and performance overhead of database operations.
Warning Level: Warning
Review Object: CREATE TABLE, ALTER TABLE ADD CONSTRAINT
Trigger Condition: Foreign key constraints are added when creating or modifying a table.
Configurable: Yes
Example: The expression can be configured as 0.8
, indicating that the creation of foreign keys is not allowed.
Supported Database Types: ALL
Inconsistent data types for primary and foreign keys
Code: DiffDataTypesOfRIColumns
Rule Description: The data types of primary keys and corresponding foreign keys must be consistent to ensure data integrity and consistency.
Warning Level: Warning
Review Object: CREATE TABLE, ALTER TABLE ADD CONSTRAINT
Trigger Condition: The data types of primary keys and foreign keys are inconsistent.
Configurable: Yes
Example: The expression can be configured as 0.8
, indicating that the data types of primary and foreign keys must be consistent when creating or modifying a table.
Supported Database Types: ALL
CHECK constraints are prohibited
Code: CreateCheckConstraintDisallowed
Rule Description: The use of CHECK constraints is prohibited because they increase the complexity and performance overhead of database operations.
Warning Level: Warning
Review Object: ALTER TABLE ADD CONSTRAINT
Trigger Condition: CHECK constraints are added.
Configurable: No
Supported Database Types: ALL