0% found this document useful (0 votes)
3 views

Unit-2 Database Design using ER Model and Relational Model (E-next.in)

The document discusses the concepts of weak and strong entities in database design, highlighting their differences and relationships, particularly in the context of the Entity-Relationship model. It also explains various types of keys in databases, including primary, foreign, candidate, super, composite, alternate, and secondary keys, along with their roles in uniquely identifying records. Additionally, the document covers aggregation, generalization, specialization, and the significance of Entity Relationship Diagrams (ERDs) in database design.

Uploaded by

aakash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit-2 Database Design using ER Model and Relational Model (E-next.in)

The document discusses the concepts of weak and strong entities in database design, highlighting their differences and relationships, particularly in the context of the Entity-Relationship model. It also explains various types of keys in databases, including primary, foreign, candidate, super, composite, alternate, and secondary keys, along with their roles in uniquely identifying records. Additionally, the document covers aggregation, generalization, specialization, and the significance of Entity Relationship Diagrams (ERDs) in database design.

Uploaded by

aakash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Unit-2 Database Design usi ng ER Model and Relational Model

Q.1 Write a short note on Weak Entity and Strong Entity.


Q.2 Differentiate between Weak vs Strong Entity.
Strong and Weak Entity Sets in DBMS:
 The entity set which does not have sufficient attributes to form a primary key is
called as Weak entity set.
 An entity set that has a primary key is termed as strong entity set.
 The existence of a weak entity set depends on the existence of an identifying entity
set.
 It must relate to the identifying entity set via a total, one-to-many relationship set
from the identifying the weak.
 The weak entity set is said to be existence dependent on the identifying entity set.
 The identifying entity set is said to own the weak entity set that it identifies.
 The primary key of the weak entity is formed by the primary key of the identifying
entity set plus weak entity set’s discriminator. Ex. {account number, transaction
number}
 Consider an entity set Payment which has three attributes: payment_number,
payment_date and payment_amount. Although each payment entity is distinct but
payment for different loans may share the same payment number. Thus, this entity
set does not have a primary key and it is an entity set.
 Each weak set must be a part of one-to-many relationship set.
 A member of a strong entity set is called dominant entity and member of weak
entity set is called as subordinate entity.
 A weak entity set does not have a primary key but we need a means of distinguishing
among all those entries in the entity set that depend on one particular strong entity
set.
 The discriminator (Partial key) of a weak entity set is a set of attributes that allows
this distinction be made. Ex. Payment number.
 For example, payment_number acts as discriminator for payment entity set. It is also
called as the Partial key of the entity set.
 The primary key of a weak entity set is formed by the primary key of the strong
entity set on which the weak entity set is existence dependent plus the weak entity
sets discriminator.
 In the above example {loan_number, payment_number} acts as primary key for
payment entity set.
 The relationship between weak entity and strong entity set is called as Identifying
Relationship.
 In example, loan-payment is the identifying relationship for payment entity.
 A weak entity set is represented by doubly outlined box .and corresponding
identifying relation by a doubly outlined diamond as shown in figure.
 Here double lines indicate total participation of weak entity in strong entity set it
means that every payment must be related via loan-payment to some account.
 The arrow from loan-payment to loan indicates that each payment is for a single
loan.
 The discriminator of a weak entity set is underlined with dashed lines rather than
solid line.

Khan S. Alam 1 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

No. Weak Entity Set Strong Entity Set


1 The weak entity has a partial The Strong entity has a primary key.
discriminator key.
2 Weak entity depends on the strong The Strong entity is independent of any
entity for its existence. other entity in a schema.
3 Weak entity is denoted with the double Strong entity is denoted by a single
rectangle. rectangle.

