Database design
Topics to be covered
• Database design & E-R Model
• Entity–Relationship model (E-R model)
• E-R Diagrams-Constraints
• Extended E-R features
Database design
• The database designer needs to interact
extensively with domain experts and specify the
user requirements
• The designer chooses a data model and, by
applying the concepts of the chosen data model,
translates these requirements into a conceptual
schema of the database
• At the stage of conceptual design, the designer
can review the schema to ensure it meets
functional requirements
Database design (Contd..)
• Logical-design phase
– The conceptual schema defined using the entity-
relationship model is converted into a relation
schema in this phase
• Physical-design phase
– The physical features of the database are specified
in this phase
ER Model
• The Entity Relational Model is a model for
identifying entities to be represented in the
database and representation of how those
entities are related
• The ER data model specifies enterprise
schema that represents the overall logical
structure of a database graphically
Why Use ER Diagrams In DBMS?
• ER diagrams are used to represent the E-R model in a
database, which makes them easy to convert into
relations (tables)
• ER diagrams provide the purpose of real-world
modeling of objects which makes them intently useful
• ER diagrams require no technical knowledge and no
hardware support
• These diagrams are very easy to understand and easy
to create even for a naive user
• It gives a standard solution for visualizing the data
logically
Symbols Used in ER Model
• Rectangles: Rectangles represent Entities in the ER Model
• Ellipses: Ellipses represent Attributes in the ER Model
• Diamond: Diamonds represent Relationships among
Entities
• Lines: Lines represent attributes to entities and entity sets
with other relationship types
• Double Ellipse: Double Ellipses represent Multi-Valued
Attributes
• Double Rectangle: Double Rectangle represents a Weak
Entity
Symbols used in ER model
Components of ER model
Example
Entity
Entity can be any real world object
Entity Set
An entity set is a set of entities of the same
type that share the same properties,
or attributes.
Strong Entity
• A strong entity is not dependent on any other
entity in the schema
• A strong entity will always have a primary key
• Strong entities are represented by a single
rectangle
• The relationship of two strong entities is
represented by a single diamond
• Various strong entities, when combined together,
create a strong entity set
Weak entity
• A weak entity is dependent on a strong entity to
ensure its existence
• Unlike a strong entity, a weak entity does not
have any primary key
• It instead has a partial discriminator key
• A weak entity is represented by a double
rectangle
• The relation between one strong and one weak
entity is represented by a double diamond
Example-1
Example-2
Attributes
Attributes are the properties that define the entity type.
For example, Roll_No, Name, DOB, Age, Address, and Mobile_No are the
attributes that define entity type Student.
Key Attribute
The attribute which uniquely identifies each entity in the entity set is called the key
attribute.
For example, Roll_No will be unique for each student
In ER diagram, the key attribute is represented by an oval with underlying lines
Composite Attribute
• An attribute composed of many other
attributes is called a composite attribute
• For example, the Address attribute of the
student Entity type consists of Street, City,
State, and Country
• In ER diagram, the composite attribute is
represented by an oval comprising of ovals
Composite Attribute (Contd..)
Multivalued Attribute
An attribute consisting of more than one value for a given entity
For example, Phone_No (can be more than one for a given student)
In ER diagram, a multivalued attribute is represented by a double oval
Derived Attribute
• An attribute that can be derived from other
attributes of the entity type is known as a
derived attribute
• E.g.; Age (can be derived from DOB)
• In ER diagram, the derived attribute is
represented by a dashed oval
Example
Student Entity Set with its attributes
Entity-Relationship Diagram
ER diagram corresponding to instructors and students
Relationship Type
• A Relationship Type represents the association
between entity types
• For example, ‘Enrolled in’ is a relationship type
that exists between entity type Student and
Course
• In ER diagram, the relationship type is
represented by a diamond and connecting the
entities with lines
Example
Relationship Set
• A set of relationships of the same type is
known as a relationship set
• The following relationship set depicts S1 as
enrolled in C2, S2 as enrolled in C1, and S3 as
registered in C3
Relationship Set
Degree of a Relationship Set
• The number of different entity sets
participating in a relationship set is called
the degree of a relationship set
• Different types of degree of a Relationship set
are
– Unary Relationship
– Binary Relationship
– n-ary Relationship
Unary Relationship
When there is only ONE entity set participating in a relation, the relationship is called
a unary relationship
Binary Relationship
When there are TWO entities set participating in a
relationship, the relationship is called a binary relationship.
For example, a Student is enrolled in a Course.
n-ary Relationship
• When there are n entities set participating in a
relation, the relationship is called an n-ary
relationship.
Cardinality
• The number of times an entity of an entity set
participates in a relationship set is known
as cardinality.
• Cardinality can be of different types
– One-to-One
– One-to-Many
– Many-to-One
– Many-to-Many
One-to-One
• When each entity in each entity set can take
part only once in the relationship, the
cardinality is one-to-one
• Example
One-to-Many
• In one-to-many mapping as well where each
entity can be related to more than one
relationship and the total number of tables
that can be used in this is 2
• Let us assume that one surgeon department
can accommodate many doctors
• So the Cardinality will be 1 to M
• It means one department has many Doctors
One to many (Contd..)
Many-to-One
• When entities in one entity set can take part
only once in the relationship set and entities
in other entity sets can take part more than
once in the relationship set, cardinality is
many to one
Many to one (Contd..)
Many-to-Many
• When entities in all entity sets can take part
more than once in the relationship cardinality
is many to many
• For example, student S1 is enrolled in C1 and
C3 and Course C3 is enrolled by S1, S3, and S4.
So it is many-to-many relationships
Many to many (Contd..)
Participation Constraint
• Participation Constraint is applied to the entity
participating in the relationship set
• Total Participation
• Each entity in the entity set must participate
in the relationship
• If each student must enroll in a course, the
participation of students will be total
• Total participation is shown by a double line in
the ER diagram
Participation Constraint
• Partial Participation
• The entity in the entity set may or may NOT
participate in the relationship
• If some courses are not enrolled by any of the
students, the participation in the course will
be partial
Total and Partial participation
Example
Example
Extended E-R Features
• Specialization
• Generalization
• Higher- and lower-level entity sets
• Attribute inheritance
• Aggregation
Specialization
• An entity set may include subgroupings of entities that are
distinct in some way from other entities in the set.
• The process of designating subgroupings within an entity
set is called specialization
• The specialization of person allows us to distinguish among
person entities according to whether they correspond to
employees or students
• The specialization relationship may also be referred to as a
superclass-subclass relationship
• Example :The university could create two specializations of
student, namely graduate and undergraduate
– Overlapping specialization
– Disjoint specialization
Specialization (Contd..
)
• For an overlapping specialization (as is the
case for student and employee as
specializations of person), two separate
arrows are used.
• For a disjoint specialization (as is the case for
instructor and secretary as specializations of
employee), a single arrow is used
Generalization
• Generalization proceeds from the recognition
that a number of entity sets share some
common features (namely, they are described
by the same attributes and participate in the
same relationship sets)
Specialization and generalization
Attribute Inheritance
• Attribute inheritance: allows lower level
entities to inherit the attributes of higher level
entities and vice versa
• Example: Car entity is an inheritance
of Vehicle entity ,So Car can acquire attributes
of Vehicle
• Example:car can acquire Model attribute
of Vehicle
Aggregation
• An ER diagram is not capable of representing the relationship
between an entity and a relationship which may be required in
some scenarios
• In those cases, a relationship with its corresponding entities is
aggregated into a higher-level entity
• Aggregation is an abstraction through which we can represent
relationships as higher-level entity sets
• For Example, an Employee working on a project may require some
machinery
• So, REQUIRE relationship is needed between the relationship
WORKS_FOR and entity MACHINERY
• Using aggregation, WORKS_FOR relationship with its entities
EMPLOYEE and PROJECT is aggregated into a single entity and
relationship REQUIRE is created between the aggregated entity and
MACHINERY.
Aggregation
Symbols used in ER notation
Alternative ER notations
Thank You

