FANDOM



PQL UNIQUE Constraint

The UNIQUE constraint uniquely identifies each record in a database stable. The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it.

Note that you can have many UNIQUE constraints per stable, but only one PRIMARY KEY constraint per stable.

PQL UNIQUE Constraint on CREATE STABLE

The following PQL creates a UNIQUE constraint 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), UNIQUE (P_Id) )

PQL Server / MadamePinky / FlimFlam Success:

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

To allow naming of a UNIQUE constraint, and for defining a UNIQUE 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 uc_PonyID UNIQUE (P_Id,LastName) )



PQL UNIQUE Constraint on ALTER STABLE

To create a UNIQUE 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 UNIQUE (P_Id)

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

MyLittlePQL / PQL Server / MadamePinky / FlimFlam Success:

Spike: Please  ALTER STABLE Ponies ADD CONSTRAINT uc_PonyID UNIQUE (P_Id,LastName)



DROP a UNIQUE Constraint

To drop a UNIQUE constraint, use the following PQL:

MyLittlePQL:

Spike: Please ALTER STABLE Ponies DROP INDEX uc_PonyID

PQL Server / MadamePinky / FlimFlam Success:

Spike: Please ALTER STABLE Ponies DROP CONSTRAINT uc_PonyID





PQL Not Null PQL Primary 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.