1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen 2002-2008 Introduction to Conceptual Database Design.

Slides:



Advertisements
Similar presentations
CHAPTER OBJECTIVE: NORMALIZATION THE SNOWFLAKE SCHEMA.
Advertisements

Chapter 2.1 V3.1 Napier University Dr Gordon Russell
primary key constraint foreign key constraint
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Natural Joins These slides are licensed.
ENTITY RELATIONSHIP MODELLING
Ch5: ER Diagrams - Part 1 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
IT420: Database Management and Organization
Copyright © 2015 Pearson Education, Inc. Database Design Chapters 17 and
Design Principles: Faithfulness
THE RELATIONAL DATABASE MODEL & THE DATABASE DEVELOPMENT PROCESS Fact of the Week: According to a Gartner study in ‘06, Microsoft SQL server had the highest.
Monash University Week 7 Data Modelling Relational Database Theory IMS1907 Database Systems.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Chapter Five Data Modeling with the Entity-Relationship Model.
CS424 PK, FK, FD Normalization Primary and Foreign Keys Primary and foreign keys are the most basic components on which relational theory is based. Primary.
Ch5: ER Diagrams - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
IT 244 Database Management System Data Modeling 1 Ref: A First Course in Database System Jeffrey D Ullman & Jennifer Widom.
DeSiamorewww.desiamore.com/ifm1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Module Title? DBMS E-R Model to Relational Model.
Week 6 Lecture Normalization
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen M:N Relationships & Bridge Classes These.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relationship Classes & N-ary Relationships.
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
Concepts and Terminology Introduction to Database.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Dependent & Identifying Relationships.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Basic Normal Forms These slides are licensed.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Conceptual State Constraints These slides.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Advanced Normalization These slides are.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen :1 Relationships These slides are licensed.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
Functional Dependencies and Normalization for Relational Databases.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
DataBase Management System What is DBMS Purpose of DBMS Data Abstraction Data Definition Language Data Manipulation Language Data Models Data Keys Relationships.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
DeSiamorePowered by DeSiaMore1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Msigwaemhttp//:msigwaem.ueuo.com/1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Description and exemplification of entity-relationship modelling.
Entity-Relationship Model
1 Functional Dependencies and Normalization Chapter 15.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational Mapping with Constraints &
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Conditions & Roles These slides are licensed.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Constraints These slides.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen The Relational Model & Relational Mapping.
WXGE 6101 DATABASE CONCEPTS & IMPLEMENTATIONS. Lesson Overview The Relational Model Terminology of relational model. Properties of database relations.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Subqueries These slides are licensed under.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Object-Relational Database Programming.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Grouping These slides are licensed under.
Ch 7: Normalization-Part 1
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Roles & Constraints These slides are licensed.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Inner Joins These slides are licensed.
1 Information System Analysis Topic-3. 2 Entity Relationship Diagram \ Definition An entity-relationship (ER) diagram is a specialized graphic that illustrates.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
1 Entity Relationship Approach u Top-down approach to data modeling u Uses diagrams u Normalization - confirms technical soundness u Entity Relationship.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Functional Dependencies & Normalization.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
COP Introduction to Database Structures
CSIS 115 Database Design and Applications for Business
Relational Normalization Theory
Translation of ER-diagram into Relational Schema
Copyright © Ellis Cohen Consistency & Initialization
Copyright © Ellis Cohen
Presentation transcript:

1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Conceptual Database Design These slides are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. For more information on how you may use them, please see

2© Ellis Cohen Overview of Lecture Entity Classes Relationships & ER Diagrams 1:M Relationship Design Multiple Relationships & The Fan Traps Conceptual Design Other ER Models Mandatory Participation Reflexive 1:M Relationships Class Identification & Surrogate Keys Redundancy & Anomalies Simple Functional Dependencies Simple Conceptual Normalization

3© Ellis Cohen Entity Classes

4© Ellis Cohen Conceptual Modeling Conceptual Modeling is a way of designing systems involving collections of tables by focusing on Entities –an abstraction of tuples Entity Classes –an abstraction of tables Relationships –between entities in different entity classes Using diagrams called ER diagrams (or Entity-Relationship Diagrams)

5© Ellis Cohen Tables as Themes Every table has a theme -- e.g. Employees Every row represents an instance of that theme -- e.g. a single Employee A row represents a single Employee empno ename sal comm Employees 7499ALLEN MARTIN BLAKE KING TURNER STERN1500

