Data

Example data

We can assign relation values to relation variables (relvars), using := to declare and assign. Here we'll build the following relvars which we'll use throughout the documentation:

S := {SNO:str  SNAME:str  STATUS:int  CITY:str}{
     ["S1",    "Smith",   20,         "London"]
     ["S2",    "Jones",   10,         "Paris"]
     ["S3",    "Blake",   30,         "Paris"]
     ["S4",    "Clark",   20,         "London"]
     ["S5",    "Adams",   30,         "Athens"]
}

P := {PNO:str PNAME:str COLOR:str WEIGHT:int CITY:str}{
     ["P1",   "Nut",    "Red",    12,        "London"]
     ["P2",   "Bolt",   "Green",  17,        "Paris"]
     ["P3",   "Screw",  "Blue",   17,        "Rome"]
     ["P4",   "Screw",  "Red",    14,        "London"]
     ["P5",   "Cam",    "Blue",   12,        "Paris"]
     ["P6",   "Cog",    "Red",    19,        "London"]
}

SP := {SNO:str PNO:str QTY:int}{
      ["S1",   "P1",   300]
      ["S1",   "P2",   200]
      ["S1",   "P3",   400]
      ["S1",   "P4",   200]
      ["S1",   "P5",   100]
      ["S1",   "P6",   100]
      ["S2",   "P1",   300]
      ["S2",   "P2",   400]
      ["S3",   "P2",   200]
      ["S4",   "P2",   200]
      ["S4",   "P4",   300]
      ["S4",   "P5",   400]
}

Then we can add some integrity constraints to ensure our data remains valid. We'll go over these in a later section.

Constraint := {name:str rule: str}{
    ["Constraint_key", "key(Constraint, {name})"],

    ["S_key", "key(S, {SNO})"],
    ["P_key", "key(P, {PNO})"],
    ["SP_key", "key(SP, {SNO,PNO})"],

    ["S_SP_FK", "SP{SNO} ⊆ S{SNO}"],
    ["P_SP_FK", "SP{PNO} ⊆ P{PNO}"],
}

We can display the relvar values, in this case as HTML tables, but note that the left-to-right ordering is arbitrary as is the top-to-bottom order of the tuples. We'll introduce operators to specify both of these orderings later, purely for output purposes, because after that point we'll no longer be dealing with relations. Again, relations have no attribute or tuple order to them.

S
SNOSNAMESTATUSCITY
S1Smith20London
S2Jones10Paris
S3Blake30Paris
S4Clark20London
S5Adams30Athens
P
PNOPNAMECOLORWEIGHTCITY
P1NutRed12London
P2BoltGreen17Paris
P3ScrewBlue17Rome
P4ScrewRed14London
P5CamBlue12Paris
P6CogRed19London
SP
SNOPNOQTY
S1P1300
S1P2200
S1P3400
S1P4200
S1P5100
S1P6100
S2P1300
S2P2400
S3P2200
S4P2200
S4P4300
S4P5400
Constraint
namerule
Constraint_keykey(Constraint, {name})
P_SP_FKSP{PNO} ⊆ P{PNO}
P_keykey(P, {PNO})
SP_keykey(SP, {SNO,PNO})
S_SP_FKSP{SNO} ⊆ S{SNO}
S_keykey(S, {SNO})