Attributes can be used in the Crows Foot logical view and in the NIAM view. With attributes, you can define the properties of an entity. Basically, each entity must have a minimal set of uniquely identifying attributes unless it is a weak entity. Together, these attributes form the primary key of the entity. For each attribute, you can specify whether it is part of the primary key, and set the optionality.
Keys can be used in the Crows Foot logical view. A key is used for uniquely identifying an entity and can be linked to attributes in an entity. A key consists of one or more attributes. When a single key is linked to an entity, it is the primary key. The primary key may be used in other entities to refer back to. To refer from one entity to the primary key of another entity, you can set a foreign key. That way, you can define the relationship between different entities.
In a NIAM view, an entity can be uniquely identified by using uniqueness constraints.
Good primary keys have different characteristics. Firstly, they are unique for each instance of an entity. Secondly, they are never empty or zero: they always contain a value. Thirdly, they rarely, preferably never, change.
On this page:
Adding attributes to an entity
Attributes can be added to an entity in different ways:
- Via the Create window pane: Click the Attribute concept and then click on an entity in the view.
- Using the entity control for adding attributes: select an entity in the view, and then click its control.
- Using the quick-create pop-up window: Click in the white area of an entity in the view, and briefly hold down the mouse button. Next, click the attribute concept in the appearing pop-up window.
Attributes cannot be added by first creating them in the model browser, and then dragging them onto a view. However, when created in a view, they can be dragged from the model browser onto another view to use there.
In the Crows Foot view, attributes are automatically sorted ascending on name when added to the entity. When the (by default mandatory) attributes are also marked as optional (-) or as part of the primary key (#), the list is also automatically sorted by the marking. The default order is primary key(s) first, then mandatory attributes, and then optional attributes.
Within each marking type, the name sorting order is used, so the primary keys are sorted, then the mandatory attributes, and finally the optional attributes.
In the NIAM view the attributes are sorted in the order they are added to the entity, and they are also not sorted on their marking. If they need to be sorted otherwise, you need to manually move them within the entity.
Moving and sorting attributes
To change their position in the list in the entity, attributes can be moved manually and sorted. If you manually rearrange the default order of the attributes in the entity, then this becomes the new default order. When the entity is dragged on another view, the manually set order is used for the attributes. If on this view, the order is rearranged again, then that becomes the new default order.
Moving an attribute
You can easily move the individual attributes to put them in the right position on the list. To move an attribute, do as follows:
- Click the attribute, and drag it to the desired position in the list.
Attributes in an entity can be sorted ascending (alphabetically), descending (alphabetically), or can be set to no sorting. Sorting attributes is only possible in the Crows Foot logical view. To sort the attributes in an entity, follow these steps:
- Select the entity in the view, and click the sorting control
In the Sorting order window, select the desired sorting order, and click OK.
Ascending (alphabetically): The attributes are automatically sorted by name from a to z, and ascending by number. Names with a number come first. If the attributes have been assigned different markings, the sorting is done within each type of marking.
Descending (alphabetically): The attributes are automatically sorted by name from z to a, and descending by number. Names with a number come last. If the attributes have been assigned different markings, the sorting is done within each type of marking.
No sorting: When set to no sorting, the attributes remain at their current position, but when moving the attributes manually afterward, they can be positioned anywhere in the entity. There will be no automatic sorting on name or marking. Example:
Removing an attribute can be done in two ways:
- Remove from the entity: Select the attribute in the entity, and then click the to the right of the attribute, or press Delete.
- Remove from the model browser: In the model browser, right-click the attribute, and then click Delete.
In both situations, the attribute is removed from the model (as opposed to what is a common behavior in most of the other modeling languages when removing elements from a view).
Removing attributes from an entity
There are two ways of using keys in your entity-relationship model:
- Defining the key by making attributes part of the primary key. In this situation the key is not physically modeled, its existence is determined by the fact that it has attributes assigned. Only one key can be defined for an entity.
- By modeling keys as objects and making attributes part of the (primary) key. In this situation, an entity can have multiple keys attached. In that case, they are no longer considered a primary key, but just a key.
Making an attribute part of the primary key
To make an attribute part of the primary key, follow these steps:
- Select the attribute in the entity, and then click the
- Click the
Modeling a key as an object
To model a key as an object, just add it to the view as any other object. After that, connect the key to the attributes in an entity you want to make part of this key using a Link relation.
An entity with one primary key (left) and with two keys (right)
If you add an existing key to another view, and this view already contains the attributes that have been linked to the key, then the links are automatically added too.
Key indicator in attributes
When an attribute is attached to a key, it is shown in different ways in the view. When an attribute is made part of a primary key (via a link or not), it is marked with ain front of the attribute's name.
In case you connect more than one key to attributes in an entity, the attributes will not be marked as part of the primary key because there is no primary key.
If the (primary) key the attribute is linked to, has been modeled as an object in your model, then the attribute also has a light gray border to indicate the connection. This also applies to attributes in a NIAM view when they are linked to a uniqueness constraint. The key does not necessarily have to be present in the same view as the attribute.
Attributes attached to a primary key modeled as an object
Setting the foreign key for an attribute
If you want to refer from one entity to the primary key of another entity in a Crows Foot logical view, then set a foreign key. When an entity has a foreign key, it is indicated by the letterin front of the attribute name.
Foreign keys in an entity
When you click the, the entity with the attribute or attributes referenced, is highlighted in the open view.
Because the primary key of an entity may consist of a single attribute or set of attributes, it is possible to select a single attribute or an entity when setting the foreign key. The entity represents the set of attributes that form the primary key.
An attribute can have a foreign key that is also part of the primary key of its entity. The attribute with the foreign key then forms along with other attributes the primary key. The attribute then has anas well as a in front of its name, as can be seen in the above figure.
To set a foreign key, follow these steps:
- Select the attribute in the entity for which you want to set the key.
- Click the blue
- In the appearing window, in the Crows Foot model element of an ER model, select the attribute or entity you want to refer to and click OK.
If you want to refer to an entity, you can also drag an entity from the model browser onto the attribute in the view, instead of selecting one.
- Name the attribute.
Removing the foreign key
To remove a foreign key, do as follows:
- Select the attribute of the entity, and then click the
Deleting the last reference to an object that is referenced as a foreign key will not automatically delete this object. If you want to delete unused objects, locate them with the Unused objects function and delete them. When deleting an object that is still referenced as a foreign key, the references will properly be reset.
Setting the optionality of an attribute
Not all entities have a value for each attribute, but some attributes must have a value for all entities. This can be set with the attribute's optionality. Make an attribute optional if it is not required that an entity has a value associated with the attribute. Make an attribute mandatory if an entity must have a value that is associated with this attribute.
]The optionality can be set for attributes in the Crows Foot logical view as well as the NIAM view.
When adding a new attribute, it is mandatory by default. To make an attribute optional, click the in front of the attribute. In the NIAM view, it directly turns into a to indicate it is optional. In the Crows Foot view, click the to make the attribute optional.
Mandatory and optional attribute
To make an optional attribute mandatory again, click again until theappears again.