6© Ellis Cohen Columns as Attributes Every column represents an attribute related to the theme -- e.g. the name or salary of an Employee empno ename sal comm Employees Primary Key is underlined Uniquely identifies an employee 7499ALLEN MARTIN BLAKE KING TURNER STERN1500

7© Ellis Cohen Rows as Objects/Entities empno: 7654 ename : MARTIN sal : 1250 comm : 1400 an Employee Object It can be useful to think of each row as an object or entity and the table as a collection of these entities. The columns of the table correspond to the instance variables for each object It can be useful to think of each row as an object or entity and the table as a collection of these entities. The columns of the table correspond to the instance variables for each object empno ename sal comm Employees 7499ALLEN MARTIN BLAKE KING TURNER STERN1500

8© Ellis Cohen Entity Classes In conceptual modeling, we focus on the entity class which represents the class of entities with the same theme. In general (but as we will see, not always), an entity class is implemented by a table in a relational database

9© Ellis Cohen Modeling Entity Classes Employee empno ename sal comm Employee Sometimes we include all the attributes Sometimes we don't Visual Conceptual Model (Crow Magnum) Textual Conceptual Model (Brief ConText) Employee( empno, ename, sal, comm ) Employee Sometimes we just include the primary key empno

10© Ellis Cohen Attributes Types Employee empno  a number ename  a string sal  a dollar amount comm  a dollar amount Keep attribute types simple Complex attribute types often mean you need to rethink your design or be more specific

11© Ellis Cohen Relationships and ER Diagrams

12© Ellis Cohen ER (Entity-Relationship) Diagrams (Crow Magnum style) The Crow's foot at Employee means … A Dept can have MANY Employees No Crow's foot at Dept, so … An Employee works for no more than ONE Dept Dept works for Crows Foot relationship characterization empno ename sal comm deptno dname Employee Depicts a relationship between Employees and Depts

13© Ellis Cohen ER & Instance Diagrams DeptEmployee works for 7698BLAKE ALLEN MARTIN STERN TURNER SALES 30ACCOUNTING * ER Diagram Entity Class Relationship Corresponds to links between instances of the related classes Instance Diagram Shows example instances and the links between them Entity Instances Links

14© Ellis Cohen Instance Diagrams & Navigation Links are the basis of navigation between instances. We will see later that there are SQL queries which effectively find the tuples in one entity class which are related to the tuples in another entity class. So we can write SQL to find information about The dept associated with an employee All the employees who work for a department 7698BLAKE ALLEN MARTIN STERN TURNER SALES 30ACCOUNTING Links

15© Ellis Cohen Entities & Links as Persistent Data Every –entity instance of an entity class –link instance of a relationship Represents –data persistently stored in a database –information needed to answer a query (e.g. what’s the salary of ALLEN?, what department does ALLEN work in?) The ONLY reason to represent an entity class or a relationship in a conceptual model is because the requirements clearly indicate they are necessary to provide information needed for some query

16© Ellis Cohen :M (1 to Many) Relationships an Employee works for (at most) 1 Dept a Dept has any number (i.e. M) of Employees Dept Employee works for empno deptno Child Entity ClassParent Entity Class

17© Ellis Cohen Easy Crow Magnum Relationships Dept Employee works for Dept Employee works for empno deptno Easy Crow Magnum is meant for quickly drawing designs on paper or a whiteboard no attributes shown in this example just primary keys shown in this example Visual Conceptual Model (Easy Crow Magnum) In Easy Crow Magnum, don't draw the box outlines on entity classes

18© Ellis Cohen Visual & Textual Models for Relationships TEXTUAL Conceptual Model (Brief ConText) (*) Employee works for Dept VISUAL Conceptual Model (Crow Magnum) relationship characterization Dept Employee works for relationship characterization

19© Ellis Cohen Inverse Relationships TEXTUAL Conceptual Model (Brief ConText) Dept contains (*) Employee VISUAL Conceptual Model (Crow Magnum) relationship characterization Dept Employee contains relationship characterization

20© Ellis Cohen Indicating Relationship Direction Dept Employee works for Must indicate the relationship direction if it is not the natural reading direction (L-to-R, top-to-bottom) Dept Employee works for Dept Employee contains Dept Employee contains Dept Employee contains Dept Employee works for

