740 likes | 757 Views
Learn the main phases and characteristics of ER modeling, including components, definitions, and attribute classifications. Understand entity types, sets, keys, and relationships, with a focus on database design principles. Figures from renowned authors Elmasri, Navathe, and Connolly are adapted for clarity.
E N D
Chapter 1 Entity Relationship Model
Chapter 3 : Objectives • Main Phases of Database Design • Characteristics of ER Model • Components of ER Model • Definitions • Classification of Attributes • Entity Types • Entity Set • Key attribute Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Chapter 3 : Objectives (Continued.) • Relationship Types • Recursive Relationships: • Structural Constraints on Relationship Types: • Attributes on Relationship Types • Weak Entity Type • Problems with ER Models Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Main Phases of Database Design • Database Design Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Introduction • E-R model facilitates database design by allowing the specification of an “enterprise schema” which represents the overall logical structure of a database. • The E-R model is extremely useful in mapping the meanings and interactions of real-world enterprises onto a conceptual schema. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Characteristics of ER Model • Express the logical properties of an enterprise database • No physical DBMS • Proposed by Dr. Peter Chen Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Components of ER Model • Entity, Entity Type, Entity Set • Attribute • Key (Identifier) • Relationship, Relationship Type, Relationship Set • Structural Constraints on relationships Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Definitions • A Database can be modeled as : • a collection of entities • relationships among entities. • Entity: • An object in the real world with an independent existence • Is distinguishable from other objects • could have a physical existence or a conceptual existence Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example (Entity) • Example: person, company, event, plant • More Specific example: Consider University of Windsor as a large enterprise. • Entities : • Ritu (Employee) • John Smith (Student) … Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Attribute Attribute: the property that describes an entity or a relationship type. Examples: Student : id, fname, lname, yrAdmin Employees: id, fname, lname, position ER : Domain of Attributes: Set of values that may be assigned to that attribute for each entity (set of permitted values) . Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Entity Types A collection of entities that have the same attributes (describes the intension of a database). ER : • Example : EMPLOYEES, STUDENTS Entity Type Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Entity Set Entity Set : The collection of all entities of a particular entity type in the database at any point in time. (Extension of the database) Attributes are properties possessed by all members of an entity set . Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Classification of Attributes 1.Simple ~ Composite • Simple Attribute : • Attribute composed of a single component with an independent existence. • Composite Attribute • Attribute composed of multiple components, each with an independent existence. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Classification of Attributes 2. Single-Valued ~ Multi-Valued Single-valued Attribute • Attribute that holds a single value for each occurrence of an entity type. Multi-valued Attribute { }, • Attribute that holds multiple values for each occurrence of an entity type. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Classification of Attributes 3. Stored ~ Derived Derived Attribute • Attribute that represents a value that is derivable from value of a related attribute, or set of attributes, not necessarily in the same entity type. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Classification of Attributes • NULL Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Key attribute • Key attribute : An attribute of an entity type whose values are distinct for each individual entity in the collection. • ER : Student_Id Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example : COMPANY Database: 1. The company is organized into departments. Each department has a unique name, a unique number, and a particular employee who manages the department. We keep track of the start date when that employee began managing the department. A department may have several locations. 2. A department controls a number of projects, each of which has a unique name, a unique number, and a single location. 3. We store each employee’s name, social security number ,address, salary, sex, and birth date. An employee is assigned to one department but may work on several projects, which are not necessarily controlled by the same department. We keep track of the number of hours per week that an employee works on each project. We also keep track of the direct supervisor of each employee. 4. We want to keep track of the dependents of each employee for insurance purposes. We keep each dependent’s first name, sex, birth date, and relationship to the employee. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Preliminary design of entity types for the COMPANY Database • DEPARTMENT • Name, Number, {Locations}, Manager, ManagerStartDate • PROJECT • Name, Number, Location, ControllingDepartment • EMPLOYEE • Name(FName, MInit, LName), SSN, Sex, Address, Salary, BirthDate, Department, Supervisor, {WorkOn (Project, Hours)} • DEPENDENT • Employee, DependentName, Sex, BirthDate, Relationship Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Ritu 315 Course Employee Relationship • A relationship is an association among entities. Teaches Relationship Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Relationship Types A relationship type R among n entity types E1 .. En is a set of relationship instances r i where each r i associates n individual entities (e1, e2, …. en) and each entity ej in ri is a member of entity type Ej, 1<=j<=n. Ej is called the participating entity type. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example • An employee works for a department Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
WORKS_FOR EMPLOYEE DEPARTMENT Example Relationship instances : r1(e1, d1) r2(e2, d2) r3(e3, d1) ……….. Relationship type: WORKS_FOR • ER : Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example • ER Diagram? Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example ER Diagram? Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
SUPERVISION EMPLOYEE Recursive Relationships: The same entity type participates more than once in a relationship type in different roles. Each role is given a name. Example : Roles are optional – they clarify semantics of a relationship Supervisee(2) Supervisor(1) Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Recursive Relationships Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Attributes of Relationship Types • A relationship type can have attributes. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Degree of a relationship Degree of a relationship: Number of relations taking part in a relationship type. • Binary Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Structural Constraints on Relationship Types: • Limit the possible combination of entities • Represent business rules established by the user or company. • 2 Structural Constraints : • Cardinality Ratio • Participation Constraint Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Cardinality Ratio Cardinality Ratio : number of relationship instances that an entity can participate in. SHOWN BY PLACING APPROPRIATE NUMBER ON THE LINK. Examples : 1:N, 1:1 , M:N Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Participation Constraint Participation Constraint: specifies whether the existence of an entity depends on its being related to another entity via the relationship type. SHOWN BY DOUBLE LINING THE LINK - Total (Existence dependency) ER : = - Partial Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Weak Entity Type Definition: A weak entity type is one that meets 2 conditions : 1. It is existence dependent; that is, it cannot exist without the entity with which it has a relationship. 2. It has a (primary) key that is partially or totally derived from the parent entity in the relationship. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Weak Entity Type -don't have key attributes of their own -Partial key -Identifying Entity Type ER - -Weak entity types always have a total participation constraint with respect to its identifying relationship. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example :ER for COMPANY database Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Alternate ER Diagram Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example 1 : Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Example 2 • Draw an ER diagram to show the relationship between CLUB_MEMBER and LOCKER. • Assume that every club member must have a locker, though a locker need not have a club member assigned to it. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Phases of DB Design Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Relational DB Model :Logical View of Data • Logical Model proposed in 1970 by Codd • Designer focuses on logical representation rather than physical • Use of table advantageous • Structural and data independence • Related records stored in independent tables • Logical simplicity • Allows for more effective design strategies Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Definitions • A relation is a table with columns and rows. • Only applies to logical structure of the database, not the physical structure. • Attribute is a named column of a relation. • Attribute Domain is the set of allowable values for one or more attributes. • Tuple is a row of a relation : rows represent a single entity Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Definitions • Row/column intersection represents single value • Degree is the number of attributes in a relation. • Cardinality is the number of tuples in a relation. • Relational Database is a collection of normalized relations with distinct relation names. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Properties of a relation • The relation has a name that is distinct from all other relation names in the database schema. • Theoretically, ordering of tuples may have no significance. • The order of attributes has no significance. • Each cell of a relation contains exactly one atomic value. • Each attribute has a distinct name. • The values of an attribute are all from the same domain. • Each tuple is distinct – there are no duplicate tuples. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Examples of relation Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Examples of Attribute Domains Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Mathematical Definition of Relation - Consider two sets, D1 & D2, where D1 = {2, 4} and D2 = {1, 3, 5}. Cartesian product, D1 X D2, is set of all ordered pairs, where first element is member of D1 and second element is member of D2. => D1 X D2 = {(2, 1), (2, 3), (2, 5), (4, 1), (4, 3), (4, 5)} - Any subset of Cartesian product is a relation e.g: R = {(2,1),(4,1)} - Mathematically, r(R) is a subset of the Cartesian product of the domains that define R. => r(R) subsetOf (dom(A1) × dom(A2) ….× dom(An)) Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Definitions • Relation Schema R denoted by R(A1,A2, …. An) is made up of a relation name R and a list of attributes A1, A2….An and domain name D1,D2,….Dn pairs. ( Each Ai has a Di ) • Relational database schema is a set of relational schemas, each with a distinct name. • Relation instance ( relation) r of a relation R(A1,A2,…..An) also denoted by r(R) is a set of n-tuples {t1….tm}where each n-tuple t is a list of n-values t=<v1,v2….vn> where 1≤vi≤n is an element of dom(Ai) • R: schema of the relation • R is also called the intension of a relation • r is also called the extension of a relation Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Relational keys • Superkey • Candidate Key (K) • Primary Key • Alternate keys • Foreign Keys • Surrogate keys Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Superkey • An attribute or set of attributes that uniquely identifies a tuple in a relation. • Every relation has at least one super key. Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly
Candidate Key (K) • Superkey such that no proper subset of K is a superkey within the relation. • K is a minimal superkey. • K is a super key of R with the additional property that removing any attribute A from K leaves a set of attributes K’ that is not a superkey of R. • In each tuple of a relation R, values of K uniquely identify that tuple (Uniqueness). • No proper subset of K has the uniqueness property (irreducibility). Ritu Chaturvedi Some figures adapted from Fundamentals of database systems by Elmasri and Navathe and By T. Connolly