Entity-Relationship
The Entity-Relationship or E-R is a model which deals with real world entities, it includes a set of objects and the relationships among them. Entity is an object that exists and is easily distinguishable from others. Like people, they can easily be distinguished from others through various methods; for instance you can distinguish people from one another by social security numbers.
Also an entity can be concrete, like a book, person, or place, while it can also be abstract, like a holiday for example. Now an entity set is a set of entities that share something, like multiple holders of a bank account, those people would be considered an entity set. Also entity sets do not need to be disjoint.
Here is an example, the entity set employee (all employees of a bank) and the entity set customer (all customers of the bank) may have members in common. Such as an employee or employees may also be members of the bank. This puts them into both sets.
We must keep in mind that an entity or entity set is defined by a set of attributes. An attribute is a function which maps an entity set into a domain. Every entity is described by a set of (attribute, data value) pairs. There is one pair for each attribute of the entity set.
To illustrate in simpler terms, consider the following.
- A bank has employees, and customers.
- Employees are an entity set defined by employee numbers.
- Customers are an entity set defined by account numbers.
- Employees can be customers as well, and will have possession of both employee numbers and account numbers.
Relationships and Relationship Sets
A relationship, is an association between several entities. A relationship set is much like the others but it is a set of entities that are associated through one or more aspects. This is where relationship and relationship set start to differ because basically it is a mathematical relation. Consider the following:
If the equation expresses different entity sets, then a relationship set R, is a subset of
Where would express the actual relationship. Though it appears to be little complicated, with some practice it can be no more challenging then reading a simple sentence.
One should remember that the role of an entity is the function it has in a relationship. Consider an example, the relationship “works-for” could be ordered pairs of different employee entities or entity sets. The first employee entity takes the role of a manager or supervisor, where as the other one will take on the role of worker or associate.
Relationships can also have descriptive attributes. This can be seen in the example of a date (as in the last date of access to an account), this date is an attribute of a customer account relationship set.
Attributes
A particular set of entities and the relationships between them can be defined in a number of ways. The differentiating factor is how you deal with the attributes. Consider a set of employees as an entity, this time let us say that the set attributes are employee name and phone number.
In some instances the phone number should be considered an entity alone, with its own attributes being the location and uniqueness of the number it is self. Now we have two entity sets, and the relationship between them being through the attribute of the phone number. This defines the association, not only between the employees but also between the employee phone numbers. This new definition allows us to more accurately reflect the real world.
Basically what constitutes an entity and what constitutes an attribute depends largely on the structure of the situation that is being modeled, as well as the semantics associated with the attributes in question.
Let us now look at an example of the entity-relationship graph.
We can easily express the logical structure of a database in picture with an entity relationship diagram. Yet this is only possible when we keep in mind what components are involved in creating this type of model.
The vital components of an entity relationship model include:
* Rectangles, representing entity sets.
* Ellipses, representing attributes.
* Diamonds, representing relationship sets.
* Lines’, linking attributes to entity sets and entity sets to relationship sets.
Below diagram illustrates how an Entity-Relationship models work.
{qbapagebreak title=Entity-Relational Diagram Styles}
Entity-Relational Diagram Styles
Some of the different variations of the Entity-Relational diagram you will see are:
* Diamonds are omitted – a link between entities indicates a relationship.
Less symbols, means a clearer picture but what will happen with descriptive attributes? In this case, we have to create an intersection entity to possess the attributes instead.
* There can be numbers instead of arrowheads to indicate cardinality.
The symbols, 1, n and m can be used. E.g. 1 to 1, 1 to n, n to m. Some feel this is easier to understand than arrowheads.
* Also we can use a range of numbers that can indicate the different options of relationship
E.g. (0, 1) is used to indicate minimum zero (optional), maximum 1. We can also use (0,n), (1,1) or (1,n). This is typically used on the near end of the link – it is very confusing at first, but this structure gives us more information.
* Multi-valued attributes can be indicated in a certain manner.
This means attributes are able to have more than one value. An example of this is hobbies. Still this structure has to be normalized at a later date.
* Extended Entity-Relationship diagrams allow more details or constraints in the real world to be recorded.
This allows us to map composite attributes and record derived attributes. We can then use subclasses and super classes. This structure is generalization and specialization.
Summary
Entity-Relationship diagrams are a very important data modeling tool that can help organize the data in a project into categories defining entities and the relationships between entities. This process has proved time and again to allow the analyst to create a nice database structure and helps to store the data correctly.
Entity
The data entity represent both real and abstract entity about which data is being stored. The types of entities fall into classes (roles, events, locations, and concepts). This could be employees, payments, campuses, books, and so on. Specific examples of an entity are called instances.
Relationship
The relationship between data is a natural association that exists with one or more entities. Like the employees process payments. Cardinality is the number of occurrences of a single entity for one occurrence of the related entity, such as, an employee may process many payments but might not process any depending on the nature of their job.
Attribute
An attribute represents the common characteristic of a particular entity or entity set. The employee number and pay rate are both attributes. An attribute or combinations of attributes that identify one and only one instance of an entity are called a primary key or an identifier. For example, an employee number is an identifier.