AfterAcademy Tech
•
19 Dec 2019

Let us imagine we are going to build a house, then what is the first thing that we do? Do we directly start building our house? No, we first get it designed from an architect or prepare a basic model of the house according to our requirements. Then we give this model to the builder to build. This is done so that we can have a conceptual view of what we are going to build.
Similarly, if we are going to design a database for any organisation like school, hospital, etc. we first talk to the organisation member and get to know what they want. At this time we don't do any implementation because the requirements may change. So, first, we design a model of their requirements and show to them. Once, they are satisfied then only the programmers start implementing and designing the database. So, how is this conceptual database designing done? Yes, the E-R model will help us in doing this. So, let's get started.
E-R model is a graphical representation of the logical structure of the database. In this model, we represent the real-world problem in the pictorial form to make it easy for the stakeholders to understand. It is also very easy for the developers to understand the system by just looking at the ER diagram. We use the ER diagram as a visual tool to represent an ER Model. ER diagram has the following three components:


Key Attribute: Key attribute is used to uniquley identify the records and it represents the primary key of the table. It is represented by oval and the text in it is underlined. Example: If we have Roll_no as the key attribute then it would be represneted as:

Composite Attribute: This attribute can be further divided into other attributes. Example: Name of a student can be further divided into first name, middle name and last name.

Multivalued Attribute: This attribute has more than one value. It is represented by a double oval. Example: A student can have more than one e-mail address.

Derived Attribute: The value of this attribute are derived from some other attributes. This is done mainly because the value for such attribute keeps on changing. It is represented by a dashed oval. Example: The value of age attribute is derived from the DOB(date of birth) attribute.

Note: Entities along with attributes are called entity type or schema. Example: Car entity has attributes Car_no, Color, Price. So, we represent an entity type as follows:

One-to-One Relationship: Such a relationship exists when each record of one table is related to only one record of the other table. Example: If there are two entities 'Person' and 'Passport'. So, each person can have only one passport and each passport belongs to only one person.

One-to-Many Relationship: Such a relationship exists when each record of one table can be related to one or more than one record of the other table. Example: If there are two entities 'Owner' and 'Pet' then each owner can have more than one pet but each pet is owned by only one owner.

Many-to-Many Relationship: Such a relationship exists when each record of the first table can be related to one or more than one record of the second table and a single record of the second table can be related to one or more than one record of the first table. Example: If there are two entities 'Customer' and 'Product' then each customer can buy more than one product and a product can be bought by many different customers.

Using the above knowledge of how to make an ER diagram, we can make an ER diagram for a hospital management system. We will have three entities i.e Doctor, Patient, Medicine.

In the above diagram, entity Doctor has key attribute 'doctor_id' which will be used to identify the doctors. It also has two multivalued attributes as 'specialization' and 'qualification' as a doctor may have more than one qualification and may be specialized in more than one fields. The Doctor and Patient entity have a one-to-many relationship as a Doctor may treat more than one patient. Similarly, Patient and Medicine have a many-to-many relationship as a patient may buy more than one medicine and vice-versa. 'Code' is the key attribute for Medicine which is unique for every medicine. The Patient has many attributes Patient_id, DOB, Age, etc. 'Age' is the derived attribute here. Also, it has a composite attribute 'Address' which can further be divided into two attributes 'Locality' and 'Town'.
This is all about the E-R model of DBMS. Hope you learned something new today.
Do share this blog with your friends to spread the knowledge. Visit our YouTube channel for more content. You can read more blogs from here.
Keep Learning 🙂
Team AfterAcademy!
AfterAcademy Tech
In this blog, we will learn about various data models present in DBMS. We will also learn about various types of data models present along with advantages and disadvantages of each model.

AfterAcademy Tech
In this blog, we will mainly learn about the OSI model and its working in detail. We'll focus on the features and working of each layer of the OSI model.

AfterAcademy Tech
In this blog, we will mainly learn about the TCP/IP model and its working in detail. We'll focus on the features and working of each layer of the TCP/IP model.

AfterAcademy Tech
In this blog, we have described the similarities and dissimilarities between the OSI and TCP/IP models. We've also tried to tell which model is better for which scenario.