4 The relationship between one strong The relation between two strong entities is
and a weak entity set is represented by denoted by a single diamond simply called
a double diamond sign. It is known as relationship.
identifying relationship.
5 Weak entity always has total Strong entity may or may not have total
participation in the identifying participation in the relationship.
relationship shown by double line.
6 The member of weak entity set is called The member of strong entity set is called as
as subordinate entity set. dominant entity set.
7 The line connecting weak entity set The line connecting strong entity set with
with the identifying relationship is the relationship is single.
double.
8 Total participation in the identifying Total participation in the relationship may
relationship always exist. or may not exist.
9 It contains a Partial Key or discriminator It contains a primary key represented by an
represented by a dashed underline. underline.

Khan S. Alam 2 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Q.3 Write a short note on


a. Primary key.
b. Foreign key.
c. Candidate key.
d. Super key.

Keys:
 Keys play an important role in relational database.
 It is used for uniquely identify any record or row of data from the table. It is also
used to establish and identify relationships between tables.
For example:
 In Student table, ID is used as a key because it is unique for each student. In PERSON
table, passport_number, license_number, SSN are keys since they are unique for
each person.

Primary Key:
 Also known as PK, a primary key is a special kind of entity attribute that uniquely
defines a record in a database table.
 In other words, there must not be two (or more) records that share the same value
for the primary key attribute.
 A Candidate Key that is used by the database designer for unique identification of
each row in a table is known as Primary Key.
 Primary key uniquely identifies each record in a table.
 It must have unique values and cannot contain nulls.
 A Primary Key can consist of one or more attributes of a table.

Example of Primary Key:


 In the below example the ROLL_NO field is marked as primary key, that means the
ROLL_NO field cannot have duplicate and null values.

Khan S. Alam 3 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

\CREATE TABLE STUDENT


(
ROLL_NO INT NOT NULL,
STU_NAME VARCHAR (35) NOT NULL UNIQUE,
STU_AGE INT NOT NULL,
STU_ADDRESS VARCHAR (35) UNIQUE,
PRIMARY KEY (ROLL_NO)
);

Example of Primary key:


 In the EMPLOYEE table, ID can be primary key since it is unique for each employee.
In EMPLOYEE table, we can even select License_Number and Passport_Number as
primary key since they are also unique.

Foreign Key:
 Also known as FK, a foreign key is a reference to a primary key in table.
 Foreign keys are the column of 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.
 It is used to identify the relationships between entities. .
 They act as a cross-reference between tables.
 Note that foreign keys need not to be unique.
 Multiple records can share the same values.
 We add primary key of 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.

Khan S. Alam 4 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Candidate key:
 It can be defined as minimal Super Key or irreducible Super Key.
 In other words an attribute or a combination of attribute that identifies the record
uniquely but none of its proper subsets can identify the records uniquely.
 Minimal set of attributes necessary to uniquely identify an entity
 A superkey for which no subset is a superkey – minimal superkey
 Candidate key is an attribute or set of attribute which can uniquely identify a tuple.
 The remaining attributes except primary key which is as strong as primary key are
considered as candidate key.

For example: In the EMPLOYEE table, id is best suited for primary key. Rest of the attributes
like: SSN, Passport_Number and License_Number etc. are considered as candidate key.

Khan S. Alam 5 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Super Key:
 An attribute or a combination of attribute that is used to identify the records
uniquely is known as Super Key.
 A table can have many Super Keys.
 Super key is a set of attribute which can uniquely identify a tuple.
 Super key is a superset of candidate key.

For example:
 In the above EMPLOYEE table, for (EMPLOEE_ID, EMPLOYEE_NAME) the name of
two employees can be same but their EMPLYEE_ID can't be same. Hence, this
combination can also be a key.
 The super key would be: EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME) etc.

E.g. of Super Key:


1 ID
2 ID, Name
3 ID, Address
4 ID, Department_ID
5 ID, Salary
6 Name, Address
7 Name, Address, Department_ID ………… So on as any combination which can identify the
records uniquely will be a Super Key.

Composite Key:
 If we use multiple attributes to create a Primary Key then that Primary Key is called
Composite Key (also called a Compound Key or Concatenated Key).
 E.g. of Composite Key, if we have used “Name, Address” as a Primary Key then it will
be our Composite Key.

