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
(
  employee_id int NOT NULL,  --Non compliant code
  first_name VARCHAR(42) NOT NULL,
  last_name VARCHAR(42) NOT NULL
);

Compliant Code Example

CREATE TABLE Employee
(
  employee_id int IDENTITY(1,1) PRIMARY KEY,  --Compliant code
  first_name VARCHAR(42) NOT NULL,
  last_name VARCHAR(42) NOT NULL
);
Visual Expert 2020
 VETSQLRULE57