Home

A primary key should be specified during table creation

Rule description

  • A primary key should be specified during table creation

 

Non-compliant Code Example

Create TABLE EMPLOYEE --Non compliant code (Table definition without primary key)
(
  ID number(10) NOT NULL,
  FIRSTNAME NVARCHAR2(75),
  LASTNAME NVARCHAR2(75),
  DEPT_ID int,  
  ADDRESS NVARCHAR2(250) NOT NULL
);

Compliant Code Example

Create TABLE EMPLOYEE --Compliant code (Table definition with primary key)
(
  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)
);
Visual Expert 2020
 VEPLSQLRULE135