Alternate Key:
 Alternate Key can be any of the Candidate Keys except for the Primary Key.
 E.g. of Alternate Key is “Name, Address” as it is the only other Candidate Key which
is not a Primary Key.

Secondary Key:
 The attributes that are not even the Super Key but can be still used for identification
of records (not unique) are known as Secondary Key.
 E.g. of Secondary Key can be Name, Address, Salary, Department_ID etc. as they can
identify the records but they might not be unique.

Khan S. Alam 6 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Q.4 Write a short note on Aggregation.


Q.5 Differentiate between Aggregation and Association.
Q.6Write a short note on Aggregation and Ternary relationship.
Q.7 Write a short note on Generalization and specialization.
Aggregation:
 One limitation of the E-R model is that it cannot express relationships among
relationships.
 Aggregation allows us to treat a relationship set as an entity set for purpose of
participation in other relationships
 In aggregation, relation between two entities is treated as a single entity.
 In aggregation, relationship with its corresponding entities is aggregated into a
higher level entity.
 The best way to model a situation such as the one just described is to use
aggregation.

For example:
 Center entity offers the Course entity act as a single entity in the relationship which
is in relationship with another entity visitor. In the real world, if a visitor visits a
coaching center then he will never enquire about the Course only or just about the
Center rather he will ask enquire about both.

Generalization:
 Generalization is like a bottom-up approach in which two or more entities of lower
level combine to form a higher level entity if they have some attributes in common.
 In generalization, entity of higher level can also combine with the entities of lower
level to form further higher level entity.
 Generalization is more like subclass and super-class system but the only difference is
the approach. Generalization uses the bottom-up approach.
 In generalization, entities are combined to form a more generalized entity i.e.
subclasses are combined to make a super-class.
 Process of identifying some common characteristics of a collection of entity sets and
creating a new entity set that contains entities possessing these common
characteristics

Khan S. Alam 7 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

 Used to express similarities between entity sets


 Subclasses are defined before the superclass
 Bottom up approach
 Specialization and generalization are simple inversions of each other

For example:
 Faculty and Student entities can be generalized and create a higher level entity with
name Person.

Specialization:
 Specialization is a top-down approach and it is opposite to Generalization. In
specialization, one higher level entity can be broken down into two lower level
entities.
 Process of identifying subsets of an entity set that share some distinguishing
characteristics
 Consider an entity set Person {name, street, city}. A Person may be – Customer,
Employee
 Additional attributes – Customer {credit_rating}, Employee {salary}
 The ISA relationship is also referred to as a superclass-subclass relationship.
 It is a top-down design approach
 An entity of a subclass inherits all attributes of the superclass

For example:
 In an Employee management system, EMPLOYEE entity can be specialized as TESTER
or DEVELOPER based on what role they play in company.

Khan S. Alam 8 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Association:
 An association defines a relationship between two entity objects based on common
attributes.
The relationship can be:
1. one-to-one
2. one-to-many
3. many-to-many

Aggregate v/s ternary relationship:


 The choice between using aggregation or a ternary relationship is mainly determined
by the existence of a relationship that relates a relationship set to an entity set (or
second relationship set).
 The choice may also be guided by certain integrity constraints that we want to
express.
 For example, a project can be sponsored by any number of departments, a
department can sponsor one or more projects, and each sponsorship is 31
monitored by one or more employees.
 If we don't need to record the until attribute of Monitors, then we might reasonably
use a ternary relationship, say, Sponsors2, as shown in following Figure.

 Daigram

 Consider the constraint that each sponsorship (of a project by a department) be


monitored by at most one employee. We cannot \ express this constraint in terms of
the Sponsors2 relationship set. On the other hand, we can easily express the
constraint by drawing an arrow from the aggregated relationship Sponsors to the
relationship Monitors.
 Thus, the presence of such a constraint serves &s another reason for using
aggregation rather than a ternary relationship set.

Khan S. Alam 9 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Q.8 What is Entity Relationship Diagram (ER-Diagram)? Explain with its advantage.
ER model:
 There are two techniques used for the purpose of data base designing from the
