Home

SQL Keywords: PRIMARY

  

Introduction

The PRIMARY keyword is used with the KEY keyword to create a primary key on a column. Here is an example:

CREATE TABLE Genders(GenderID COUNTER(1,1) PRIMARY KEY NOT NULL,
                     Gender varchar(20));

Here is an example that uses the CONSTRAINT keyword:

CREATE TABLE Persons(PersonID COUNTER(1,1) NOT NULL,
                     FirstName varchar(20),
                     LastName varchar(20) NOT NULL,
                     CONSTRAINT PrimKeyPeople PRIMARY KEY(PersonID));

By convention or tradition, the name of the primary starts with PK_ followed by the name of the table. Here is an example:

CREATE TABLE Persons(PersonID COUNTER(1,1) NOT NULL,
                     FirstName varchar(20),
                     LastName varchar(20) NOT NULL,
                     CONSTRAINT PK_People PRIMARY KEY(PersonID));

Home Copyright © 2009-2016, FunctionX, Inc.