S-Database Design U 2
S-Database Design U 2
ANALYSIS
SUKESH KUMAR BHAGAT
ER MODEL CONCEPT
ER (ENTITY RELATIONSHIP) DIAGRAM IN DBMS
• 1. Entity:
• An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as rectangles.
• Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity.
a. Weak Entity
• An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute of
its own. The weak entity is represented by a double rectangle.
COMPONENT OF ER DIAGRAM
• 2. Attribute
• The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
• For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
The key attribute is used to represent the main characteristics of an
entity. It represents a primary key. The key attribute is represented
by an ellipse with the text underlined.
b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute. The
composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse.
• c. Multivalued Attribute
• An attribute can have more than one value. These attributes are
known as a multivalued attribute. The double oval is used to
represent multivalued attribute.
• For example, a student can have more than one phone number.
• d. Derived Attribute
• An attribute that can be derived from other attribute is known as a
derived attribute. It can be represented by a dashed ellipse.
• For example, A person's age changes over time and can be derived
from another attribute like Date of birth.
RELATIONSHIP
• A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the
relationship.
• When only one instance of an entity is associated with the relationship, then it is known
as one to one relationship.
• For example, A female can marry to one male, and a male can marry to one female.
ONE-TO-MANY RELATIONSHIP
• 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 then this is known as a one-to-many
relationship.
• For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.
MANY-TO-ONE RELATIONSHIP
• 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 then it is known as a many-to-one
relationship.
• For example, Student enrolls for only one course, but a course can have many students.
MANY-TO-MANY RELATIONSHIP
• 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 then it is known as a many-to-many
relationship.
• For example, Employee can assign by many projects and project can have many
employees.
NOTATION OF ER DIAGRAM
• Database can be represented using the notations. In ER diagram, many notations are used
to express the cardinality. These notations are as follows:
ER DESIGN ISSUES
• The use of an entity set or attribute depends on the structure of the real-world enterprise
that is being modelled and the semantics associated with its attributes.
• It leads to a mistake when the user use the primary key of an entity set as an attribute of
another entity set. Instead, he should use the relationship to do so. Also, the primary key
attributes are implicit in the relationship set, but we designate it in the relationship sets.
USE OF ENTITY SET VS. RELATIONSHIP SETS
• Generally, the relationships described in the databases are binary relationships. However,
non-binary relationships can be represented by several binary relationships.
• For example, we can create and represent a ternary relationship 'parent' that may relate to
a child, his father, as well as his mother. Such relationship can also be represented by two
binary relationships i.e, mother and father, that may relate to their child. Thus, it is
possible to represent a non-binary relationship by a set of distinct binary relationships.
PLACING RELATIONSHIP ATTRIBUTES
• The cardinality ratios can become an affective measure in the placement of the relationship attributes.
• So, it is better to associate the attributes of one-to-one or one-to-many relationship sets with any participating
entity sets, instead of any relationship set. The decision of placing the specified attribute as a relationship or
entity attribute should possess the charactestics of the real world enterprise that is being modelled.
For example, if there is an entity which can be determined by the combination of participating entity sets,
instead of determing it as a separate entity. Such type of attribute must be associated with the many-to-many
relationship sets.
• Thus, it requires the overall knowledge of each part that is involved inb desgining and modelling an ER
diagram. The basic requirement is to analyse the real-world enterprise and the connectivity of one entity or
attribute with other.
CARDINALITY IN DBMS (MAPPING
CONSTRAINTS)
Cardinality
Cardinality means how the entities are arranged to each other or what is the relationship structure between
entities in a relationship set.
In a Database Management System, Cardinality represents a number that denotes how many times an entity is
participating with another entity in a relationship set. The Cardinality of DBMS is a very important attribute in
representing the structure of a Database. In a table, the number of rows or tuples represents the Cardinality.
Cardinality Ratio
Cardinality ratio is also called Cardinality Mapping, which represents the mapping of one entity set to another
entity set in a relationship set. We generally take the example of a binary relationship set where two entities are
mapped to each other.
Cardinality is very important in the Database of various businesses. For example, if we want to track the
purchase history of each customer then we can use the one-to-many cardinality to find the data of a specific
customer. The Cardinality model can be used in Databases by Database Managers for a variety of purposes, but
corporations often use it to evaluate customer or inventory data.
KEYS
1. PRIMARY KEY
2. CANDIDATE KEY
3. SUPER KEY
4. FOREIGN KEY
5. ALTERNATE KEY
6. COMPOSITE KEY
7. ARTIFICIAL KEY
PRIMARY KEY
• Foreign keys are the column of the table used to point to the
primary key of another table.
• Every employee works in a specific department in a
company, and employee and department are two different
entities. So we can't store the department's information 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.
• In the EMPLOYEE table, Department_Id is the foreign key,
and both the tables are related.
ALTERNATE KEY
• The database can be represented using the notations, and these notations can be reduced to a
collection of tables.
• In the database, every entity set or relationship set can be represented in tabular form.
• The ER diagram is given below:
REDUCTION OF ER DIAGRAM TO TABLE
There are some points for converting the ER diagram to the table:
• The degree of relationship can be defined as the number of occurrences in one entity that
is associated with the number of occurrences in another entity.
• There is the three degree of relationship:
1. One-to-one (1:1)
2. One-to-many (1:M)
3. Many-to-many (M:N)
ONE-TO-ONE
• Basic concepts: entities and entity types, attributes and keys, relationships and relationship
types
• Entity-Relationship schema (aka ER diagram)
• Constraints on relationship types
• Design choices
• Enhanced Entity-Relationship model features
• Steps in designing an ER schema
• Translation of an ER schema to tables
WHAT DOES CONCEPTUAL DESIGN INCLUDE?
(Entity-Relationship diagram)
ENTITY TYPES, ENTITY SETS, ATTRIBUTES AND
KEYS
• Entity: real-world object or thing with an independent existence and which is distinguishable from other
objects. Examples are a person, car, customer, product, gene, book etc.
• Attributes: an entity is represented by a set of attributes (its descriptive properties), e.g., name, age, salary,
price etc. Attribute values that describe each entity become a major part of the data eventually stored in a
database.
• With each attribute a domain is associated, i.e., a set of permitted values for an attribute. Possible domains
are integer, string, date, etc.
• Entity Type: Collection of entities that all have the same attributes, e.g., persons, cars, customers etc.
• Entity Set: Collection of entities of a particular entity type at any point in time; entity set is typically referred
to using the same name as entity type.
KEY ATTRIBUTES OF AN ENTITY TYPE
• Degree of a relationship: refers to the number of entity types that participate in the relationship type
(binary, ternary, . . . )
• Roles: The same entity type can participate more than once in a relationship type.
• Role labels clarify semantics of a relationship, i.e., the way in which an entity participates in a relationship.
~recursive relationship
• Relationship Attributes: A relationship type can have attributes describing properties of a relationship. customer
Smith ordered product PC42 on January 11, 2005, for $2345 .
• These are attributes that cannot be associated with participating entities only, i.e., they make only sense in the
context of a relationship.
• Note that a relationship does not have key attributes! The identification of a particular relationship in a relationship
set occurs through the keys of participating entities.
EXAMPLE OF AN ENTITY-RELATIONSHIP
DIAGRAM
• Rectangles represent entity types
• Ellipses represent attributes
• Diamonds represent relationship types
• Lines link attributes to entity types and entity types to relationship types
• Primary key attributes are underlined
• Empty Circle at the end of a line linking an attribute to an entity type represents an optional (null)
attribute (not mentioned in textbook) Not in the above diagram, but later in examples:
• Double Ellipses represent multi-valued attributes
CONSTRAINTS ON RELATIONSHIP TYPES
11. Define and give examples to illustrate the four types of attributes in database.
11. Explain specialization and generalization concepts in ER diagram with Suitable example.
12. What is Functional dependency? Explain its usage in database design. Explain various types of Functional dependency.
13. Explain following terms in detail. Entity set, Simple attribute, Composite attribute, single valued attribute, multi valued attribute, Null attribute,
derived attribute.
14. Construct E-R diagram for a hospital with a set of patients and medical
15. Doctors. Associate with each patient a log of various tests and examinations conducted.
16. Give Symbol used in E-R Diagram and Draw the E-R diagram of Library Management System.
17. Draw symbols for following in E-R diagram: .Weak Entity set, Derived attribute, Multi valued .Relationship Set ,and Primary key attribute.
Q.37
38.Convert following ER Diagram into database using Queries:
39.Construct ER Diagram & ER Model for the given problem:
40. Construct ER Diagram & ER Model for the given problem:
1.DEFINE (I) ENTITY (II) ATTRIBUTE
• Entity
• An entity is an object that data is captured about. It can be a person, place, thing, event, or concept. An entity can contain many
attributes, which further define the information stored.
• Attribute
• An attribute is a property or characteristic of an entity. For example, a person's attributes might include their height, weight, and
date of birth. An entity can contain multiple attributes, but one attribute is considered the primary key.
2. DEFINE RELATIONSHIP AND RELATIONSHIP
SET?
• In a database, a relationship is a connection between two tables.
• A relationship set is a collection of relationships that are all of the same type.