21© Ellis Cohen Naming Relationships Entity Classes Employee( empno, ename, addr ) Dept( deptno, dname ) Relationships DeptAssignment DeptAssignment: (*) Employee works for Dept It is useful, though not required, to name relationships in ConText Relationship characterization Choose a relationship name so that it clearly and uniquely identifies the relationship Relationship name

22© Ellis Cohen M:N (Many-to-Many) Relationships EmployeeProject assigned to (*) Employee assigned to (*) Project Visual Conceptual Model (Crow Magnum) Textual Conceptual Model (Brief ConText) Each employee may be assigned to a number of projects Each project may have a number of employees

23© Ellis Cohen M:N Related Instances empno ename address empnopno EmployeeProject assigned to 7499ALLEN MARTIN BLAKE KING TURNER STERN … pno pname … 2621… 2622…

24© Ellis Cohen :1 (One-to-One) Relationships DeskEmployee assigned to Each employee may be assigned to at most one desk Each desk may be assigned to at most one employee Desk assigned to Employee Visual Conceptual Model (Crow Magnum) Textual Conceptual Model (Brief ConText)

25© Ellis Cohen :1 Related Instances empnodeskno 311… deskno … EmployeeDesk assigned to 312… 313… empno ename address 7499ALLEN MARTIN BLAKE KING TURNER STERN...

26© Ellis Cohen :M Relationship Design

27© Ellis Cohen :M Relationship Exercise Come up with an Easy Crow Magnum ER Diagram of a 1:M Relationship between two entity classes (not a 1:1 or M:N relationship, and not Dept/Employee) The diagram must 1.show the name of each entity class 2.show main attributes of each entity class 3.include the primary key (and underline it) 4.show the relationship characterization Dept works for empno ename sal deptno dname Employee

28© Ellis Cohen Choosing Relationship Characterizations ER diagrams are meant for communicating designs as clearly as possible. It is worth taking the time to choose the best possible relationship characterization. Dept Employee works for Dept Employee employs Dept Employee has Dept Employee has

29© Ellis Cohen Mistaking 1:M for M:N persid flavid Person Ice Cream Flavor likes persid flavid Person Ice Cream Flavor likes It is common to consider relationships from only one perspective. Think about a person. They like many ice cream flavors. Must be 1:M? But in fact, many persons like the same ice cream flavor, so it is actually M:N. Specifying the relationship characterization is crucial. The "favorite flavor" relationship is 1:M, but in the other direction! persid flavid Person Ice Cream Flavor favorite flavor

30© Ellis Cohen Choosing the Wrong Key persid title Person Book owns This case is somewhat similar to the previous one. A person owns many books, each one identified by their title. So, it must be 1:M. In fact, may people own a book with a particular title (e.g. there are lots of copies of "Gone with the Wind"). The problem is that the wrong primary key has been used. Imagine that every copy of every book ever published was given a unique serial number which uniquely identifies a single book instance. That's what would be needed to really have a 1:M relationship! persid serialnum Person Book owns

31© Ellis Cohen Singleton Classes Boston University Building owns bldgno Boston University is a singleton entity class, which only has a single entity (i.e. a single tuple) in it. Either leave it out entirely, or replace it with a more general entity class DON'T DO THIS DO THIS INSTEAD University Building owns bldgno name Building bldgno OR THIS

32© Ellis Cohen Singleton Classes & M:N Relationships Microsoft Building uses bldgno Generalizing singleton entity classes can result in M:N relationships DON'T DO THIS Company Building uses bldgno name Building bldgno DO THIS INSTEAD OR THIS

33© Ellis Cohen Entity Classes vs. Attributes Salary Employee makes empno ename salary Employee empno ename salary Don't create an entity class for something that really does not need to have a "life of its own", but ought to simply be an attribute of another entity class DON'T DO THIS DO THIS INSTEAD

34© Ellis Cohen Attribute vs. Entity Class Principles Dept Employee empno ename deptno Employee empno ename deptno Reasons for upgrading attributes to entity classes: 1.Substance: It emphasizes that a department is something that can and should stand in its own right 2.Extensibility: One might want to add attributes specific to a department (e.g. its name, location, etc.) 3.Multiplicity: It emphasizes that a department can have multiple employees associated with it 4.Association: It emphasizes that an employees cannot have an arbitrary deptno value, but that the employee is associated with a department which has a specific deptno Note that none of these reasons make sense for Salary (though multiplicity suggests that it might be useful to add a PayGrade Class, and make salary an attribute of a PayGrade)

