President. Each column represents a different relation. So we can use the name of each column as relation name. Then, we invent names to describe the content of each column:
president[President*President], we have reused the relation
lastname. By doing so, we have interpreted the third column of the spreadsheet as the last name of the president. More importantly, we have reused an earlier relation. The drawing can also be extended:
capital[President*City]. In the model this relation pairs presidents to capital cities of the state in which they were born. This meaning can be made more obvious, by redefining one relation somewhat:
capital[State*City]feels more natural. The reason is obvious: a capital city belongs more to the state than it belongs to a president who happens to have been born in that state.
capitalin this example.
firstnameit hardly needs to be said that it contains the first name of each president. But it is not always that obvious. In the second example we saw that the meaning of the relation
capital[President*City]was far from obvious. It relates a president to the capital city of the state in which he was born. There are two things we need to do about it:
RELATION birth[President*State], the reader should interpret that as "President
RELATION birth[President*State]must be univalent:
UNI) and injective (
r[A*B] [UNI]means that there is at most one pair
r[A*B] [INJ]means that there is at most one pair
r[A*B] [UNI,INJ]means the relation is both univalent and injective.
firstnameto be univalent.
birthto be univalent
stateto be univalent
capitalto be univalent and injective.
CONTEXTand run it on RAP3. Ampersand will produce the following data model: