×
>
<

Aptitude

Entity Relationship Models

What is Entity Relationship Diagram in DBMS?

To give a user view of how the data in a given database has a logical relationship amongst one another. With various units involved in the same like –

  • Entity
  • Atributes
  • Various Relationships

Unit components of Entity Relationship Diagram
Entity

Entity is a real object representation in an Entity Relationship diagram. For example if we want to create a database for a college in that case students studying in the college will be considered as an entity.

It can be anything like –

  • Teachers
  • Course
  • Buildings
  • Classrooms etc.

The way of representing an entity is as follows –Representation : A very simple Rectangular box.

Entity Set

A set of all entities together is called an entity set.

Representation : A vertical Oval listing all entities.

Attributes

Attributes are the properties of any given entity. For example for student entity the following will be the attributes –

  • ID
  • Email ID
  • Age
  • Address
  • Phone Number etc

Representation : A horizontal Oval. There are the following types of attributes –

  • Key attribute
  • Composite attribute
  • Multivalued attribute
  • Derived attribute

Key Attribute

A key attribute is the one which will uniquely identify and associate identity for an entity.

For example – For a student, his roll number or his studentID maybe its key attribute. For course offered by university, the course code like IT101 will be its key attribute.

Representation : It is same as Horizontal oval for an attribute. But, has an underline below the same.

Composite Attribute

As clear from its name a composite attribute composes of multiple units of attributes forming a larger one.

For example – Address may have following composite attributes –

  • House Number
  • Street
  • City
  • State
  • Country
  • Pin Code

Representation : Horizontal ovals mapped with further composite vertical ovals

Multivalued Attribute

A multivalued attribute is one, which may have more than one value for example. The phone number for student maybe multivalued as student may have one or more than 1 phone numbers.

Representation : Double Horizontal Oval

Derived Attribute

A derived attribute as the name suggests is the one that can be derived or calculated with the help of other attribute present itself.

For example – The age of the student can be calculated from date of birth present as an attribute.

Representation : Horizontal Dashed Oval.

Relationship

The association between different entities that are existing in a database is depicted by relationship. For example in a university there may be thousands of students, which have enrolled in a few subjects each year.

So student entity is related to course entity by enrolment relationship.

Representation : Diamond box with entities connected to its edges as depicted in the image.

There are various types of relationships than can exist in a database which are –

  • Unary
  • Binary
  • n-ary

Relationship set is mapping of different entity set to the others with the help of connected lines are depicted in the image.

Unary Relationship

Unary relationship is where there is only entity which is related to itself.

For example –An entity person is related to itself, in relationship as married to.

Binary Relationship

Binary relationship is when there are 2 different entities associated with some relationship with one another.

For example –Students enrolled in a course

n-ary Relationship

n-ary relationship is when there is complex relationship amongst various entities. These are generally avoided by programmers to keep database architecture simple

For example –Men eating animal, Animals eating animals, Men eating Plants, Animal eating plants etc etc. All of them are bound by eating relationship.

Cardinalty

For a given entity sites, the number of entities that can participate in a relationship with another entity set is called cardinality.

One to One

When there is only one entity at a given instance participating in a relationship or association with only one different entity.

For example –Man married woman.

At a given time only one man can marry one woman at a given time. So it is one to one relationship.

Another example would be earth revolves around the sun

Many to One

When there are multiple entities in a given entity set in relationship with only one entity of another or same entity set.

Example – Assuming there is a rule that student can only enrol in 1 course this semester.

Students enrol in course.

There may be n number of students while the course offered is only 1.

Many to Many

Imagine there is no restriction in number of courses that can be enrolled in, then.

Many students can register in many different courses.

n students may register in m different courses.

Participation Constraint
Total Participation

All the entities in the entity set must participate in the relationship. For example the university forces, you to necessarily enrol in atleast 1 course, in that case it will be called total participation that student end.

It is represented by a double line joining entity and relationship..

Partial Participation

It is when there maybe cases when some entities may and some entities may not participate in a relationship.

This is represented by single line joining entity and relationship.

Weak Entity and Weak Relationship

Weak entities are the one which may not have their own attributes and depend on other entity for their existence. For example the monthly instalment is dependent upon the loan entity and its attributes. The participation for weak entity type is always total.

This is represented by a double rectangle as represented in the image.

Weak relationship which is represented by double diamond connects relationship between a strong entity and a weak entity.