35© Ellis Cohen Break Up Complex Attributes Employee empno ename assignments Assignment Employee empno ename assnid projnam rate startdate Do NOT use attributes that contain complex sets of details. Break them up into additional entity classes! Moreover, this should probably be replaced by a relationship with a Project entity class

36© Ellis Cohen Entity Attributes & Relationships Employee does not contain an attribute that identifies the Dept it is associated with (i.e. deptno). An employee is certainly associated with a department – but that is represented by the relationship between Employee and Dept. A deptno attribute in Employee would be an entity attribute (it identifies a Dept entity). This would not only be redundant (with the works for relationship), but wrong to include in a Conceptual Model [no conceptual foreign keys] * DeptEmployee works for deptno dname empno ename addr deptno Does NOT include deptno

37© Ellis Cohen Relationships & Persistence A relationship represents information which needs to be persistently stored in a database! If the information doesn't need to be stored and queried, don't represent it as a relationship Don't include relationships which simply show what a user can do or keep track of what a user has done, unless it is clear that information will be needed later! *

38© Ellis Cohen Multiple Relationships & The Fan Traps

39© Ellis Cohen Multiple Relationships Coach TeamPlayer TeamPlayerHealth Plan TeamPlayerChild has enrolled in works for has What do these diagrams mean?

40© Ellis Cohen The Fan Trap Employee DivisionDept works for divided into Suppose there are multiple divisions in a company, each divided into departments Every employee works for a division (and is assigned to a particular department in that division) What's wrong with the diagram below?

41© Ellis Cohen Fan Trap Instances 7698BLAKE 7499ALLEN 7654MARTIN 7986STERN 7844TURNER 10SALES 30ACCOUNTING It is impossible to determine which department an employee is assigned to! DIV A DIV B … …

42© Ellis Cohen The Reverse Fan Trap Division EmployeeDept employs works for Suppose a company has multiple divisions Every employee is employed by a division, and assigned to a particular department (in that division) What's wrong with this diagram? empnodeptnodivno

43© Ellis Cohen Reverse Fan Trap Instances 7698BLAKE 7499ALLEN 7654MARTIN 7986STERN 7844TURNER DIV A DIV B … 10SALES 30ACCOUNTING … Two employees in the same department could be assigned to different divisions Is there any way to prevent this when using this model?

44© Ellis Cohen Business Rules & The Reverse Fan Trap Division EmployeeDept employs works for empnodeptnodivno + Two employees who are in the same department must be in the same division We can prevent this problem by adding the business rule above! But how would this be enforced? Well, we'll see that we can write code that detects every time a change is made to the data in the database which might violate this business rule, and then ensures that the business rule is enforced! Are there any other problems with this model?

45© Ellis Cohen Deletion Anomalies & The Reverse Fan Trap 7698BLAKE 7499ALLEN 7654MARTIN 7986STERN 7844TURNER DIV A DIV B … 10SALES 30ACCOUNTING … Suppose STERN is the only employee in department 30. If STERN is terminated, there is no longer any way, to determine that dept 30 is in division B! So maybe we should try another model?

46© Ellis Cohen Resolving the Fan Traps EmployeeDeptDivision works for part of It is now possible to determine each employee's department & each department's division! We can also still tell which division an employee is assigned to, by following the link from the employee to the dept, and then from the dept to the division 7698BLAKE 7499ALLEN 7654MARTIN 7986STERN 7844TURNER 10SALES 30ACCOUNTING DIV A DIV B … …

47© Ellis Cohen Conceptual Design

48© Ellis Cohen Database Design Levels Conceptual Design / Model Model of the database design in terms that users will understand Logical Design / Model Description of the design in terms that can be directly used to build a database (This is called a Relational Model, if we are building an RDB) Physical Design / Model Additional design descriptions that specify or affect the data representation in physical storage

49© Ellis Cohen Database Design Process Requirements Physical Model using DDL & DCL Relational Model Conceptual Model Conceptual Design Relational Mapping Physical Mapping Actual Design of Tables in the Database A model used for communication with system analysts and UI designers

50© Ellis Cohen Conceptual Modeling (also known as Conceptual Design) starts with two activities Identify Entity Classes Identify Relationships between them

51© Ellis Cohen Identify Entity Classes Identify the classes of entities called for to support requirements Think of an entity as –a readily identifiable thing A potential entity class should have 1.Multiple instances (i.e. the requirements should imply the need for more than one entity of that class) 2.A clear set of attributes based on the requirements 3.A primary key to uniquely identify tuples

