Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Components of ER Diagrams in DBMS

 ER model stands for the Entity Relationship Model in the database


management system (DBMS). It is the first step of designing to give
the flow for a concept. It is the DFD (Data Flow Diagram) requirement
of a company.
 It is the basic building block for relational models. Not that much
training is required to design the database project. It is very easy to
convert the E-R model into a relational table or to a normalized table.
 It is a high-level data model diagram that defines the conceptual view
of the database. It acts as a blueprint to implement a database in
future.

COMPONENTS OF ER DIAGRAM

The components of ER diagram are as follows −

 Entity
 Attributes
 Relationship
 Weak entity
 Strong entity
 Simple attribute
 Key attribute
 Composite attribute
 Derived attribute
 Multivalued attribute

ENTITY
It may be an object, person, place or event that stores data in a database. In a
relationship diagram an entity is represented in rectangle form.

For example, students, employees, managers, etc.


The entity is pictorially depicted as follows −

ENTITY SET
It is a collection of entities of the same type which share similar properties.
For example, a group of students in a college and students are an entity set
Entity is characterized into two types as follows −

 Strong entity set


 Weak entity set

STRONG ENTITY SET


The entity types which consist of key
attributes or if there are enough
attributes for forming a primary key
attribute are called a strong entity set. It is
represented by a single rectangle.

WEAK ENTITY SET


An entity does not have a primary key attribute and depends on another
strong entity via foreign key attribute. It is represented by a double rectangle.

ATTRIBUTES
It is the name, thing etc. These are the data characteristics of entities or data
elements and data fields.
TYPES OF ATTRIBUTES

The types of attributes in the Entity Relationship (ER) model are as follows –

1. Single value attribute − These attributes contain a single value. For


example, age, salary etc.
2. Multivalued attribute − They contain more than one value of a single
entity. For example, phone numbers.
3. Composite attribute − The attributes which can be further divided.
For example, Name-> First name, Middle name, last name
4. Derived attribute − The attribute that can be derived from others. For
example, Date of Birth.
5. Simple Attributes − are those that cannot be further divided into sub-
attributes. For example, A student's roll number of a student or the
employee identification number. These attributes are usually
assigned by an organization and are used to identify an individual
within that organization uniquely. Databases and other systems often
use simple attributes to track and manage information.
6. Complex Attributes -The complex attribute in DBMS involves both
multivalued and composite attributes. For example, someone might
have more than one house, and each house might have more than
one phone. The phone is then considered a complex attribute.
7. Stored Attributes - In a DBMS, stored attributes are the data that
remain constant and fixed for an entity instance. These values help in
deriving the derived attributes. For example: consider a customer
entity in a bank. The customer's name, age, and address would be
stored attributes. The customer's account balance (a derived
attribute) could be calculated based on the transactions (another
stored attribute) associated with the customer.
8. Key Attributes - DBMS's key attributes are used to uniquely identify
each row in a table. Usually, there is more than one key attribute in a
table (primary key and foreign key). For example: In a table of
employees, the employee ID would be the primary key, while the
manager ID would be the foreign key.
DIFFERENT TYPES OF KEYS IN DBMS
Keys are of eight broad types in DBMS:
1. Primary Key
2. Natural Key
3. Candidate Key
4. Alternate Key
5. Foreign Key
6. Composite Key
7. Unique Key
8. Surrogate Key

1. Primary Key

 The primary key refers to a column or a set of columns of a table that


helps us identify all the records uniquely present in that table. A table
can consist of just one primary key.
 Also, this primary key cannot consist of the same values
reappearing/repeating for any of its rows. All the values of a primary
key have to be different, and there should be no repetitions.
 The PK (PRIMARY KEY) constraint that we put on a column/set of
columns won’t allow these to have a null value or a duplicate. Any
table can consist of only a single primary key constraint.

2. Natural Key

 A natural key is an attribute that exists in the real world or is used by


the business. It can be used to uniquely identify the row.
 Not all types of keys use attributes that are used in the real world, but
those that do are called natural keys.
 An example of a natural key is a Social Security Number (for US
citizens). It’s usually a unique number that applies to a person, and
has a use for tax purposes. In Australia, we have a Tax File Number
(TFN) which has a similar purpose. It’s a way to uniquely identify a
record, and actually has a meaning in the world outside the database.


Advantages of a Natural Key
When designing your database, you’ll need to choose a primary key for each
of your tables. One option you have is to choose a natural key.
There are several advantages of using a natural key as a primary key:
 It already exists, meaning you don’t need to create a new column in
your table.
 It simplifies the quality of your data as it ensures only one row can
exist for this value

