Besides entity and attribute, relationship is another basic concept of the ER model. For example, the relationship works_on between entities EMPLOYEE and. Depending on your implementation style, the concepts of entity, attribute, and entity type reflect the technical capabilities of virtual and physical. database and the relationships among those components. An ER model is a diagram containing entities or "items", relationships among them, and attributes of.
In a sales database, we could store the name, email address, postal address, and telephone number for each customer. Attributes describe the entity they belong to.
Entities and Attributes
An attribute may be formed from smaller parts; for example, a postal address is composed of a street number, city, ZIP code, and country. Some attributes can have multiple values for a given entity. For example, a customer could provide several telephone numbers, so the telephone number attribute is multivalued.
Attributes help distinguish one entity from other entities of the same type. We could use the name attribute to distinguish between customers, but this could be an inadequate solution because several customers could have identical names.
To be able to tell them apart, we need an attribute or a minimal combination of attributes guaranteed to be unique to each individual customer. The identifying attribute or attributes form a key. In our example, we can assume that no two customers have the same email address, so the email address can be the key.
However, we need to think carefully about the implications of our choices. For example, if we decide to identify customers by their email address, it would be hard to allow a customer to have multiple email addresses. Any applications we build to use this database might treat each email address as a separate person, and it might be hard to adapt everything to allow people to have multiple email addresses. Clearly, there may be several possible keys that could be used to identify an entity; we choose one of the alternative, or candidate, keys to be our main, or primary, key.
You usually make this choice based on how confident you are that the attribute will be non-empty and unique for each individual entity, and on how small the key is shorter keys are faster to maintain and use. Attributes comprising the primary key are shown underlined. The parts of any composite attributes are drawn connected to the oval of the composite attribute, and multivalued attributes are shown as double-lined ovals.
Similarly, a product price could be a positive rational number. Attributes can be empty; for example, some customers may not provide their telephone numbers. You should think carefully when classifying an attribute as multivalued: The sales database requirements may specify that a product has a name and a price.
Key concepts: Entity, attribute, and entity type
To distinguish between products, we can assign a unique product ID number to each item we stock; this would be the primary key. Each product entity would have name, price, and product ID attributes. The ER diagram representation of the product entity Representing Relationships Entities can participate in relationships with other entities.
For example, a customer can buy a product, a student can take a course, an artist can record an album, and so on. Like entities, relationships can have attributes: Our database could then record each sale and tell us, for example, that at 3: For example, each customer can buy any number of products, and each product can be bought by any number of customers. This is known as a many-to-many relationship. We can also have one-to-many relationships.
For example, one person can have several credit cards, but each credit card belongs to just one person. Looking at it the other way, a one-to-many relationship becomes a many-to-one relationship; for example, many credit cards belong to a single person.
Finally, the serial number on a car engine is an example of a one-to-one relationship; each engine has just one serial number, and each serial number belongs to just one engine. We often use the shorthand terms 1: N for one-to-one, one-to-many, and many-to-many relationships, respectively.
The number of entities on either side of a relationship the cardinality of the relationship define the key constraints of the relationship. There are many relationships that may at first seem to be one-to-one, but turn out to be more complex.
For example, people sometimes change their names; in some applications, such as police databases, this is of particular interest, and so it may be necessary to model a many-to-many relationship between a person entity and a name entity.
Redesigning a database can be time-consuming if you assume a relationship is simpler than it really is. In an ER diagram, we represent a relationship set with a named diamond. The cardinality of the relationship is often indicated alongside the relationship diamond; this is the style we use in this book.
The ER diagram representation of the customer and product entities, and the sale relationship between them. Partial and Total Participation Relationships between entities can be optional or compulsory.
- ER Model - Basic Concepts
- Key concepts: Entity, attribute, and entity type
- Learning MySQL by Hugh E. Williams, Saied M.M. Tahaghoghi
In our example, we could decide that a person is considered to be a customer only if they have bought a product.
On the other hand, we could say that a customer is a person whom we know about and whom we hope might buy something—that is, we can have people listed as customers in our database who never buy a product. These are referred to as the participation constraints of the relationship. In an ER diagram, we indicate total participation with a double line between the entity box and the relationship diamond.
Definition An entity is a real-world item or concept that exists on its own. The set of all possible values for an entity is the entity type. ER diagram notation for entity student Attribute Each entity has attributes, or particular properties that describe the entity. For example, student Emanuel Vagas has properties of his own Student Identification number, name, and grade.
A particular value of an attribute, such as 93 for the grade, is a value of the attribute. Most of the data in a database consists of values of attributes. The set of all possible values of an attribute, such as integers from 0 to for a grade, is the attribute domain. In an ER model, an attribute name appears in an oval that has a line to the corresponding entity box, such as in Figure 3.
Definition An attribute of an entity is a particular property that describes the entity. The set of all possible values of an attribute is the attribute domain. Sometimes the value of an attribute is unknown or missing, and sometimes a value is not applicable.
In such cases, the attribute can have the special value of null. For example, until the professor grades a laboratory assignment, the team grade is missing or null. Definition Null is the special attribute value that indicates an unknown or missing value.
An attribute can be simple or composite. A simple attribute, such as grade, is one component that is atomic. If we consider the name in two parts, last name and first name, then the name attribute is a composite. A composite attribute, such as "Emanuel Vagas", has multiple components, such as "Emanuel" and "Vagas"; and each component is atomic or composite. We illustrate this composite nature in the ER model by branching off the component attributes, such as in Figure 4.
Definition A simple attribute is one component that is atomic.
The Entity Relationship Model - Learning MySQL [Book]
A composite attribute has multiple components, each of which is atomic or composite. ER diagram notation for composite attribute domain, name Another way to classify attributes is either as single-valued or multi-valued.
For an entity an attribute, such as StudentGrade, usually holds exactly one value, such as 93, and thus is a single-valued attribute. However, two lab assistants might assist in a laboratory section.
Consequently, the LabAssistant attribute for the entity LabSection is multi-valued. A multi-valued attribute has more than one value for a particular entity. We illustrate this situation with a double oval around the lab assistant type, LabAssistant see Figure 5.
Definition For a particular entity, an entity attribute that holds exactly one value is a single-valued attribute. ER diagram notation for multi-valued attribute domain, LabAssistant A derived attribute can be obtained from other attributes or related entities. For example, the radius of a sphere can be determined from the circumference. We request the derived attribute with a dotted oval and line, such as in Figure 6. ER diagram notation for derived attribute, radius An attribute or set of attributes that uniquely identifies a particular entity is a key.
However, to determine the class we need a composite key that consists of several attributes, such as catalogue number, section, semester, and year.Entity, Entity Type, Entity Set - Database Management System
In the ER diagram of Figure 7we underline the composite key, class. The figure shows another attribute DragExpWeek of LabSection that stores the week of the semester in which the drag experiment occurs.
Definition An attribute or set of attributes that uniquely identifies a particular entity is a key.