Database Design and Entity relationship Model.pptx

  • 1.
  • 2.
    Topics to becovered • Database design & E-R Model • Entity–Relationship model (E-R model) • E-R Diagrams-Constraints • Extended E-R features
  • 3.
    Database design • Thedatabase designer needs to interact extensively with domain experts and specify the user requirements • The designer chooses a data model and, by applying the concepts of the chosen data model, translates these requirements into a conceptual schema of the database • At the stage of conceptual design, the designer can review the schema to ensure it meets functional requirements
  • 4.
    Database design (Contd..) •Logical-design phase – The conceptual schema defined using the entity- relationship model is converted into a relation schema in this phase • Physical-design phase – The physical features of the database are specified in this phase
  • 5.
    ER Model • TheEntity Relational Model is a model for identifying entities to be represented in the database and representation of how those entities are related • The ER data model specifies enterprise schema that represents the overall logical structure of a database graphically
  • 6.
    Why Use ERDiagrams In DBMS? • ER diagrams are used to represent the E-R model in a database, which makes them easy to convert into relations (tables) • ER diagrams provide the purpose of real-world modeling of objects which makes them intently useful • ER diagrams require no technical knowledge and no hardware support • These diagrams are very easy to understand and easy to create even for a naive user • It gives a standard solution for visualizing the data logically
  • 7.
    Symbols Used inER Model • Rectangles: Rectangles represent Entities in the ER Model • Ellipses: Ellipses represent Attributes in the ER Model • Diamond: Diamonds represent Relationships among Entities • Lines: Lines represent attributes to entities and entity sets with other relationship types • Double Ellipse: Double Ellipses represent Multi-Valued Attributes • Double Rectangle: Double Rectangle represents a Weak Entity
  • 8.
  • 9.
  • 10.
  • 11.
    Entity Entity can beany real world object
  • 12.
    Entity Set An entityset is a set of entities of the same type that share the same properties, or attributes.
  • 13.
    Strong Entity • Astrong entity is not dependent on any other entity in the schema • A strong entity will always have a primary key • Strong entities are represented by a single rectangle • The relationship of two strong entities is represented by a single diamond • Various strong entities, when combined together, create a strong entity set
  • 14.
    Weak entity • Aweak entity is dependent on a strong entity to ensure its existence • Unlike a strong entity, a weak entity does not have any primary key • It instead has a partial discriminator key • A weak entity is represented by a double rectangle • The relation between one strong and one weak entity is represented by a double diamond
  • 15.
  • 16.
  • 17.
    Attributes Attributes are theproperties that define the entity type. For example, Roll_No, Name, DOB, Age, Address, and Mobile_No are the attributes that define entity type Student.
  • 18.
    Key Attribute The attributewhich uniquely identifies each entity in the entity set is called the key attribute. For example, Roll_No will be unique for each student In ER diagram, the key attribute is represented by an oval with underlying lines
  • 19.
    Composite Attribute • Anattribute composed of many other attributes is called a composite attribute • For example, the Address attribute of the student Entity type consists of Street, City, State, and Country • In ER diagram, the composite attribute is represented by an oval comprising of ovals
  • 20.
  • 21.
    Multivalued Attribute An attributeconsisting of more than one value for a given entity For example, Phone_No (can be more than one for a given student) In ER diagram, a multivalued attribute is represented by a double oval
  • 22.
    Derived Attribute • Anattribute that can be derived from other attributes of the entity type is known as a derived attribute • E.g.; Age (can be derived from DOB) • In ER diagram, the derived attribute is represented by a dashed oval
  • 23.
    Example Student Entity Setwith its attributes
  • 24.
    Entity-Relationship Diagram ER diagramcorresponding to instructors and students
  • 25.
    Relationship Type • ARelationship Type represents the association between entity types • For example, ‘Enrolled in’ is a relationship type that exists between entity type Student and Course • In ER diagram, the relationship type is represented by a diamond and connecting the entities with lines
  • 26.
  • 27.
    Relationship Set • Aset of relationships of the same type is known as a relationship set • The following relationship set depicts S1 as enrolled in C2, S2 as enrolled in C1, and S3 as registered in C3
  • 28.
  • 29.
    Degree of aRelationship Set • The number of different entity sets participating in a relationship set is called the degree of a relationship set • Different types of degree of a Relationship set are – Unary Relationship – Binary Relationship – n-ary Relationship
  • 30.
    Unary Relationship When thereis only ONE entity set participating in a relation, the relationship is called a unary relationship
  • 31.
    Binary Relationship When thereare TWO entities set participating in a relationship, the relationship is called a binary relationship. For example, a Student is enrolled in a Course.
  • 32.
    n-ary Relationship • Whenthere are n entities set participating in a relation, the relationship is called an n-ary relationship.
  • 33.
    Cardinality • The numberof times an entity of an entity set participates in a relationship set is known as cardinality. • Cardinality can be of different types – One-to-One – One-to-Many – Many-to-One – Many-to-Many
  • 34.
    One-to-One • When eachentity in each entity set can take part only once in the relationship, the cardinality is one-to-one • Example
  • 35.
    One-to-Many • In one-to-manymapping as well where each entity can be related to more than one relationship and the total number of tables that can be used in this is 2 • Let us assume that one surgeon department can accommodate many doctors • So the Cardinality will be 1 to M • It means one department has many Doctors
  • 36.
    One to many(Contd..)
  • 37.
    Many-to-One • When entitiesin one entity set can take part only once in the relationship set and entities in other entity sets can take part more than once in the relationship set, cardinality is many to one
  • 38.
    Many to one(Contd..)
  • 39.
    Many-to-Many • When entitiesin all entity sets can take part more than once in the relationship cardinality is many to many • For example, student S1 is enrolled in C1 and C3 and Course C3 is enrolled by S1, S3, and S4. So it is many-to-many relationships
  • 40.
    Many to many(Contd..)
  • 41.
    Participation Constraint • ParticipationConstraint is applied to the entity participating in the relationship set • Total Participation • Each entity in the entity set must participate in the relationship • If each student must enroll in a course, the participation of students will be total • Total participation is shown by a double line in the ER diagram
  • 42.
    Participation Constraint • PartialParticipation • The entity in the entity set may or may NOT participate in the relationship • If some courses are not enrolled by any of the students, the participation in the course will be partial
  • 43.
    Total and Partialparticipation
  • 44.
  • 45.
  • 46.
    Extended E-R Features •Specialization • Generalization • Higher- and lower-level entity sets • Attribute inheritance • Aggregation
  • 47.
    Specialization • An entityset may include subgroupings of entities that are distinct in some way from other entities in the set. • The process of designating subgroupings within an entity set is called specialization • The specialization of person allows us to distinguish among person entities according to whether they correspond to employees or students • The specialization relationship may also be referred to as a superclass-subclass relationship • Example :The university could create two specializations of student, namely graduate and undergraduate – Overlapping specialization – Disjoint specialization
  • 48.
    Specialization (Contd.. ) • Foran overlapping specialization (as is the case for student and employee as specializations of person), two separate arrows are used. • For a disjoint specialization (as is the case for instructor and secretary as specializations of employee), a single arrow is used
  • 49.
    Generalization • Generalization proceedsfrom the recognition that a number of entity sets share some common features (namely, they are described by the same attributes and participate in the same relationship sets)
  • 50.
  • 51.
    Attribute Inheritance • Attributeinheritance: allows lower level entities to inherit the attributes of higher level entities and vice versa • Example: Car entity is an inheritance of Vehicle entity ,So Car can acquire attributes of Vehicle • Example:car can acquire Model attribute of Vehicle
  • 52.
    Aggregation • An ERdiagram is not capable of representing the relationship between an entity and a relationship which may be required in some scenarios • In those cases, a relationship with its corresponding entities is aggregated into a higher-level entity • Aggregation is an abstraction through which we can represent relationships as higher-level entity sets • For Example, an Employee working on a project may require some machinery • So, REQUIRE relationship is needed between the relationship WORKS_FOR and entity MACHINERY • Using aggregation, WORKS_FOR relationship with its entities EMPLOYEE and PROJECT is aggregated into a single entity and relationship REQUIRE is created between the aggregated entity and MACHINERY.
  • 53.
  • 54.
    Symbols used inER notation
  • 55.
  • 56.