2.1.1. Entities, attributes and relationships
By state we mean a real world object that can be distinguished from other objects and some properties that interest us.
Examples of entity
Some examples are an employee organization, product, or an office. Entities are also other elements of the real world of interest, less tangible but equally distinguishable from other objects, for example, a subject taught at a university, a bank loan, a customer order, etc..
The properties of the objects that interest us are called attributes.
Examples of attribute
Over a particular employee may interest us, for instance, have registered your ID, your SSN, name, last name and his salary as attributes.
The term entity is used to denote individual objects so as to refer to sets of similar items of interest to us the same attributes, ie, for example, is used to designate both a particular employee of a company and the set of all company employees.More specifically, the term will refer entity may be specific instances or occurrences (individual employees) or to types or classes of entities (the set of all employees).
The ER model provides a diagrammatic notation to represent graphically the entities and their attributes:
• Entities are represented by a rectangle.The entity name is written in capital letters within the rectangle.
• The attributes are represented by their name in lower case coupled with a dash to the rectangle of the entity to which they belong. Many times, as there are many attributes for each entity listed all apart of the diagram to keep it simple.
Each of the attributes of an entity takes values from a given domain or set of values. The values of the fields should be atomic, ie should not be able
be broken.In addition, all attributes must be single-valued. An attribute is single-valued if you have a single value for each occurrence of an entity.
Diagrammatic notation of entities and attributes
The figure shows the diagrammatic notation for the case of employee entity with attributes ID, SSN, name and salary.
Example of single-valued attribute
The salary of the entity attribute used, for example, takes values in the domain of the real and only takes a value for each individual employee, therefore, no employee can have more than one value for the salary.
As discussed above, an entity must be distinguishable from other objects in the real world.This makes possible for any entity to find a set of attributes that can be identified. This set of attributes forms a key entity.
The employee is a key entity consisting of the attribute dni because all employees have different ID numbers.
A given entity may have more than one key, ie, multiple candidate keys.
Candidate key concepts and primary key of an entity similar to the concepts of candidate key and primary key of a relationship, we have studied in the unit "The relational model
and the relational algebra. "
Example candidate key
The agency employee has two candidate keys, which is formed by the attribute ID and which is constituted by the attribute nss, given that the NSS will also be different for each employee.
The designer chooses a primary key among all the candidate keys.In diagrammatic notation, the primary key is underlined to distinguish it from other keys.
Example of primary key
In the case of an employee organization, we can choose dni as the primary key.In the margin we figure that the primary key is underlined to distinguish it from the rest.
Relationship is defined as an association between entities.
The interrelationships are represented in ER diagrams by a diamond pattern. Next to the diamond indicates the name of the interaction with capital letters.
Example of interaction
Consider an employee organization and a contracting firm and assume that employees are assigned to offices where they work. Then there is a relationship between the entity and the entity employee office.
This relationship, which could call assignment, employees associated with the firms where they work.The figure shows the interaction margin mapping between entities and office staff.
The interaction term can be used both to denote a particular form of associations or occurrences to appoint joint or similar kinds of partnerships.
A relationship applies to a specific association between the employee ID '50 .455.234 'and serving' Diagonal, 20 'as a generic association between the entity and the entity employee office.
Interests sometimes reflect some properties of the interrelations.For this reason, the relationships can also have attributes. The attributes of interrelationships, as well as those entities have a certain domain, they must take atomic values and must be single-valued.
The attributes of the interrelationships are represented by their name in lower case together with a dash at the interface diamond to which they belong.
Attribute such a relationship
Observe the student entity and the entity subject shown in the figure below:
Between these two entities is established evaluation interface to indicate what subjects the students have been assessed.This relationship has the attribute note, which is used to specify what grade students have obtained the subjects evaluated.
Note that the attribute must be bound to note a relationship attribute evaluation, it would be wrong to consider it an attribute of student entity or an attribute of the entity subject.We'll explain it by analyzing the occurrences of the assessment relationship shown in the figure above.
If note is considered an attribute of student then the student 'E1' in Fig need two attribute values, one for each course the student has, therefore, would not be single-valued. Similarly, if you were not subject attribute may be single-valued because, for example, the subject 'A1' note would require three values, one for each student who is enrolled in it. We conclude that the note is related to attribute the same time with a subject and a student who attends
andTherefore must be an attribute of the relationship that links the two entities.