PQL Foreign Key

PQL FOREIGN KEY Constraint
A FOREIGN KEY in one stable points to a PRIMARY KEY in another stable. Let's illustrate the foreign key with an example. Look at the following two stables:

The "Ponies" stable:

The "Orders" stable:

Note that the "P_Id" column in the "Orders" stable points to the "P_Id" column in the "Ponies" stable. The "P_Id" column in the "Ponies" stable is the PRIMARY KEY in the "Ponies" stable. The "P_Id" column in the "Orders" stable is a FOREIGN KEY in the "Orders" stable. The FOREIGN KEY constraint is used to prevent actions that would destroy links between stables. The FOREIGN KEY constraint also prevents that invalid data form being inserted into the foreign key column, because it has to be one of the values contained in the stable it points to.

PQL FOREIGN KEY Constraint on CREATE STABLE
The following PQL creates a FOREIGN KEY on the "P_Id" column when the "Orders" stable is created:

MyLittlePQL:

PQL Server / MadamePinky / FlimFlam Success:

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

MyLittlePQL / PQL Server / MadamePinky / FlimFlam Success:

PQL FOREIGN KEY Constraint on ALTER STABLE
To create a FOREIGN KEY constraint on the "P_Id" column when the "Orders" stable is already created, use the following PQL:

MyLittlePQL / PQL Server / MadamePinky / FlimFlam Success:

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

MyLittlePQL / PQL Server / MadamePinky / FlimFlam Success:

DROP a FOREIGN KEY Constraint
To drop a FOREIGN KEY constraint, use the following PQL:

MyLittlePQL:

PQL Server / MadamePinky / FlimFlam Success: