on master help sign in
update tutd tutorial with lowercase Date relvars
ad7a300AgentM
docs/tutd_tutorial.markdown+64−64
@@ -32,11 +32,11 @@ With regards to boolean values, be sure not to conflate ```t``` or ```f``` as a
32Project:M36 will complain loudly if the expected types do not match. Automatic type coercion does not exist.
32Project:M36 will complain loudly if the expected types do not match. Automatic type coercion does not exist.
33
33
34```
34```
35−TutorialD (master): :showexpr S:{more:=add(10,@SNAME)}
35+TutorialD (master): :showexpr S:{more:=add(10,@sname)}
36ERR: AtomFunctionTypeError "add" 2 IntAtomType StringAtomType
36ERR: AtomFunctionTypeError "add" 2 IntAtomType StringAtomType
37```
37```
38
38
39−The integer "10" cannot be added to the string SNAME value.
39+The integer "10" cannot be added to the string sname value.
40
40
41### Using Relation Variables
41### Using Relation Variables
42
42
@@ -75,18 +75,18 @@ Each section assumes a fresh instance of the Date examples. The relation variabl
75
75
76|Relation Variable Name|Description|
76|Relation Variable Name|Description|
77|----------------------|-----------|
77|----------------------|-----------|
78−|S|suppliers|
78+|s|suppliers|
79−|P|parts|
79+|p|parts|
80−|SP|contains mapping of which suppliers supply which parts|
80+|sp|contains mapping of which suppliers supply which parts|
81
81
82### Relational Expressions
82### Relational Expressions
83
83
84−A relational expression combines relational operators to create a new relation. ```tutd``` can display the result of executing a relational expression with ":showexpr".
84+A relational expression combines relational operators to create a new relation. ```tutd``` can display the result of executing a relational expression with ":showexpr".
85
85
86```
86```
87−TutorialD (master): :showexpr P
87+TutorialD (master): :showexpr p
88┌──────┬─────┬──┬─────┬──────┐
88┌──────┬─────┬──┬─────┬──────┐
89−│CITY │COLOR│P#│PNAME│WEIGHT│
89+│city │color│p#│pname│weight│
90├──────┼─────┼──┼─────┼──────┤
90├──────┼─────┼──┼─────┼──────┤
91│London│Red │P6│Cog │19 │
91│London│Red │P6│Cog │19 │
92│Paris │Blue │P5│Cam │12 │
92│Paris │Blue │P5│Cam │12 │
@@ -99,16 +99,16 @@ TutorialD (master): :showexpr P
99
99
100### Using Relational Operators
100### Using Relational Operators
101
101
102−Relational operators generate new relations from existing relations. The operators form the closed algebra against relations.
102+Relational operators generate new relations from existing relations. The operators form the closed algebra against relations.
103
103
104#### Rename
104#### Rename
105
105
106The unary rename operator outputs a new relation with chosen attributes renamed. In SQL, the equivalent is to use "AS" in the column name list of SELECTS.
106The unary rename operator outputs a new relation with chosen attributes renamed. In SQL, the equivalent is to use "AS" in the column name list of SELECTS.
107
107
108```
108```
109−TutorialD (master): :showexpr S rename {CITY as TOWN}
109+TutorialD (master): :showexpr s rename {city as town}
110┌──┬─────┬──────┬──────┐
110┌──┬─────┬──────┬──────┐
111−│S#│SNAME│STATUS│TOWN │
111+│s#│sname│status│town │
112├──┼─────┼──────┼──────┤
112├──┼─────┼──────┼──────┤
113│S3│Blake│30 │Paris │
113│S3│Blake│30 │Paris │
114│S4│Clark│20 │London│
114│S4│Clark│20 │London│
@@ -125,9 +125,9 @@ Projection is applied by adding curly braces and attribute names following a rel
125For example:
125For example:
126
126
127```
127```
128−TutorialD (master): :showexpr P{COLOR,CITY}
128+TutorialD (master): :showexpr p{color,city}
129┌──────┬─────┐
129┌──────┬─────┐
130−│CITY │COLOR│
130+│city │color│
131├──────┼─────┤
131├──────┼─────┤
132│London│Red │
132│London│Red │
133│Paris │Blue │
133│Paris │Blue │
@@ -141,9 +141,9 @@ TutorialD (master): :showexpr P{COLOR,CITY}
141Restriction is applied using a "where" clause, much like in SQL.
141Restriction is applied using a "where" clause, much like in SQL.
142
142
143```
143```
144−TutorialD (master): :showexpr P where COLOR="Blue" and CITY="Paris"
144+TutorialD (master): :showexpr p where color="Blue" and city="Paris"
145┌─────┬─────┬──┬─────┬──────┐
145┌─────┬─────┬──┬─────┬──────┐
146−│CITY │COLOR│P#│PNAME│WEIGHT│
146+│city │color│p#│pname│weight│
147├─────┼─────┼──┼─────┼──────┤
147├─────┼─────┼──┼─────┼──────┤
148│Paris│Blue │P5│Cam │12 │
148│Paris│Blue │P5│Cam │12 │
149└─────┴─────┴──┴─────┴──────┘
149└─────┴─────┴──┴─────┴──────┘
@@ -152,9 +152,9 @@ TutorialD (master): :showexpr P where COLOR="Blue" and CITY="Paris"
152The restriction predicate can be built from "and", "not", and "or". Boolean atom functions can also appear in a restriction as long as they are preceded by "^". For example:
152The restriction predicate can be built from "and", "not", and "or". Boolean atom functions can also appear in a restriction as long as they are preceded by "^". For example:
153
153
154```
154```
155−TutorialD (master): :showexpr S where ^lt(@STATUS,20)
155+TutorialD (master): :showexpr s where ^lt(@status,20)
156┌─────┬──┬─────┬──────┐
156┌─────┬──┬─────┬──────┐
157−│CITY │S#│SNAME│STATUS│
157+│city │s#│sname│status│
158├─────┼──┼─────┼──────┤
158├─────┼──┼─────┼──────┤
159│Paris│S2│Jones│10 │
159│Paris│S2│Jones│10 │
160└─────┴──┴─────┴──────┘
160└─────┴──┴─────┴──────┘
@@ -165,9 +165,9 @@ TutorialD (master): :showexpr S where ^lt(@STATUS,20)
165Joins are binary operators and are applied with the "join" keyword. The equivalent in SQL would be a "NATURAL JOIN". To join attributes which are not identically-named, use the rename operator
165Joins are binary operators and are applied with the "join" keyword. The equivalent in SQL would be a "NATURAL JOIN". To join attributes which are not identically-named, use the rename operator
166
166
167```
167```
168−TutorialD (master): :showexpr S join SP
168+TutorialD (master): :showexpr s join sp
169┌──────┬──┬───┬──┬─────┬──────┐
169┌──────┬──┬───┬──┬─────┬──────┐
170−│CITY │P#│QTY│S#│SNAME│STATUS│
170+│city │p#│QTY│s#│sname│status│
171├──────┼──┼───┼──┼─────┼──────┤
171├──────┼──┼───┼──┼─────┼──────┤
172│London│P6│100│S1│Smith│20 │
172│London│P6│100│S1│Smith│20 │
173│London│P3│400│S1│Smith│20 │
173│London│P3│400│S1│Smith│20 │
@@ -190,7 +190,7 @@ The binary union operator merges tuples from both relations if-and-only-if the a
190```
190```
191TutorialD (master): :showexpr S union S
191TutorialD (master): :showexpr S union S
192┌──────┬──┬─────┬──────┐
192┌──────┬──┬─────┬──────┐
193−│CITY │S#│SNAME│STATUS│
193+│city │s#│sname│status│
194├──────┼──┼─────┼──────┤
194├──────┼──┼─────┼──────┤
195│Paris │S3│Blake│30 │
195│Paris │S3│Blake│30 │
196│London│S4│Clark│20 │
196│London│S4│Clark│20 │
@@ -207,9 +207,9 @@ The union of any relation with itself is itself.
207The extend unary operator adds an attribute to a relation's header and body and is represented by a colon ":". The equivalent in SQL is a subselect in a SELECT column list. Typically, extend is used to add information derived from relation.
207The extend unary operator adds an attribute to a relation's header and body and is represented by a colon ":". The equivalent in SQL is a subselect in a SELECT column list. Typically, extend is used to add information derived from relation.
208
208
209```
209```
210−TutorialD (master): :showexpr S:{STATUS2:=add(10,@STATUS)}
210+TutorialD (master): :showexpr s:{status2:=add(10,@status)}
211┌──────┬──┬─────┬──────┬───────┐
211┌──────┬──┬─────┬──────┬───────┐
212−│CITY │S#│SNAME│STATUS│STATUS2│
212+│city │s#│sname│status│status2│
213├──────┼──┼─────┼──────┼───────┤
213├──────┼──┼─────┼──────┼───────┤
214│Paris │S2│Jones│10 │20 │
214│Paris │S2│Jones│10 │20 │
215│Athens│S5│Adams│30 │40 │
215│Athens│S5│Adams│30 │40 │
@@ -239,23 +239,23 @@ The unary group operator groups the argument attributes into subrelations for ea
239Grouping is useful for aggregate operations (see below) or for summarizing data against a set of attributes; for example, "display all employees grouped by boss name".
239Grouping is useful for aggregate operations (see below) or for summarizing data against a set of attributes; for example, "display all employees grouped by boss name".
240
240
241```
241```
242−TutorialD (master): :showexpr S group ({SNAME,STATUS,S#} as subrel)
242+TutorialD (master): :showexpr s group ({sname,status,s#} as subrel)
243┌──────┬─────────────────┐
243┌──────┬─────────────────┐
244−│CITY │subrel │
244+│city │subrel │
245├──────┼─────────────────┤
245├──────┼─────────────────┤
246│Athens│┌──┬─────┬──────┐│
246│Athens│┌──┬─────┬──────┐│
247−│ ││S#│SNAME│STATUS││
247+│ ││s#│sname│status││
248│ │├──┼─────┼──────┤│
248│ │├──┼─────┼──────┤│
249│ ││S5│Adams│30 ││
249│ ││S5│Adams│30 ││
250│ │└──┴─────┴──────┘│
250│ │└──┴─────┴──────┘│
251│London│┌──┬─────┬──────┐│
251│London│┌──┬─────┬──────┐│
252−│ ││S#│SNAME│STATUS││
252+│ ││s#│sname│status││
253│ │├──┼─────┼──────┤│
253│ │├──┼─────┼──────┤│
254│ ││S1│Smith│20 ││
254│ ││S1│Smith│20 ││
255│ ││S4│Clark│20 ││
255│ ││S4│Clark│20 ││
256│ │└──┴─────┴──────┘│
256│ │└──┴─────┴──────┘│
257│Paris │┌──┬─────┬──────┐│
257│Paris │┌──┬─────┬──────┐│
258−│ ││S#│SNAME│STATUS││
258+│ ││s#│sname│status││
259│ │├──┼─────┼──────┤│
259│ │├──┼─────┼──────┤│
260│ ││S3│Blake│30 ││
260│ ││S3│Blake│30 ││
261│ ││S2│Jones│10 ││
261│ ││S2│Jones│10 ││
@@ -268,9 +268,9 @@ TutorialD (master): :showexpr S group ({SNAME,STATUS,S#} as subrel)
268The unary ungroup operator "unwraps" subrelations in a relation-valued attribute. There is no equivalent in SQL.
268The unary ungroup operator "unwraps" subrelations in a relation-valued attribute. There is no equivalent in SQL.
269
269
270```
270```
271−TutorialD (master): :showexpr (S group ({SNAME,STATUS,S#} as subrel)) ungroup subrel
271+TutorialD (master): :showexpr (s group ({sname,status,s#} as subrel)) ungroup subrel
272┌──────┬──┬─────┬──────┐
272┌──────┬──┬─────┬──────┐
273−│CITY │S#│SNAME│STATUS│
273+│city │s#│sname│status│
274├──────┼──┼─────┼──────┤
274├──────┼──┼─────┼──────┤
275│Paris │S3│Blake│30 │
275│Paris │S3│Blake│30 │
276│London│S4│Clark│20 │
276│London│S4│Clark│20 │
@@ -288,11 +288,11 @@ While relational operators compose to relational expressions representing querie
288
288
289#### Define and Assign
289#### Define and Assign
290
290
291−The relation assignment mentioned above certainly changes the state of the database.
291+The relation variable assignment mentioned above certainly changes the state of the database.
292
292
293```
293```
294−TutorialD (master): newrel:=relation{tuple{age 3}}
294+TutorialD (master): newrelvar:=relation{tuple{age 3}}
295−TutorialD (master): :showexpr newrel
295+TutorialD (master): :showexpr newrelvar
296┌───┐
296┌───┐
297│age│
297│age│
298├───┤
298├───┤
@@ -307,9 +307,9 @@ All further operators are convenience operators and could be implemented with si
307To signal that a relation variable should be forgotten, undefine it.
307To signal that a relation variable should be forgotten, undefine it.
308
308
309```
309```
310−TutorialD (master): undefine S
310+TutorialD (master): undefine s
311−TutorialD (master): :showexpr S
311+TutorialD (master): :showexpr s
312−ERR: RelVarNotDefinedError "S"
312+ERR: RelVarNotDefinedError "s"
313```
313```
314
314
315#### Insert
315#### Insert
@@ -317,10 +317,10 @@ ERR: RelVarNotDefinedError "S"
317The insert operators accepts a relation variable and a relation of the same type (a relation having an identical header), and replaces the relation referenced by the relation variable with the union of the previous relation value and the argument's relation value.
317The insert operators accepts a relation variable and a relation of the same type (a relation having an identical header), and replaces the relation referenced by the relation variable with the union of the previous relation value and the argument's relation value.
318
318
319```
319```
320−TutorialD (master): insert S relation{tuple{CITY "Boston",S# "S10",SNAME "Gonzalez",STATUS 10}}
320+TutorialD (master): insert s relation{tuple{city "Boston",s# "S10",sname "Gonzalez",status 10}}
321−TutorialD (master): :showexpr S
321+TutorialD (master): :showexpr s
322┌──────┬───┬────────┬──────┐
322┌──────┬───┬────────┬──────┐
323−│CITY │S# │SNAME │STATUS│
323+│city │s# │sname │status│
324├──────┼───┼────────┼──────┤
324├──────┼───┼────────┼──────┤
325│Paris │S3 │Blake │30 │
325│Paris │S3 │Blake │30 │
326│London│S4 │Clark │20 │
326│London│S4 │Clark │20 │
@@ -334,17 +334,17 @@ TutorialD (master): :showexpr S
334This insertion operation is equivalent to:
334This insertion operation is equivalent to:
335
335
336```
336```
337−S:=S union relation{tuple{CITY "Boston",S# "S10",SNAME "Gonzalez",STATUS 10}}
337+s:=s union relation{tuple{city "Boston",s# "S10",sname "Gonzalez",status 10}}
338```
338```
339#### Update
339#### Update
340
340
341The update operator accepts a relation argument and a predicate, optionally filters and creates new tuples based on the original relation.
341The update operator accepts a relation argument and a predicate, optionally filters and creates new tuples based on the original relation.
342
342
343```
343```
344−TutorialD (master): update S where STATUS=20 (SNAME:="Mr. Twenty")
344+TutorialD (master): update s where status=20 (sname:="Mr. Twenty")
345−TutorialD (master): :showexpr S
345+TutorialD (master): :showexpr s
346┌──────┬──┬──────────┬──────┐
346┌──────┬──┬──────────┬──────┐
347−│CITY │S#│SNAME │STATUS│
347+│city │s#│sname │status│
348├──────┼──┼──────────┼──────┤
348├──────┼──┼──────────┼──────┤
349│Paris │S3│Blake │30 │
349│Paris │S3│Blake │30 │
350│London│S1│Mr. Twenty│20 │
350│London│S1│Mr. Twenty│20 │
@@ -357,10 +357,10 @@ TutorialD (master): :showexpr S
357This is logically equivalent to:
357This is logically equivalent to:
358
358
359```
359```
360−TutorialD (master): S:=(((S where STATUS=20){CITY,S#,STATUS}):{SNAME:="Mr. Twenty"}) union (S where not STATUS=20)
360+TutorialD (master): s:=(((s where status=20){city,s#,status}):{sname:="Mr. Twenty"}) union (s where not status=20)
361−TutorialD (master): :showexpr S
361+TutorialD (master): :showexpr s
362┌──────┬──┬──────────┬──────┐
362┌──────┬──┬──────────┬──────┐
363−│CITY │S#│SNAME │STATUS│
363+│city │s#│sname │status│
364├──────┼──┼──────────┼──────┤
364├──────┼──┼──────────┼──────┤
365│Paris │S3│Blake │30 │
365│Paris │S3│Blake │30 │
366│London│S1│Mr. Twenty│20 │
366│London│S1│Mr. Twenty│20 │
@@ -370,17 +370,17 @@ TutorialD (master): :showexpr S
370└──────┴──┴──────────┴──────┘
370└──────┴──┴──────────┴──────┘
371```
371```
372
372
373−This query means: "Drop the SNAME attribute from S filtered where STATUS equals 20, extend the resultant relation by SNAME with value 'Mr. Twenty', then union the resultant relation with S filtered by STATUS not equaling 20, and assign that to S."
373+This query means: "Drop the sname attribute from S filtered where status equals 20, extend the resultant relation by sname with value 'Mr. Twenty', then union the resultant relation with S filtered by status not equaling 20, and assign that to S."
374
374
375#### Delete
375#### Delete
376
376
377The delete operator accepts a relation argument and a filtering predicate, creates a new relation with only the tuples which do not match the predicate, and stores the result in the relation variable argument.
377The delete operator accepts a relation argument and a filtering predicate, creates a new relation with only the tuples which do not match the predicate, and stores the result in the relation variable argument.
378
378
379```
379```
380−TutorialD (master): delete SP where S#="S4"
380+TutorialD (master): delete sp where s#="S4"
381−TutorialD (master): :showexpr SP
381+TutorialD (master): :showexpr sp
382┌──┬───┬──┐
382┌──┬───┬──┐
383−│P#│QTY│S#│
383+│p#│QTY│s#│
384├──┼───┼──┤
384├──┼───┼──┤
385│P3│400│S1│
385│P3│400│S1│
386│P4│200│S1│
386│P4│200│S1│
@@ -397,7 +397,7 @@ TutorialD (master): :showexpr SP
397This is logically equivalent to:
397This is logically equivalent to:
398
398
399```
399```
400−TutorialD (master): SP:=SP where not S#="S4"
400+TutorialD (master): sp:=sp where not s#="S4"
401```
401```
402
402
403Note the inverted predicate.
403Note the inverted predicate.
@@ -413,56 +413,56 @@ Chris Date identified that all constraints can be represented as inclusion depen
413Uniqueness constraints ensure that a set of attributes' values are unique throughout a relational expression. For example, it is useful to ensure that all products' identifiers are unique. The equivalent in SQL is the UNIQUE expression found in table creation.
413Uniqueness constraints ensure that a set of attributes' values are unique throughout a relational expression. For example, it is useful to ensure that all products' identifiers are unique. The equivalent in SQL is the UNIQUE expression found in table creation.
414
414
415```
415```
416−TutorialD (master): key S_key_constraint {S#} S
416+TutorialD (master): key s_key_constraint {s#} s
417```
417```
418
418
419−This expression creates a constraint named "S_key_constraint" and ensure that the values of the "S#" attribute are unique in the "S" relational expression.
419+This expression creates a constraint named "S_key_constraint" and ensure that the values of the "s#" attribute are unique in the "S" relational expression.
420
420
421#### Foreign Key Constraints
421#### Foreign Key Constraints
422
422
423Foreign keys are constraints which require that certain values appearing in one relation variable must appear in another. The equivalent in SQL is the FOREIGN KEY() construction in table creation.
423Foreign keys are constraints which require that certain values appearing in one relation variable must appear in another. The equivalent in SQL is the FOREIGN KEY() construction in table creation.
424
424
425```
425```
426−TutorialD (master): foreign key S#_in_SP SP{S#} in S{S#}
426+TutorialD (master): foreign key s#_in_sp sp{s#} in s{s#}
427```
427```
428
428
429−This expression ensure that any SP{S#} must also appear as a value in S{S#}.
429+This expression ensure that any sp{s#} must also appear as a value in s{s#}.
430
430
431#### Other Constraints
431#### Other Constraints
432
432
433All other constraints can be represented by a set of inclusion dependencies.
433All other constraints can be represented by a set of inclusion dependencies.
434
434
435```
435```
436−TutorialD (master): constraint S_status_less_than_50 (S where ^lt(50,@STATUS)){} in false
436+TutorialD (master): constraint s_status_less_than_50 (s where ^lt(50,@status)){} in false
437```
437```
438
438
439−This expression ensures that the relation variable's relation can never include a tuple with STATUS greater than 50.
439+This expression ensures that the relation variable's relation can never include a tuple with status greater than 50.
440
440
441## Aggregate Queries
441## Aggregate Queries
442
442
443−Aggregate queries in TutorialD are able to provide much more information than SQL queries due to the support for relation-valued attributes. For example, a single query can return aggregate results alongside its constituent tuples.
443+Aggregate queries in TutorialD are able to provide much more information than SQL queries due to the support for relation-valued attributes. For example, a single query can return aggregate results alongside its constituent tuples.
444
444
445−SQL supports aggregate queries using aggregate functions (SUM(), COUNT(), AVERAGE(), etc.) and GROUP BY while the aggregate functions in the relational algebra simply accept relation values as arguments.
445+SQL supports aggregate queries using aggregate functions (SUM(), COUNT(), AVERAGE(), etc.) and GROUP BY while the aggregate functions in the relational algebra simply accept relation values as arguments.
446
446
447```
447```
448−TutorialD (master): :showexpr S group ({S#,SNAME,STATUS} as subrel):{citycount:=count(@subrel)}
448+TutorialD (master): :showexpr s group ({s#,sname,status} as subrel):{citycount:=count(@subrel)}
449┌──────┬─────────┬─────────────────┐
449┌──────┬─────────┬─────────────────┐
450−│CITY │citycount│subrel │
450+│city │citycount│subrel │
451├──────┼─────────┼─────────────────┤
451├──────┼─────────┼─────────────────┤
452│Paris │2 │┌──┬─────┬──────┐│
452│Paris │2 │┌──┬─────┬──────┐│
453−│ │ ││S#│SNAME│STATUS││
453+│ │ ││s#│sname│status││
454│ │ │├──┼─────┼──────┤│
454│ │ │├──┼─────┼──────┤│
455│ │ ││S3│Blake│30 ││
455│ │ ││S3│Blake│30 ││
456│ │ ││S2│Jones│10 ││
456│ │ ││S2│Jones│10 ││
457│ │ │└──┴─────┴──────┘│
457│ │ │└──┴─────┴──────┘│
458│London│2 │┌──┬─────┬──────┐│
458│London│2 │┌──┬─────┬──────┐│
459−│ │ ││S#│SNAME│STATUS││
459+│ │ ││s#│sname│status││
460│ │ │├──┼─────┼──────┤│
460│ │ │├──┼─────┼──────┤│
461│ │ ││S1│Smith│20 ││
461│ │ ││S1│Smith│20 ││
462│ │ ││S4│Clark│20 ││
462│ │ ││S4│Clark│20 ││
463│ │ │└──┴─────┴──────┘│
463│ │ │└──┴─────┴──────┘│
464│Athens│1 │┌──┬─────┬──────┐│
464│Athens│1 │┌──┬─────┬──────┐│
465−│ │ ││S#│SNAME│STATUS││
465+│ │ ││s#│sname│status││
466│ │ │├──┼─────┼──────┤│
466│ │ │├──┼─────┼──────┤│
467│ │ ││S5│Adams│30 ││
467│ │ ││S5│Adams│30 ││
468│ │ │└──┴─────┴──────┘│
468│ │ │└──┴─────┴──────┘│
@@ -476,4 +476,4 @@ In this query result, we can simultaneously answer how many suppliers are locate
476|count(relation{any tuple types})|return the number of tuples in each relation value|
476|count(relation{any tuple types})|return the number of tuples in each relation value|
477|sum(relation{int})|return the int sum of the relation's values|
477|sum(relation{int})|return the int sum of the relation's values|
478|max(relation{int})|return the maximum int from all the relation's values|
478|max(relation{int})|return the maximum int from all the relation's values|
479−|min(relation{int})|return the minimum int from all the relation's values|
479+|min(relation{int})|return the minimum int from all the relation's values|
scripts/DateExamples.tutd+1−1
@@ -1,5 +1,5 @@
1s := relation{tuple{s# "S1",sname "Smith",status 20, city "London"}, tuple{s# "S2",sname "Jones",status 10,city "Paris"}, tuple{s# "S3",sname "Blake",status 30,city "Paris"}, tuple{s# "S4",sname "Clark",status 20,city "London"}, tuple{s# "S5",sname "Adams",status 30,city "Athens"}}
1s := relation{tuple{s# "S1",sname "Smith",status 20, city "London"}, tuple{s# "S2",sname "Jones",status 10,city "Paris"}, tuple{s# "S3",sname "Blake",status 30,city "Paris"}, tuple{s# "S4",sname "Clark",status 20,city "London"}, tuple{s# "S5",sname "Adams",status 30,city "Athens"}}
2−p := relation{tuple{p# "P1",PNAME "Nut",COLOR "Red",WEIGHT 12,city "London"}, tuple{p# "P2",PNAME "Bolt",COLOR "Green",WEIGHT 17,city "Paris"}, tuple{p# "P3",PNAME "Screw",COLOR "Blue",WEIGHT 17,city "Oslo"}, tuple{p# "P4",PNAME "Screw",COLOR "Red",WEIGHT 14,city "London"}, tuple{p# "P5",PNAME "Cam",COLOR "Blue",WEIGHT 12,city "Paris"}, tuple{p# "P6", PNAME "Cog", COLOR "Red",WEIGHT 19,city "London"}}
2+p := relation{tuple{p# "P1",pname "Nut",color "Red",weight 12,city "London"}, tuple{p# "P2",pname "Bolt",color "Green",weight 17,city "Paris"}, tuple{p# "P3",pname "Screw",color "Blue",weight 17,city "Oslo"}, tuple{p# "P4",pname "Screw",color "Red",weight 14,city "London"}, tuple{p# "P5",pname "Cam",color "Blue",weight 12,city "Paris"}, tuple{p# "P6", pname "Cog", color "Red",weight 19,city "London"}}
3sp := relation{tuple{s# "S1",p# "P1",qty 300}, tuple{s# "S1",p# "P2",qty 200}, tuple{s# "S1",p# "P3",qty 400}, tuple{s# "S1",p# "P4",qty 200}, tuple{s# "S1",p# "P5",qty 100}, tuple{s# "S1",p# "P6",qty 100}, tuple{s# "S2",p# "P1",qty 300}, tuple{s# "S2",p# "P2",qty 400}, tuple{s# "S3",p# "P2",qty 200}, tuple{s# "S4",p# "P4",qty 300}, tuple{s# "S4",p# "P5",qty 400}}
3sp := relation{tuple{s# "S1",p# "P1",qty 300}, tuple{s# "S1",p# "P2",qty 200}, tuple{s# "S1",p# "P3",qty 400}, tuple{s# "S1",p# "P4",qty 200}, tuple{s# "S1",p# "P5",qty 100}, tuple{s# "S1",p# "P6",qty 100}, tuple{s# "S2",p# "P1",qty 300}, tuple{s# "S2",p# "P2",qty 400}, tuple{s# "S3",p# "P2",qty 200}, tuple{s# "S4",p# "P4",qty 300}, tuple{s# "S4",p# "P5",qty 400}}
4foreign key sp2s sp{s#} in s{s#}
4foreign key sp2s sp{s#} in s{s#}
5foreign key sp2p sp{p#} in p{p#}
5foreign key sp2p sp{p#} in p{p#}