Lec 2 Data Modeling and Database Design
Lec 2 Data Modeling and Database Design
ER Model
It displays the relationships of entity set stored in a database. In other words, we can
say that ER diagrams help you to explain the logical structure of databases.
ER diagrams are a visual tool which is helpful to represent the ER model. It was
proposed by Peter Chen in 1971 to create a uniform convention which can be used
for relational database and network. He aimed to use an ER model as a conceptual
modeling approach.
Entity relationship diagram displays the relationships of entity set stored in a
database. In other words, we can say that ER diagrams help you to explain the logical
structure of databases. At first look, an ER diagram looks very similar to the
flowchart. However, ER Diagram includes many specialized symbols, and its
meanings make this model unique.
Entities
Attributes
Relationships
Example
For example, in a University database, we might have entities for Students, Courses,
and Lecturers. Students’ entity can have attributes like Rollno, Name, and DeptID. They
might have relationships with Courses and Lecturers.
What is an Entity?
A real-world thing either living or non-living that is easily recognizable and non-
recognizable. It is anything in the enterprise that is to be represented in our
database. It may be a physical thing or simply a fact about the enterprise or an event
that happens in the real world.
An entity can be place, person, object, event or a concept, which stores data in the
database.
The characteristics of entities are must have an attribute, and a unique key.
Every entity is made up of some 'attributes' which represent that entity.
A weak entity is a type of entity which doesn't have its key attribute. It can be identified
uniquely by considering the primary key of another entity. For that, weak entity sets need to
have participation.
In Chen Notation ERD an entity can be presented as rectangles.
Examples of entities:
What is an Attribute?
Types of Attributes
What is a Relationship?
Example:
ER Diagram Notations
ER- Diagram is a visual representation of data that describe how data is related to each
other.
Cardinality - Defines the numerical attributes of the relationship between two entities or
entity sets.
One-to-Many Relationships - When only one instance of the entity on the left, and
more than one instance of an entity on the right associates with the relationship.
May to One Relationships - When more than one instance of the entity on the left,
and only one instance of an entity on the right associates with the relationship.
Many-to-Many Relationships - When more than one instance of the entity on the
left, and more than one instance of an entity on the right associates with the
relationship.
Ordinality
Optional
Mandatory
The most noticeable differences to the Chen notation is the use of a line only instead of the
diamond to express the relationships and the inclusion of the attributes within the entity
rectangle.
Example:
Student
Course
Professor
You need to study the files, forms, reports, data currently maintained by the
organization to identify attributes. You can also conduct interviews with various
stakeholders to identify entities. Initially, it's important to identify the attributes without
mapping them to a particular entity.
Once, you have a list of Attributes, you need to map them to the identified entities.
Ensure an attribute is to be paired with exactly one entity. If you think an attribute should
belong to more than one entity, use a modifier to make it unique.
Once the mapping is done, identify the primary Keys. If a unique key is not readily
available, create one.
For Course Entity, attributes could be Duration, Credits, Assignments, etc. For the
sake of ease we have considered just one attribute.
You should assure that each entity only appears a single time in the ER diagram
Name every relationship, entity, and attribute are represented on your diagram
Never connect relationships to each other
You should use colors to highlight important portions of the ER diagram
Keys
Types of Key
A. Primary Key
It is the first key which is used to identify one and only one instance of an
entity uniquely.
The key which is most suitable from those lists become a primary key.
In the EMPLOYEE table, ID can be primary key since it is unique for each
employee. In the EMPLOYEE table, we can even select License_Number and
Passport_Number as primary key since they are also unique.
For each entity, selection of the primary key is based on requirement and
developers.
B. Candidate Key
A candidate key is an attribute or set of an attribute which can uniquely
identify a tuple.
The remaining attributes except for primary key are considered as a
candidate key. The candidate keys are as strong as the primary key.
C. Foreign Key
Foreign keys are the column of the table which is used to point to the primary
key of another table.
In a company, every employee works in a specific department, and employee
and department are two different entities. So we can't store the information
of the department in the employee table. That's why we link these two tables
through the primary key of one table.
We add the primary key of the
DEPARTMENT table,
Department_Id as a new attribute
in the EMPLOYEE table.
Now in the EMPLOYEE table,
Department_Id is the foreign key,
and both the tables are related.
There are some points for converting the ER diagram to the table:
In the given ER diagram, LECTURER, STUDENT, SUBJECTS and COURSE forms individual
tables.
In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of STUDENT
table. Similarly, COURSE_NAME and COURSE_ID form the column of COURSE table and so
on.
In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and LECTURE_ID are the
key attribute of the entity.
In the given ER diagram, student address is a composite attribute. It contains CITY, PIN,
DOOR#, STREET, and STATE. In the STUDENT table, these attributes can merge as an
individual column.
In the STUDENT table, Age is the derived attribute. It can be calculated at any point of
time by calculating the difference between current date and Date of Birth.
Using these rules, you can convert the ER diagram to tables and columns and assign the
mapping between the tables. Table structure for the given ER diagram is as below:
References:
https://www.javatpoint.com/dbms-tutorial
https://www.guru99.com/dbms-tutorial.html