Sie sind auf Seite 1von 10

DCIT24 – Information Management

Lecture 2 – Data Modeling and Database Design

ER Model

 ER model stands for an Entity-Relationship model.


 It is a high-level data model. This model is used to define the data elements and
relationship for a specified system.
 It develops a conceptual design for the database. It also develops a very simple and
easy to design view of data.
 In ER modeling, the database structure is portrayed as a diagram called an Entity-
Relationship Diagram or (ERD).
 ER modeling helps you to analyze data requirements systematically to produce a
well-designed database.
 Entity-Relation model is based on the notion of real-world entities and the
relationship between them.
 ER modeling helps you to analyze data requirements systematically to produce a
well-designed database.
 So, it is considered a best practice to complete ER modeling before implementing
your database.

Entity Relationship Diagram

 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.

Cavite State University – Naic 1


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

Facts about ER Diagram Model:

 ER model allows you to draw Database Design


 It is an easy to use graphical tool for modeling data
 Widely used in Database Design
 It is a GUI representation of the logical structure of a Database
 It helps you to identifies the entities which exist in a system and the relationships
between those entities

Why use ER Diagrams?

 Helps you to define terms related to entity relationship modeling


 Provide a preview of how all your tables should connect, what fields are going to be
on each table
 Helps to describe entities, attributes, relationships
 ER diagrams are translatable into relational tables which allows you to build
databases quickly
 ER diagrams can be used by database designers as a blueprint for implementing data
in specific software applications
 The database designer gains a better understanding of the information to be
contained in the database with the help of ERP diagram
 ERD is allowed you to communicate with the logical structure of the database to
users.

Components of the ER Diagram

This model is based on three basic concepts:

 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.

Cavite State University – Naic 2


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

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:

 Person: Employee, Student, Patient


 Place: Store, Building
 Object: Machine, product, and Car
 Event: Sale, Registration, Renewal
 Concept: Account, Course

Strong Entity Set Weak Entity Set


Strong entity set always has a primary key. It does not have enough attributes to build a
primary key.
It is represented by a rectangle symbol. It is represented by a double rectangle
symbol.
It contains a Primary key represented by the It contains a Partial Key which is represented
underline symbol. by a dashed underline symbol.
The member of a strong entity set is called The member of a weak entity set called as a
as dominant entity set. subordinate entity set.
Primary Key is one of its attributes which In a weak entity set, it is a combination of
helps to identify its member. primary key and partial key of the strong
entity set.
In the ER diagram the relationship between The relationship between one strong and a
two strong entity set shown by using a weak entity set shown by using the double
diamond symbol. diamond symbol.
The connecting line of the strong entity set The line connecting the weak entity set for
with the relationship is single. identifying relationship is double.

Cavite State University – Naic 3


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

What is an Attribute?

 It is used to describe the property of an entity.


 It is a single-valued property of either an entity-type or a relationship-type.
 For example, a lecture might have attributes: time, date, duration, place, etc.
 In Chen Notation ERD , an attribute is represented by an Ellipse

Types of Attributes

 Key Attribute - is used to represent the main characteristics of an entity. It


represents a primary key.
 Composite Attribute - It is possible to break down.
 Derived Attributes - An attribute that can be derived from other attribute.
 Multivalued Attribute - can have more than one values.

What is a Relationship?

 Relationship is nothing but an association among two or more entities.


 Entities take part in relationships. We can often identify relationships with verbs or
verb phrases.
 A relationship is used to describe the relation between entities.
 In Chen Notation ERD, diamond or rhombus is used to represent the relationship.

Example:

 A student attends a lecture


 A lecturer is giving a lecture
 A teacher teaches student

ER Diagram Notations

ER- Diagram is a visual representation of data that describe how data is related to each
other.

 Rectangles: This symbol represent entity types


 Ellipses : Symbol represent attributes

Cavite State University – Naic 4


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

 Diamonds: This symbol represents relationship types


 Lines: It links attributes to entity types and entity types with other relationship types
 Primary key: attributes are underlined

Cardinality - Defines the numerical attributes of the relationship between two entities or
entity sets.

Different types of cardinal relationships are:

 One-to-One Relationships - When only one instance of an entity is associated with


the relationship.

 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

Cavite State University – Naic 5


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

Crow’s Foot Notation

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.

Steps to Create ERD

Example:

In a university, a Student enrolls in Courses. A student must be assigned to at least


one or more Courses. Each course is taught by a single Professor. To maintain instruction
quality, a Professor can deliver only one course.

Step 1: Entity Identification

We have three entities.

 Student
 Course
 Professor

Step 2: Relationship Identification

We have the following two relationships

 The student is assigned a course


 Professor delivers a course

Step 3: Cardinality and Ordinality Identification


For them problem statement we know that,
 A student can be assigned multiple courses
 A Professor can deliver only one course

Cavite State University – Naic 6


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

Step 4: Identify Attributes

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.

Entity Primary Key Attribute


Student Student_ID StudentName
Professor Employee_ID ProfessorName
Course Course_ID CourseName

For Course Entity, attributes could be Duration, Credits, Assignments, etc. For the
sake of ease we have considered just one attribute.

Step 5: Create the ERD (Crow’s Foot Notation)

Best Practices for Developing Effective ER Diagrams

 Eliminate any redundant entities or relationships


 You need to make sure that all your entities and relationships are properly labeled
 There may be various valid approaches to an ER diagram. You need to make sure
that the ER diagram supports all the data you need to store

Cavite State University – Naic 7


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

 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

 Keys play an important role in the relational database.


 It is used to uniquely identify any record or row of data from the table. It is also used
to establish and identify relationships between tables.

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.

Cavite State University – Naic 8


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

Converting CHEN Notation ER Diagram into Crow Foot Notation Table

There are some points for converting the ER diagram to the table:

A. Entity type becomes a table.

In the given ER diagram, LECTURER, STUDENT, SUBJECTS and COURSE forms individual
tables.

B. All single-valued attribute becomes a column for the table.

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.

C. A key attribute of the entity type represented by the primary key.

In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and LECTURE_ID are the
key attribute of the entity.

D. The multivalued attribute is represented by a separate table.

In the student table, a hobby is a multivalued attribute. So it is not possible to represent


multiple values in a single column of STUDENT table. Hence we create a table STUD_HOBBY
with column name STUDENT_ID and HOBBY. Using both the column, we create a composite
key.

E. Composite attribute represented by components.

Cavite State University – Naic 9


Information Technology Department
DCIT24 – Information Management
Lecture 2 – Data Modeling and Database Design

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.

F. Derived attributes are not considered in the table.

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

Cavite State University – Naic 10


Information Technology Department

Das könnte Ihnen auch gefallen