52© Ellis Cohen Design Exercise A university is divided into departments. Each department is made up of faculty members. Each department may have a number of degree-granting programs. Every student may only declare a major in a single program. Every student may be assigned a faculty member as an advisor. What are the entity classes needed?

53© Ellis Cohen Entity Classes Needed University: MAYBE, but it sounds like it's a singleton class Department: YES Faculty Member: YES Student: YES Person: MAYBE (ignore for now) (Degree-Granting) Program: YES Major: MAYBE (but it is simpler to just treat major as a relationship) between a student and a program Advisor: MAYBE (but it is simpler to treat advise as a relationship between Faculty Member and Student (also, Advisor is a subclass of Faculty Member, which is a bit too complicated to get into just yet)

54© Ellis Cohen Identify Relationships If the database needs to persistently keep track of a link/association between an entity of one class and an entity of another class The entity classes are related to one another Draw the Easy Crow Magnum diagram based on the identified entity classes. All 1:M Relationships!

55© Ellis Cohen Design Solution Faculty Member DepartmentProgram Student made up of offers majors in advises Faculty members sometimes have appointments in more than one department. The relationship would be 1:M if the requirement were " Each department is made up of faculty members; and each faculty member is only in one department, at most" Faculty Member Department

56© Ellis Cohen Relationship Exercise Bikeshop Bike ModelBike Part ModelPart has in stock part of sells instance of used on The model above describes the parts on bikes sold by a chain of bike-shops (i.e. there are multiple bike-shops). It contains both 1:M and M:N relationships, but the Crow's Feet have all been removed. Put them back where they belong!

57© Ellis Cohen Relationship Exercise Answer Bikeshop Bike ModelBike Part ModelPart has in stock part of used on sells instance of

58© Ellis Cohen Uses of 1:M Relationships EmployeeDental Plan enrolled in BikePart part of Part ModelPart instance of 1. Relationship between independent entity classes 2. Aggregation (Part/Whole) Relationship 3. Instance/Category Relationship

59© Ellis Cohen Entity Class Specificity Whenever we design entity classes, it is important to think VERY CAREFULLY about its specificity When designing the entity class Auto, we could mean –A kind of auto: Individual entities would be identified by model and year: e.g Honda Accord. Better to name this class Auto Model –A specific auto: Individual entities would be identified by their VIN (vehicle identification number): e.g. 614HT37994PL7394, but might also have a model and year (or maybe not) Sometimes a design will need multiple levels of specificity (related by a 1:M relationship – e.g. Bike & Bike Model).

60© Ellis Cohen Other ER Models

61© Ellis Cohen Chen 1:M ER Model Crow Magnum Chen Key constraint: The primary key of Employee not only uniquely identifies an employee (and their name & addr), but also uniquely identifies their associated department (its deptno & dname) EmployeeDept works for Employee Dept works for empno ename addr deptno dname Child Entity ClassParent Entity Class

62© Ellis Cohen UML 1:M ER Model UML Crow Magnum Associations (i.e. relationships) reflect the associations that one entity should or needs to have with other entities. EmployeeDept works for * EmployeeDept works for A department needs to be associated with multiple (*) employees – all the employees that work for it An employee only needs to be associated with, at most, a single department – the department it is in Child Entity ClassParent Entity Class 0..1

63© Ellis Cohen UML with Attributes UML Crow Magnum EmployeeDept works for * EmployeeDept works for 0..1 deptno dname empno ename addr PK empno ename addr PK deptno dname Using UML's icon notation for PK

64© Ellis Cohen Primary Key Representations in UML UML Dept « PK »deptno dname UML Dept PK deptno dname UML Dept deptno { PK } dname Use UML's stereotype notation, which is a way of associating domain-specific characteristics, enclosed in « guillemets », with a UML element Use UML's icon notation. An icon is a predefined arbitrary graphical symbol, in this case, to be used in place of a stereotype PK Use UML's property notation, which is a way of associating properties, enclosed in { curly braces }, with a UML element

65© Ellis Cohen UML Aggregation UML PartBike * When a 1:M relationship is a part/whole relationship (e.g. a bicycle part is a part of a bike), then UML uses a special aggregation symbol to depict it Crow Magnum PartBike part of In rare circumstances, UML also allows aggregation with M:N relationships as well 0..1

66© Ellis Cohen :M Relationships UML Chen Crow Magnum Easy Crow Magnum EmployeeDept works for EmployeeDept works for EmployeeDept works for * 0..1 Employee Dept works for

67© Ellis Cohen :1 Relationships EmployeeDesk sits at UML EmployeeDesk sits at Chen 0..1 EmployeeDesk EmployeeDesk Crow Magnum Easy Crow Magnum sits at

68© Ellis Cohen M:N Relationships EmployeeProject assigned to Chen No key constraints! EmployeeProject assigned to EmployeeProject Crow Magnum Easy Crow Magnum assigned to EmployeeProject assigned to * * UML

69© Ellis Cohen Mandatory Participation

70© Ellis Cohen Child Participation Mandatory: An Employee MUST work for 1 Dept Dept Employee Dept Employee works for Indeterminate Deferred participation design decision Child Entity ClassParent Entity Class

71© Ellis Cohen Mandatory Child Participation (Every employee is assigned to 1 department) 7698BLAKE ALLEN MARTIN STERN TURNER SALES 30ACCOUNTING Dept Employee works for Every Employee participates in a relationship with a Dept Child Entity ClassParent Entity Class

72© Ellis Cohen Non-Mandatory Child Participation (There may be employees with no dept) 7698BLAKE ALLEN MARTIN STERN TURNER SALES 30ACCOUNTING Dept Employee works for There are Employees who don't participate in a relationship with a Dept Child Entity ClassParent Entity Class

73© Ellis Cohen Mandatory Child Participation in UML UML Crow Magnum EmployeeDept works for * EmployeeDept works for an Employee must be assigned to 1 Dept 1 Child Entity ClassParent Entity Class

74© Ellis Cohen Parent Participation Mandatory: MUST be 1 Employee in every Dept Dept Employee Dept Employee Indeterminate: Deferred participation design decision works for Child Entity ClassParent Entity Class

75© Ellis Cohen Mandatory Parent Participation (Every department has at least 1 employee) 7698BLAKE ALLEN MARTIN STERN TURNER SALES 30ACCOUNTING Dept Employee works for Every Dept participates in a relationship with an Employee Child Entity ClassParent Entity Class

76© Ellis Cohen Non-Mandatory Parent Participation (There may be depts with no employees) Dept Employee works for 7698BLAKE ALLEN MARTIN STERN TURNER SALES 30ACCOUNTING 20RESEARCH There are Depts who don't participate in a relationship with Employees Child Entity ClassParent Entity Class

77© Ellis Cohen Mandatory Parent Participation in UML UML Crow Magnum EmployeeDept works for 1..* EmployeeDept works for a Dept must have at least 1 employee Child Entity ClassParent Entity Class 0..1

78© Ellis Cohen Reflexive 1:M Relationships

79© Ellis Cohen Reflexive Entity Attributes Employee empno ename addr mgr Suppose an employee can have a manager, (who is another employee) This could identify an employee's manager. Perhaps it would hold the empno or ename of the manager. IS THIS OK OR A BAD IDEA? DON'T DO THIS!

80© Ellis Cohen Entity Attributes & Relationships What's wrong with adding deptno as an attribute of Employee? DeptEmployee works for deptno dname empno ename addr deptno DON'T DO THIS!

81© Ellis Cohen Attributes vs Relationships Employee empno ename addr mgr DON'T DO THIS! mgr would be an entity attribute – an attribute whose value identifies some other entity – in this case, some other employee But entity attributes reflect relationships But entity attributes reflect relationships – e.g. an employee is related (by the manages relationship) to the employee who is their manager. The conceptual model is meant to show relationships. Replace entity attributes by relationships!

82© Ellis Cohen Reflexive Relationships Employee manages Visual Conceptual Model (Crow Magnum) Textual Conceptual Model (Brief ConText) Employee( empno, ename, addr ) Employee manages (*) Employee An employee may manage other employees This does not imply that a manager can manage themselves (which would probably be a bad idea!) It doesn’t disallow it either. We'll see how to do that later. empno ename addr

83© Ellis Cohen Reflexive Relationships & Instance Hierarchies 7698BLAKE ALLEN MARTIN JONES TURNER KING5000 Reflexive relationships commonly describe entity hierarchies: KING manages BLAKE & JONES BLAKE manages MARTIN & TURNER JONES manages ALLEN, etc.

84© Ellis Cohen Complete Conceptual Model with Attributes Sometimes, designers draw a more detailed diagram that includes the attributes of an entity class (sometimes JUST the primary key attributes) DeptEmployee works for deptno dname empno ename addr manages

