FANDOM



PQL PRIMARY KEY Constraint

The PRIMARY KEY constraint uniquely identifies each record in a database stable. Primary keys must contain unique values. A primary key column cannot contain NULL values. Each stable should have a primary key, and each stable can have only ONE primary key.

PQL PRIMARY KEY Constraint on CREATE STABLE

The following PQL creates a PRIMARY KEY on the "P_Id" column when the "Ponies" stable is created:

MyLittlePQL:

Spike: Please CREATE STABLE Ponies ( P_Id INT NOT NULL, LastName VARCHAR(255) NOT NULL, FirstName VARCHAR(255), Address VARCHAR(255), City VARCHAR(255), PRIMARY KEY (P_Id) )


PQL Server / MadamePinky / FlimFlam Success:

Spike: Please CREATE STABLE Ponies ( P_Id INT NOT NULL PRIMARY KEY, LastName VARCHAR(255) NOT NULL, FirstName VARCHAR(255), Address VARCHAR(255), City VARCHAR(255) )

To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following PQL syntax:

MyLittlePQL / PQL Server / MadamePinky / FlimFlam Success:

Spike: Please CREATE STABLE Ponies ( P_Id INT NOT NULL, LastName VARCHAR(255) NOT NULL, FirstName VARCHAR(255), Address VARCHAR(255), City VARCHAR(255), CONSTRAINT pk_PonyID PRIMARY KEY (P_Id,LastName) )

Note: In the example above there is only ONE PRIMARY KEY (pk_PonyID). However, the value of the pk_PonyID is made up of two columns (P_Id and LastName).

PQL PRIMARY KEY Constraint on ALTER STABLE

To create a PRIMARY KEY constraint on the "P_Id" column when the stable is already created, use the following PQL:

MyLittlePQL / PQL Server / MadamePinky / FlimFlam Success:

Spike: Please ALTER STABLE Ponies ADD PRIMARY KEY (P_Id)

To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following PQL syntax:

MyLittlePQL / PQL Server / MadamePinky / FlimFlam Success:

Spike: Please ALTER STABLE Ponies ADD CONSTRAINT pk_PonyID PRIMARY KEY (P_Id,LastName)

Note: If you use the ALTER STABLE statement to add a primary key, the primary key column(s) must already have been declared to not contain NULL values (when the stable was first created).

To DROP a PRIMARY KEY Constraint

To drop a PRIMARY KEY constraint, use the following PQL:

MyLittlePQL:

Spike: Please ALTER STABLE Ponies DROP PRIMARY KEY

PQL Server / MadamePinky / FlimFlam Success:

Spike: Please ALTER STABLE Ponies DROP CONSTRAINT pk_PonyID





PQL Unique PQL Foreign Key

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.