system requirements. These are:
1. Top down Approach known as Entity-Relationship Modeling
2. Bottom Up approach known as Normalization.

 Entity Relationship Diagram, also known as ERD, ER Diagram or ER model, is a type of


structural diagram for use in database design.
 An ERD contains different symbols and connectors that visualize two important
information: The major entities within the system scope, and the inter-relationships
among these entities. And that's why it's called "Entity" "Relationship" diagram
(ERD)!
 It defines the conceptual view of a database.
 It Used to develop an initial database design
 ER-Diagram is a pictorial representation of data that describes how data is
communicated and related to each other.
 Any object, such as entities, attributes of an entity, sets of relationship and other
attributes of relationship can be characterized with the help of the ER diagram.
 It maps well to the relational model. The constructs used in the ER model can easily
be transformed into relational tables.
 It is simple and easy to understand with a minimum of training. Therefore, the model
can be used by the database designer to communicate the design to the end user.
 In addition, the model can be used as a design plan by the database developer to
implement a data model in specific database management software.

The basic things contained in an ER Model are:


1. Entity
2. Attributes
3. Relationship

Entities:
 They are represented using the rectangle shape box. These rectangles are named
with the entity set they represent.
 ER modeling is a top-down structure to database design that begins with identifying
the important data called entities and relationships in combination between the data
that must be characterized in the model.
 Then database model designers can add more details such as the information they
want to hold about the entities and relationships which are the attributes and any
constraints on the entities, relationships, and attributes.
 ER modeling is an important technique for any database designer to master and
forms the basis of the methodology.

Khan S. Alam 10 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Entity type:
 It is a group of objects with the same properties that are identified by the enterprise
as having an independent existence.
 The basic concept of the ER model is the entity type that is used to represent a group
of ‘objects’ in the ‘real world’ with the same properties.
 An entity type has an independent existence within a database.

Relationships:
 Relationships are represented by diamond-shaped box. All the entities (rectangle
shaped) participating in a relationship gets connected using a line.

There are four types of relationships. These are:


1. One-to-one:
 When only a single instance of an entity is associated with the relationship, it is
termed as ‘1:1’.
2. One-to-many:
 When more than one instance of an entity is related and linked with a relationship, it is
termed as ‘1:N’.
3. Many-to-one:
 When more than one instance of entity is linked with the relationship, it is termed as
‘N:1’.
4. Many-to-many:
 When more than one instance of an entity on the left and more than one instance of an
entity on the right can be linked with the relationship, then it is termed as N:N
relationship.

Conceptual design with ER model:


 An E-R diagram can express the overall logical structure of a database graphically. E-R
diagrams are simple and clear— qualities that may well account in large part for the
widespread use of the E-R model. Such a diagram consists of the following major
components:
1) Rectangles, which represent entity sets
2) Ellipses, which represent attributes
3) Diamonds, which represent relationship sets
4) Lines, which link attributes to entity sets and entity sets to relationship sets
5) Double ellipses, which represent multi valued attributes
6) Dashed ellipses, which denote derived attributes
7) Double lines, which indicate total participation of an entity in a relationship set
8) Double rectangles, which represent weak entity sets

Khan S. Alam 11 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Advantages of an E-R Model:


1. Straightforward relation representation:
 Having designed an E-R diagram for a database application, the relational
representation of the database model becomes relatively straightforward.
2. Easy conversion for E-R to other data model:
 Conversion from E-R diagram to a network or hierarchical data model can· easily be
accomplished.
3. Graphical representation for better understanding:
 An E-R model gives graphical and diagrammatical representation of various entities,
its attributes and relationships between entities. This is turn helps in the clear
understanding of the data structure and in minimizing redundancy and other
problems.

Disadvantages of E-R Data Model:


1. No industry standard for notation:
 There is no industry standard notation for developing an E-R diagram.
2. Popular for high-level design:
 The E-R data model is especially popular for high level Entity Relationship Design