85© Ellis Cohen Entity Classes Employee( empno, ename, addr ) Dept( deptno, dname ) Relationships WorksFor WorksFor: (*) Employee works for Dept Manages Manages: Employee manages (*) Employee Visual/Textual Conceptual Model DeptEmployee works for manages empnodeptno Note: here we chose to just show the primary keys Note: MUST list all conceptual attributes here Visual Conceptual Model (Crow Magnum) Textual Conceptual Model (Brief ConText)

86© Ellis Cohen Class Identification & Surrogate Keys

87© Ellis Cohen Entity Class Identification Exercise A clothing manufacturer identifies each style of item they make by their own unique stylecode. Items within the same style vary by size and color, and each such item is given an itemsku. Each style of item has a category identified by its catid. Create a conceptual model (UML or Easy Crow Magnum ER Diagram) for the manufacturer's database, which includes the following attributes itemsku e.g. 'FX311B-24M' stylecode e.g. '302' stylenam e.g. 'Hunting Bikini Brief' styledate e.g (when introduced) catid e.g. 'MU' catnam e.g. 'Mens Underwear' size e.g. 9 color e.g. 'red'

88© Ellis Cohen Answer to Entity Class Identification Exercise Item( itemsku, size, color ) Style( stylecode, stylenam, styledate ) Category( catid, catnam ) ItemStyle: (*) Item has Style StyleCategory: (*) Style has Category StyleItem has itemsku size color stylecode stylenam styledate Category has catid catnam TEXTUAL Conceptual Model (Brief ConText Entity Classes) VISUAL Conceptual Model (Easy Crow Magnum)

89© Ellis Cohen Surrogate Primary Key Item itemsku size color Item itemid itemsku size color vs Why would you add a surrogate key? Surrogate primary key: A new attribute added to an entity class or relation and used in place of the original primary key. Note: We often wait to add surrogate keys until we map the conceptual model to a relational model

90© Ellis Cohen Simple Candidate Keys Item itemid itemsku size color Simple Candidate Keys A simple candidate key is any attribute which uniquely identifies a tuple A designer chooses a primary key from one of the candidate keys Both itemid and itemsku uniquely identify an item

91© Ellis Cohen Redundancy & Anomalies

92© Ellis Cohen Normalization Problem In designing a conceptual model for employees with the attributes empno, ename, deptno, dname, addr What's wrong with just using a single entity class: Employee( empno, ename, deptno, dname, addr )?

93© Ellis Cohen Answer: What's Wrong … Entity Class Principles: substance, extensibility, multiplicity, association argue that there should be a Dept class Redundancy: deptno & dname Extra Work: If changed name of a department, would have to do it in multiple places Anomalies: Could change deptno without changing dname or vice versa.

94© Ellis Cohen Redundancy: deptno  dname empno deptno dname Employee 7654…30SALES… Entities with the same value for deptno have the same value for dname Including dname in the entity class is redundant, since it can be derived from deptno Redundancy causes duplicate work Suppose the company wants to change deptno 30 to be the Sales & Marketing department. That change must be made to multiple employees SUPPORT SALES ACCOUNTING SALES

95© Ellis Cohen Redundancy and Anomaly Redundancy can cause anomalies (inconsistencies) if modifications are not done carefully Update Anomaly: –Updating a value in a single cell can make the database inconsistent Insertion Anomaly: –Adding an entity can make the database inconsistent Deletion Anomaly: –Deleting some information can make the database inconsistent or cause unintended loss of information

96© Ellis Cohen Anomaly Examples Modification Anomaly: Modify 7654's dname to 'SUPPORT' (without changing its deptno) Insert Anomaly: Insert a new employee with a deptno of 20, and a dname of 'SUPPORT' Delete Anomaly: Delete employee 7986 (it’s the only employee in SUPPORT, and no other entity class keeps track that dept 50 is SUPPORT) Employee empno deptno dname 7654…30SALES… SUPPORT SALES ACCOUNTING SALES

97© Ellis Cohen Simple Functional Dependencies

98© Ellis Cohen Redundancy and Functional Dependencies Functional Dependencies Specify which attributes in a entity class are determined by other attributes Identify potential redundancies Help us see how to eliminate those redundancies (generating the conceptual model we really should have produced initially!)