3. Candidate Key
The candidate keys refer to those attributes that identify rows uniquely in a
table. In a table, we select the primary key from a candidate key. Thus, a
candidate key has similar properties as that of the primary keys that we have
explained above. In a table, there can be multiple candidate keys.

Using our earlier examples, these would be candidate keys for a “customer”
table:

 Social Security Number


 Customer ID
 First Name, Last Name, Date of Birth

These keys are all candidate keys, as they are an option or candidate to be the
primary key. They don’t contain any redundant attributes – we don’t specify
“Social Security Number and First Name” as a candidate key, because Social
Security Number is a key by itself. Unlike the previous keys we looked at
(Natural, Surrogate, Composite), a candidate key is a name for existing types
of keys, and not a new type of key.

4. Alternate Key
As we have stated above, any table can consist of multiple choices for the
primary key. But, it can only choose one. Thus, all those keys that did not
become a primary key are known as alternate keys.

 They are an option or alternate to the primary key. This can also be called
a unique key.
 For example, using the candidate keys:
o Social Security Number
o Customer ID
o First Name, Last Name, Date of Birth
 If the Social Security Number was chosen as the primary key, then
Customer ID and “First Name, Last Name, Date of Birth” would be
alternate keys.
 Unlike the previous keys we looked at (Natural, Surrogate, Composite), an
alternate key is a name for existing types of keys, and not a new type of
key.

5. Foreign Key
We use a foreign key to establish relationships between two available tables.
The foreign key would require every value present in a column/set of columns
to match the referential table’s primary key. A foreign key helps us to
maintain data as well as referential integrity.

 They are used to specify that this record in this table is related to that
record in that table.
 Using the earlier customer and bank account example, you are a
customer at a bank. You may have several accounts with that bank.
These account details would be records in an account table.

6. Composite Key
The composite key refers to a set of multiple attributes that help us uniquely
identify every tuple present in a table. The attributes present in a set may not
be unique whenever we consider them separately. Thus, when we take them
all together, it will ensure total uniqueness.

 The examples we’ve looked at so far mention a single attribute.


However, I believe most databases let you use more than one column
as a primary key. If you do, this is called a composite key.
 An example of this would be identifying an address by combining the
street number, street name, city, and postal code. Depending on your
database, this may uniquely identify an address. If so, it could be used
as a composite key.
 These fields could not be used individually to identify an address.
Street numbers can be repeated, and so can street names. However,
the combination of all of these fields would be unique.
Advantages of a Composite Key

The advantages of using a composite key as a primary key are:

 The attributes already exist, so you don’t need to create any new
attributes or columns on your table like you do with the surrogate
key. This simplifies the table and reduces storage.
 The combination of the attributes ensures the record is unique,
like the natural key
 It allows you to use business values to identify a record if a single
value does not uniquely identify a record. If a natural key doesn’t
work, you can use a composite key.

Disadvantages of a Composite Key

The disadvantages of using a composite key as a primary key are:

 Risk of change to the business rules. Like a natural key, if any of the
business rules change (type of field, format of data) then this will need
to be updated. Also, the data may no longer uniquely identify a row so
you may need to expand your composite key.
 All fields are needed in related tables. When you want to refer to this
record from another table, you’ll need to store all of the fields in the
composite key in another table.

7. Unique Key
A unique key refers to a column/a set of columns that identify every record
uniquely in a table. All the values in this key would have to be unique.
Remember that a unique key is different from a primary key. It is because it is
only capable of having one null value. A primary key, on the other hand,
cannot have a null value.

8. Surrogate Key
The word surrogate means substitute. A surrogate key is an attribute that is
invented or made up for the sole purpose of being used as the primary key. It
has no value to the business or the real world.
 An example of a surrogate key is an “address ID” for a table of
addresses. Outside of the system, an address ID has no value to
anyone. But for the database, it’s used to uniquely identify the record.
 Surrogate keys are often used when there is no other way to identify a
record – when there is no natural key. They are often an integer value,
starting at 1 and incrementing for each new record.

Advantages of a Surrogate Key


There are several advantages using a surrogate key for your primary key:

 It has no business or real world value, which means you have control
over the format and usage of the value. No matter what happens to
the other data in the record (e.g. change in formats or types), this key
won’t change.
 It’s easy to define. There’s no need to work out which of the existing
attributes can make a key, as you can use a new column for the
identifier.

Disadvantages of a Surrogate Key


There are a few disadvantages of using a surrogate key as your primary key:

 It’s another extra column in your table, which increases storage space.
However, storage is cheap so this may not be an issue.
 You can’t look at the key and determine anything about the record,
unlike a Social Security Number or a Country Name.

What’s the Difference between a Primary Key and a Unique Key?


A primary key and a unique key are similar, but there are some
differences.

You might also like