Home

Constraint names should comply with a naming convention

Description

    The rule "Constraint names should comply with a naming convention" states that all constraints in a PL/SQL code should have names that follow a specific naming convention. This ensures that the names of the constraints are consistent and easily identifiable. The naming convention should be agreed upon by the development team and should be documented in the project documentation. This will help to ensure that the names of the constraints are easily recognizable and understood by all members of the development team.

Key Benefits

  • Improved readability: Constraint names that comply with a naming convention rule are easier to read and understand.
  • Reduced errors: Following a naming convention for constraints reduces the chance of errors when creating and maintaining the database.
  • Simplified maintenance: A consistent naming convention makes it easier to maintain the database over time.

 

Non-compliant Code Example

Create TABLE EMPLOYEE 
(
  EMP_ID number(10) NOT NULL,
  FIRSTNAME NVARCHAR2(75),
  LASTNAME NVARCHAR2(75),
  DEPT_ID int,  
  ADDRESS NVARCHAR2(250) NOT NULL,

  CONSTRAINT employee_pk PRIMARY KEY (EMP_ID) --Non compliant code
);

Compliant Code Example

Create TABLE EMPLOYEE 
(
  EMP_ID number(10) NOT NULL,
  FIRSTNAME NVARCHAR2(75),
  LASTNAME NVARCHAR2(75),
  DEPT_ID int,  
  ADDRESS NVARCHAR2(250) NOT NULL,

  CONSTRAINT pk_employee PRIMARY KEY (EMP_ID)   --Compliant code
);
Visual Expert 2024
 VEPLSQLRULE183