99© Ellis Cohen Functional Dependencies (FD's) Dependencies among attributes A  B A functionally determines B B functionally depends on A The value of A uniquely determines a single value for B If two or more entities (of a specific entity class) have the same value for A, they have the same value for B (e.g. Every employee that has the same value for deptno – e.g. 30 has the same value for dname – e.g. SALES)

100© Ellis Cohen FD's for a Normalized Example Employee( empno, ename, addr ) empno  ename empno  addr This can also be written as empno  ename, addr orempno  { ename, addr } Also empno  empno (this is a trivial FD, which we usually don't write) empno can be used to lookup (and therefore uniquely determine) all the other attributes of an Employee tuple

101© Ellis Cohen Determinants & Dependents Determinant Dependent empno  addr

102© Ellis Cohen FD's for an Example with Redundancy Employee( empno, ename, deptno, dname, addr ) empno  ename empno  deptno empno  dname empno  addr However, also deptno  dname (possibly) dname  deptno This is a problem! deptno is NOT a candidate key It indicates redundancy!

103© Ellis Cohen Redundancy: deptno  dname Because deptno is not a candidate key, the same deptno value (e.g. 30) can appear multiple times. But deptno  dname, that is, two tuples with the same value of deptno have the same value of dname Voila! REDUNDANCY! empno deptno dname Employee 7654…30SALES… SUPPORT SALES ACCOUNTING SALES

104© Ellis Cohen Simple FD Exercise Assume you have (foolishly) designed a single Item entity class containing all of the following attributes itemsku e.g. 'FX311B-24M' stylecode e.g. '302' stylenam e.g. 'Hunting Bikini Brief' styledate e.g (when introduced) catid e.g. 'MU' catnam e.g. 'Mens Underwear' size e.g. 9 color e.g. 'red' Find all the simple FD's whose determinant is not a candidate key

105© Ellis Cohen Non-Candidate-Key FD's catid  catnam stylecode  stylenam stylecode  styledate stylecode  catid stylecode  catnam follows by transitive inference, because stylecode  catid & catid  catnam

106© Ellis Cohen Simple Conceptual Normalization

107© Ellis Cohen Simple Conceptual Normalization Given an entity class with a (non-trivial) functional dependency whose determinant is NOT a candidate key –Split out a new entity class –Make the determinant the primary key (or at least a candidate key) of the new class –Move all attributes that depend on it Employee( empno, ename, deptno, dname, addr ) deptno  dname Employee( empno, ename, addr ) Dept( deptno, dname ) Note: Most books only discuss Normalization at the Relational Design level. However, Conceptual Normalization, though not complete, is a way to improve a conceptual design. We'll examine Normalization in much more detail later in the term

108© Ellis Cohen Result of Simple Conceptual Normalization Each simple conceptual normalization step –adds one entity class –adds one 1:M relationship link Employee empno ename deptno dname addr Employee has empno ename addr Dept deptno dname deptno  dname

109© Ellis Cohen Conceptual Normalization Exercise Assume you have designed an Item entity class with the following attributes itemsku e.g. 'FX311B-24M' stylecode e.g. '302' stylenam e.g. 'Hunting Bikini Brief' styledate e.g (when introduced) catid e.g. 'MU' catnam e.g. 'Mens Underwear' size e.g. 9 color e.g. 'red' Find an FD with a non-candidate-key determinant, and use Conceptual Normalization to split out a new entity class. Continue doing this with all of the resulting entity classes until each of them are in Conceptual Normal Form.

110© Ellis Cohen ER Decomposition (a) StyleItem has itemsku size color stylecode stylenam styledate Category has catid catnam Item itemsku stylecode stylenam styledate catid catnam size color Item has itemsku size color Style stylecode stylenam styledate catid catnam stylecode  stylenam, styledate, catid catnam catid  catnam Each simple conceptual normalization step adds one entity class adds one relationship link Step 1 Step 2

111© Ellis Cohen ER Decomposition (b) StyleItem has itemsku size color stylecode stylenam styledate Category has catid catnam Item itemsku stylecode stylenam styledate catid catnam size color Item has itemsku stylecode stylenam styledate size color Category catid catnam catid  catnam stylecode  stylenam, styledate Each simple conceptual normalization step adds one entity class adds one relationship link Step 1 Step 2

112© Ellis Cohen Database Design Process Requirements Physical Model using DDL & DCL Relational Model Conceptual Model Conceptual Design & Conceptual Normalization Relational Mapping & Relational Normalization Physical Mapping