@@ -16,7 +16,7 @@ Let us begin by starting with the smallest units in the relational model and wor
1616
1717A value is a typed, singular unit of data.
1818
19−Common examples could be a number indicating a person's age, the number of dollars in a bank account, or a street address used for delivery. In all cases, a value must be of a specific type and must support the notion of equality.
19+Common examples could be a number indicating a person's age, the number of dollars in a bank account, or a street address used for delivery. In all cases, a value must be of a specific type and must support the notion of equality.
2020
2121As an example, it doesn't make sense to ask if a person's age is equal to a street address; the relational model can enforce this- this is called "type safety" and is the motivation for using types.
2222
@@ -38,11 +38,11 @@ An attribute is a pair containing an attribute name along with an attribute type
3838
3939Examples:
4040* An "Address" attribute name is of type "Text":
41−
41+
4242(Address, Text)
4343
4444* An "Current Balance" attribute name is of type "Dollar Amount":
45−
45+
4646(Current Balance, Dollar Amount)
4747
4848#### Tuple
@@ -62,7 +62,7 @@ In the last example, the fact that the car failed the inspection is implied by t
6262
6363#### Relation
6464
65−A relation is a container of values organized by tuples of the same type. Specifically, a relation is a set of attributes (a relation header) mapped over a set of tuples (a relation body). Note that this implies that tuples cannot appear more than once since a set can only hold unique items.
65+A relation is a container of values organized by tuples of the same type. Specifically, a relation is a set of attributes (a relation header) mapped over a set of tuples (a relation body). Note that this implies that tuples cannot appear more than once since a set can only hold unique items.
6666
6767When a tuple appears in a relation, a relation's attributes and respective types must match that of all of its tuples. Thus, a relation's header summarizes the attribute names and types of all of its constituent tuples.
6868
@@ -116,7 +116,7 @@ To reiterate, the transition from T1 to T2 replaced the "Employees" relation var
116116
117117#### Relational Operators
118118
119−Since we refer to the relational algebra as a closed algebra, all relational operators necessarily operate on and generate relations. The purpose of the operators is allow data modelers to answer questions (queries) based on the current state of the database. For example, a modeler may wish to know the ages of the employees working in the accounting department. The modeler can then compose the relational operators together to answer this and virtually any other conceivable query.
119+Since we refer to the relational algebra as a closed algebra, all relational operators necessarily operate on and generate relations. The purpose of the operators is allow data modelers to answer questions (queries) based on the current state of the database. For example, a modeler may wish to know the ages of the employees working in the accounting department. The modeler can then compose the relational operators together to answer this and virtually any other conceivable query.
120120
121121##### Project
122122
@@ -186,7 +186,7 @@ Note that rename does not alter the type of the attribute in question.
186186
187187##### Join
188188
189−One of the most essential-to-understand operators is the join operator. Unlike the previous two unary (single relation argument) operators, join operates on two (or potentially more) relations. The purpose of a join is to merge multiple relations into one relation in order to determine the relationships between data across relations. For example, there are good reasons (which have not yet been explained) why a relation representing a company's products and records of when those products were shipped should be two disparate relations. The join operators merges relation A and relation B by returning a new relation with the attribute sets of both relation headers merged and with a body of the tuples merged if-and-only-if the in-common attributes' values are equal.
189+One of the most essential-to-understand operators is the join operator. Unlike the previous two unary (single relation argument) operators, join operates on two (or potentially more) relations. The purpose of a join is to merge multiple relations into one relation in order to determine the relationships between data across relations. For example, there are good reasons (which have not yet been explained) why a relation representing a company's products and records of when those products were shipped should be two disparate relations. The join operators merges relation A and relation B by returning a new relation with the attribute sets of both relation headers merged and with a body of the tuples merged if-and-only-if the in-common attributes' values are equal.
190190
191191In the case where no attributes are in common between the relations, the join operator becomes a cross-product operator; this is not a special case, rather a logical consequence of the definition.
192192
@@ -208,7 +208,7 @@ Join (Instructor relation)
208208|French 2|Bob|Room 103|
209209|English 2|Steve|Room 104|
210210
211−["Instructor Name" is the in-common attribute]
211+["Instructor Name" is the in-common attribute]
212212===>
213213
214214|(Instructor Name, Instructor Name Type)|(Office Number, Office Number Type)|(Course Name, Course Name Type)|(Course Room Number, Room Number Type)|
@@ -259,7 +259,7 @@ Examples:
259259
260260group ("Name") as "SameAgePeople"
261261
262−|(Name, Name Type)|(Age, Age Type)|
262+| (Name, Name Type)|(Age, Age Type) |
263263|-----------------|---------------|
264264|Steve|12|
265265|Cindy|12|
@@ -301,6 +301,37 @@ ungroup ("Pets")
301301
302302Note that Bob does not appear in the result relation because he has no pets.
303303
304+#### Difference
305+
306+The difference operator ("minus" in TutorialD) receives two relations of the same type (same attributes) as arguments rvA and rvB and returns a relation which contains tuples in rvA which are not found in rvB. This operator is similar to set difference.
307+
308+Example:
309+
310+* Show a relation of non-managers by starting with the relation of employees and removing the employees found in the manager relation.
311+
312+Employees
313+
314+|(Name, Name Type)|
315+|-----------------|
316+| Bob |
317+| Jim |
318+| Steve |
319+| Bart |
320+
321+Managers
322+
323+|(Name, Name Type)|
324+|-----------------|
325+| Bob |
326+| Steve |
327+
328+====>
329+
330+|(Name, Name Type)|
331+|-----------------|
332+| Jim |
333+| Bart |
334+
304335### Displaying Relations
305336
306337Note that in the above operator examples, the order of the tuples appears to shift around. Since a relation body is a set of tuples, any ordering, such as required to represent a relation in two-dimenstional space as a table, is completely arbitrary. Note that the following two relations are two representations of *same* relation:
@@ -311,7 +342,7 @@ Note that in the above operator examples, the order of the tuples appears to shi
311342|Sam|41|
312343|Cindy|42|
313344
314−and
345+and
315346
316347|(Name, Name Type)|(Age, Age Type)|
317348|-----------------|---------------|
@@ -343,7 +374,7 @@ For most companies, its data, such as customer, employee, sales, and product inf
343374
344375## What is the advantage of having relation-valued attributes?
345376
346−Since a value can store any (immutable) type, it can certainly hold a relation. At the very least, the mathematics does not exclude the possibility. This does create a recursively-defined data structure (Relation -> Tuple -> Value -> Relation), but it turns out that relations as values can be quite useful.
377+Since a value can store any (immutable) type, it can certainly hold a relation. At the very least, the mathematics does not exclude the possibility. This does create a recursively-defined data structure (Relation -> Tuple -> Value -> Relation), but it turns out that relations as values can be quite useful.
347378
348379For example, in SQL, if one wants to collect some aggregate data over some tuples while still returning the individual tuples, in the best case, the aggregate information must be repeated for every individual tuple. In the worst case, two separate queries are required since nested tables are not supported.
349380
@@ -372,7 +403,7 @@ Example:
372403
373404## Suggested Reading
374405
375−Chris Date has been researching the relational model and its consequences for over forty years. Date has published his findings in various papers but also summarizes his work in a series of introductory and advanced books. Date freely admits that his work on the relational algebra has been corrected over time, so it is best to read his latest works.
406+Chris Date has been researching the relational model and its consequences for over forty years. Date has published his findings in various papers but also summarizes his work in a series of introductory and advanced books. Date freely admits that his work on the relational algebra has been corrected over time, so it is best to read his latest works.
376407
377408Despite that fact that modern SQL databases do not adhere to the principles of relational algebra doesn't mean that the principles cannot be applied. Date often discusses and compares SQL constructions with his own "TutorialD" language. Project:M36 also supports TutorialD.
378409