×

MySQL: Entity-Relationship Model

Entity-Relationship Model

Entity-Relationship model or E R model is used to create a relationship between different attributes or entities. It describes the structure of the database with the help of the ER Diagram or Entity Relationship Diagram. ER model creates a simple design view of the data. It helps in creating the conceptual diagram of the database that makes the data easier to understand.

For example:Here, we have a database COMPANY, and in this database, EMPLOYEE is the entity (table). The employee entity contains several attributes like EMP_ID, EMP_NAME, EMP_ADDRESS, EMP_DATE_OF_BIRTH, EMP_AGE, and EMP_CONTACT. In these attributes, EMP_NAME can be work as another entity having attributes like FIRST_NAME, MIDDLE_NAME, and LAST_NAME. Again, another attribute EMP_ADDRESS in the table EMPLOYEE can work as another entity with attributes like EMP_CITY, EMP_HOUSE_NO, EMP_PIN, etc.

MySQL: Entity-Relationship Model

ER model contains the following essential component:

  • Entity
  • Entity Set
  • Attributes
  • Relation

Entity:

The entity in DBMS can be a real-world object having conceptual reality and existence.

For example: Above, we have a database COMPANY, and the entity type is EMPLOYEE. Here employees are the natural world person that has some existence.

An entity can be further divided into several types:

  • Strong entity
  • Weak entity
  • Tangible entity
  • Intangible entity

Strong entity:

Strong entities are those entities which do not depend on other entity. The strong entity mainly contains the primary key.A single rectangular box represents a strong entity.

MySQL: Entity-Relationship Model

For example:In the previous example, we have entity EMPLOYEE having EMP_ID as the primary key. Therefore, it is termed as a strong entity.

Weak entity:

Weak entities do not contain the primary key in the table. They mainly depend on the parent entity for the data. A double rectangular box represents it.

MySQL: Entity-Relationship Model

For example:Suppose we have an entity EMPLOYEE_ADDRESS having attributes EMP_CITY, EMP_HOUSE_NO, and EMP_PIN. Here we see that the primary key is unavailable, and EMPLOYEE_ADDRESS (entity) is dependent on the EMPLOYEE (entity) for the data.

Tangible-entity:

Tangible entities are those entities that have some physical existence. These entities exist in the real world.

For example, Person, Table, Chair, etc.

Intangible-entity:

Intangible entities are those entities that do not have physical existence. There is no existence of an intangible entity in the real world.

For example, Bank Account.

Entity Set

An entity set is a collection of more than one entity of a similar entity type. The entity type can be the data or values given to the data.

For example, suppose we have a table STUDENT(entity type) with attributes ID, NAME, and AGE.Then, the data given to this table can be the entity set. Let’s have a table name as STUDENT.

MySQL: Entity-Relationship Model

Here, STUDENT is entity type, and (01, Sumit, 23), (02, Ajay 26), and (03, Amit, 32) are the entity set.

Attributes

Attributes indicate the property and characteristics of an entity. There can be several attributes of an entity, depend on its possibility. One of the attributes is considered to be the primary key, candidate key, etc.

Attributes are represented by elliptical shape.

MySQL: Entity-Relationship Model

Example:

MySQL: Entity-Relationship Model

These attributes can be divided into several types, such as:

  • Simple attribute
  • Composite attribute
  • Single valued attribute
  • Multi-valued attribute
  • Derived attribute

Simple attribute:

The simple attribute cannot be further divided into its subtype. In other words, it cannot be further divided into one or more attributes.It also contains null values.

For example, Attributes like ID and ROLL_NO in table STUDENT (entity type) are examples of simple attributes as these attributes cannot be further divided into subtypes.

MySQL: Entity-Relationship Model

Composite Attribute

Composite attributes are those attributes that can be further divided into meaningful subparts. In other words, these attributes can be further divided into more than one sub-attributes.

For example, in the table STUDENT, attributes like NAME and ADDRESS can be further divided into sub-attributes. Like name can be divided into FIRST_NAME, MIDDLE_NAME, and LAST_NAME. ADDRESS can also be divided into CITY, HOUSE_NO, and PIN.

MySQL: Entity-Relationship Model

Single valued attribute

A single value attribute can have only a single attribute. Single value attributes are not necessarily simple attributes.

For example:AGE in entity STUDENT can be a single-valued attribute because age for each people will have a single value. It is not possible to have two ages for a single person. Each person will have only one age.

MySQL: Entity-Relationship Model

Multi-valued attribute

Multi-valued attributes are those attributes that contain more than one value at a time. It can be a composite attribute.

For example, ADDRESS attribute in the table STUDENT. An address can hold attributes like city, pin code, etc. NAME attributes in table STUDENT can also be multi-valued attributes.

MySQL: Entity-Relationship Model