Issues Design Issues
 The notions of an entity set and a relationship set are not precise, and it is possible
to define a set of entities and the relationships among them in a number of different
ways.

Khan S. Alam 12 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Q.9 What is Relational Data Model.


Relation Data Model:
 Relational data model is the primary data model, which is used widely around the
world for data storage and processing.
 This model is simple and it has all the properties and capabilities required to process
data with storage efficiency.

Concepts:
1. Tables
 In relational data model, relations are saved in the format of Tables. This format
stores the relation among entities.
 A table has rows and columns, where rows represents records and columns
represent the attributes.

2. Tuple
 A single row of a table, which contains a single record for that relation is called a
tuple.

3. Relation instance
 A finite set of tuples in the relational database system represents relation instance.
 Relation instances do not have duplicate tuples.

4. Relation schema
 A relation schema describes the relation name (table name), attributes, and their
names.

5. Relation key
 Each row has one or more attributes, known as relation key, which can identify the
row in the relation (table) uniquely.

6. Attribute domain
 Every attribute has some pre-defined value scope, known as attribute domain.

Khan S. Alam 13 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Constraints:
 Every relation has some conditions that must hold for it to be a valid relation.
 These conditions are called Relational Integrity Constraints.
There are three main integrity constraints:
1. Key constraints
2. Domain constraints
3. Referential integrity constraints

1. Key Constraints
 There must be at least one minimal subset of attributes in the relation, which can
identify a tuple uniquely.
 This minimal subset of attributes is called key for that relation.
 If there are more than one such minimal subsets, these are called candidate keys.
 Key constraints force that −in a relation with a key attribute, no two tuples can have
identical values for key attributes.
 A key attribute can not have NULL values.
 Key constraints are also referred to as Entity Constraints.

2. Domain Constraints
 Attributes have specific values in real-world scenario. For example, age can only be a
positive integer.
 The same constraints have been tried to employ on the attributes of a relation.
 Every attribute is bound to have a specific range of values.
 For example, age cannot be less than zero and telephone numbers cannot contain a
digit outside 0-9.

3. Referential integrity Constraints


 Referential integrity constraints work on the concept of Foreign Keys.
 A foreign key is a key attribute of a relation that can be referred in other relation.
 Referential integrity constraint states that if a relation refers to a key attribute of a
different or same relation, then that key element must exist.

Khan S. Alam 14 https://E-next.in


Unit-2 Database Design usi ng ER Model and Relational Model

Q.10 What is Data integrity enforcement.


Data integrity enforcement:
 Data integrity is enforced by database constraints
 Database Constraints are declarative integrity rules of defining table structures.
They include the following 7 constraint types:
1. Data type constraint:
 This defines the type of data, data length, and a few other attributes which are
specifically associated with the type of data in a column.

2. Default constraint:
 This defines what value the column should use when no value has been supplied
explicitly when inserting a record in the table.

3. Nullability constraint:
 This defines that if a column is NOT NULL or allow NULL values to be stored in it.

4. Primary key constraint:


 This is the unique identifier of the table. Each row must have a distinct value.
 The primary key can be either a sequentially incremented integer number or a
natural selection of data that represents what is happening in the real world (e.g.
Social Security Number).
 NULL values are not allowed in primary key values.

5. Unique constraint:
 This defines that the values in a column must be unique and no duplicates should be
stored.
 Sometimes the data in a column must be unique even though the column does not
act as Primary Key of the table.
 For example CategoryName column is unique in categories table but CategoryName
is not primary key of the table.

6. Foreign key constraint:


 This defines how referential integrity is enforced between two tables.

7. Check constraint:
 This defines a validation rule for the data values in a column so it is a user-defined
data integrity constraint.
 This rule is defined by the user when designing the column in a table.
 Not every database engine supports check constraints.
 As of version 5.0, MySQL does not support check constraint. But you can use enum
data type or set data type to achieve some of its functionalities that are available in
other Relational Database Management Systems (Oracle, SQL Server, etc).

Khan S. Alam 15 https://E-next.in

You might also like