56 Entity Types
A concrete domain represents an entity in the real world, with the attributes giving the properties of the entity. For example, the following are the entities associated with Chris Date's Supplier-and-parts database example appearing in his book An introduction to Database Systems.
entity Supplier
{
Integer id;
String name;
Integer status;
String city;
key {id};
}
entity Part
{
Integer id;
String name;
Color color;
Real weight;
String city;
key {id};
}
entity Shipment
{
Supplier supplier;
Part part;
Integer qty;
key {supplier,part};
}
entity ShipmentsSystem
{
Supplier supplier*;
Part part*;
Shipment shipment*;
constraints
{
shipment.supplier.Σ ⊆ supplier.Σ;
shipment.part.Σ ⊆ part.Σ;
}
}
In Predica, an entity type may represent anything that exists in time and space and can be referred to. An entity need not be a physical object; it may also be an organisation, event, action, or relationship. A birth, a marriage, a shipment, or an ownership are all entities in this sense.
This can initially surprise people familiar with the Entity–Relationship Model (ERM), which draws a sharp but ultimately artificial line between entity boxes and relationship diamonds. Traditional ER modelling treats relationships as second-class constructs, and events, actions, and interactions are often forced into diagrammatic shapes that do not reflect their real-world status as things that occur and can be identified.
Carrier set
The structural body of an entity type is the structural type obtained from its attribute declarations, before applying any constraints and ignoring key declarations. For example:
entity Supplier
{
Integer id;
String name;
Integer status where status ≥ 0;
key {id};
}
has structural body:
{
Integer id;
String name;
Integer status;
}
An entity type declaration introduces a named type whose carrier is isomorphic to the constrained carrier of its structural body, just as for value types.
If S is the structural body of an entity type E, and K is the conjunction
of its constraints, then:
carrier(E) ≅ { v ∈ carrier(S) | K(v) }
The constraints K include constraints written in the constraints block and
constraints introduced by where clauses on attributes. In the example above,
K includes status ≥ 0.
Key declarations are ignored in this definition. A key does not change which values belong to the carrier of an entity type.
The distinction between value types and entity types is therefore not a difference in the mathematical construction of their carriers. Both are defined from their structural bodies and constraints. The distinction concerns how the type is interpreted and used by modellers.
Entity keys, including default keys, derived key attributes, and keys inherited from abstract entity types, are specified in 57 Keys.