Derived attribute

The derived attribute is those attributes that do not exist in the physical database. Its value gets derived from other attributes, or we can say that it depends on other database attributes for the data.

For example:Suppose we have a table SCHOOL. In this table, we can say that the AGE attribute can be derived attribute as it can be derived from the DATE OF BIRTH attribute of the table.

MySQL: Entity-Relationship Model

Relation

MySQL: Entity-Relationship Model

The relation shows the relationship among different entities. Its shows how two or more entities are related to each other.It is represented by a diamond shape in the ER diagram.

There are four types of relationship:

  • One to one
  • One to many
  • Many to one
  • Many to many

One to one

Here, one entity is related to another single entity known as one relationship.

For example, a person can have only one voter ID card, and so the relation among them will be one to one only.

One to many

When an entity is related to more than one entity, then this relation is known as one to many relationships.

For example, a relation between customer and order. Here a customer can place many orders, but many customers cannot place an order.

Many to one

When more than one entity is related to a single entity, this is called a many to one relationship.

For example, a relation between student and school, many students can study in a single school, but vice versa is not possible.

Many to many

When more than one entity is related to more than one entity, this is called many to many relationships.

For example, a relation among students and subjects will be the best example for this as many students read many subjects and vice versa.


Related Topics

MySQL Aggregate function

The aggregation function works on the multiple values and returns single value output.  It makes the advanced and complex operation simple. The summation (SUM), MAX, AVG, MIN, COUNT functions are...

5 minutes read.

MySQL Create index

An index creation helps to make a row of the table unique. The index operates and handles table data quickly. MySQL index requires NOT NULL column constraint. The index column...

2 minutes read.

MySQL Invisible Index

Invisible Index MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in...

3 minutes read.

MySQL DATE_ADD() function

In this context, we will learn how we can use the MySQL DATE_ADD() function with proper syntax and good examples. Introduction of MySQL DATE_ADD() function In MySQL, the DATE_ADD() function is used...

3 minutes read.

MySQL Operators

MySQL Operators MySQL operator needs advanced operation on the table and its data. This operator works with the "WHERE" clause. MySQL operators are a statement to modify information. It helps to...

13 minutes read.

MySQL Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL INSTR() Function

In this context, we will learn how we can use the MySQL INSTR() function with proper syntax and good examples. Introduction of MySQL INSTR() function This function in MySQL returns the location...

4 minutes read.

MySQL LENGTH() Function

In this context, we will learn how we can use the MySQL LENGTH() function with proper syntax and good examples. Introduction of MySQL LENGTH() function This function in MySQL is used to...

2 minutes read.

MySQL INSERT() Function

In this context, we will learn how we can use the MySQL INSERT() function with proper syntax and good examples. Introduction of MySQL INSERT() function Basically, in MySQL, the INSERT function is...

2 minutes read.

MySQL RPAD() function

In this context, we will learn how we can use the MySQL RPAD() function with proper syntax and good examples. Introduction of MySQL RPAD() function RPAD() function in MySQL is used to...

2 minutes read.

MySQL LOG2() function

In this context, we will learn how we can use the MySQL LOG2() function to calculate the Logarithm of a specific number with base 2 with proper syntax and examples. Introduction...

2 minutes read.

MySQL Composite Index

Composite Index A composite index is an index that is used on multiple columns. MySQL management system manages multiple columns simultaneously. Therefore, the single index contains multiple columns in one query...

3 minutes read.

MySQL logical conditions

MySQL logical conditions Introduction MySQL handles data with clauses, operators, and conditions. The logical condition is used to compare information and returns the required output. This condition applies logic to MySQL expressions...

7 minutes read.

MySQL View

Introduction MySQL View is a virtual table to create a clone of the base table. The View does not contain its values or data. MySQL View creates to connect more than...

12 minutes read.

MySQL Full text index

Full text index The full-text index in the table isused to search the full text of the data. This index assigns to the table using a "FULLTEXT" keyword. First, the table...

3 minutes read.

MySQL Advance table Query

MySQL Advance table Query The table is created by index, rows, and columns in the MySQL database. The user saves their information in matrix format. The database requires a query to...

14 minutes read.

MySQL ELT() function

In this context, we will learn how we can use the MySQL ELT() function with proper syntax and good examples. Introduction of MySQL ELT() function In the ELT function, the number field...

2 minutes read.

MySQL CEIL() function

In this context, we will learn how we can use the MySQL CEIL () function with proper syntax and good examples. Introduction of MySQL CEIL() function Input is taken by the CEIL()...

3 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL CONCAT() function

In this context, we will learn how we can use the MySQL CONCAT() function with proper syntax and good examples. Introduction of MySQL CONCAT() function By using the MySQL CONCAT function, we...

3 minutes read.