CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL (PART I) Modern Database Management 13th Edition Jeff Hoffer, Venkataraman Ramesh, Heikki Topi We learned in Chap 2 Database Analysis Chap 4: Transformation from ERD to relational model Copyright 2016 Pearson Education, Inc. We are moving into Database Disam
bigua - Data tion: m o del diagr mean a m - ; s E-R Relat data ional mod in 2-d el m t i m a b e les (c Part 1:
nsion eans urren a - 1 t cha l ) sho Define terms pter) state rt text me List five properties of relations - 2 ) gra nt, and p ca repre hikeys State two properties of candidate l senta n Define first, second, and third normal form tio mostly in PART II Describe problems from merging relations OBJECTIVES
Transform E-R and EER diagrams to relations Create tables with entity and relational integrity constraints Part 2: Use normalization to decompose anomalous Chapter 4 2016 Pearson Education, Inc. relations toCopyright well-structured relations 4-2 DATABASE SCHEMA (CH 1) External Schema
Conceptual Schema User Views Can be determined from business-function/data entity matrices [Fig 16; pasted as next slide] DBA determines schema for different users View of data architect or data administrator E-R models covered in Chapters 2 and 3 Internal Schema Logical structuresrepresentation for a type of data mgmt tech; covered in Chapter 4 (Relational model) structureshow dataInc.
are to be Chapter 4 Physical Copyright 2016 Pearson Education, 4-3 FIGURE 1-6 Example business function-to-data entity matrix Chapter 4 Can use this matrix to help with your DB project: Copyright 2016entities Pearson Education, Did I get the right for my Inc. biz functions? 4-4 INTRODUCTION OF BASIC CONCEPTS AND PROCEDURES Chapter 4
Copyright 2016 Pearson Education, Inc. 4-5 INTRODUCTION Logical DB design: process of transforming the conceptual data model (i.e., ERD) into a logical data model (i.e., relational models in this chap) Conceptual data modeling: getting the right requirements >>model the biz logic correctly biz rules Logical DB design: getting the requirements right >>correctly transform the biz logic for implementation An E-R data model is not a relational data model need normalization [2nd half of Ch 4]
ERD is developed for the purpose of Copyright 2016 Education, Inc.structuring understanding bizPearson rules, not Chapter 4 4-6 COMPONENTS OF RELATIONAL MODEL Data structure: Direct view (DB terms) Data manipulation (Chaps 5 & 6)
Tables (relation), rows (record), columns (field/attribute) (Chaps 2, 3, & 4) Powerful SQL operations for retrieving and modifying data Data integrity (Chaps 4 & 5) Copyright 2016 Pearson Education, Inc. Mechanisms for implementing Chapter 4 4-7 RELATION (P. 155); CORRESPONDENCE W ERD A relation is a named, two-dimensional table of data. (with specific requirements)
A table consists of rows (records) and columns (attributes or fields). Correspondence w E-R model: Relations (tables) correspond with entity types and with many-to-many relationship types (______ entity) 1. Columns correspond with attributes. 2.Chapter Rows correspond with entity 4 Copyright 2016 Pearson Education, Inc. 4-8 TEXT DESCRIPTION OF A RELATION We can express the structure of a relation by a shorthand notation (text
description): RELATION (attribute1, attribute2, attribute3, ) Example: PRODUCT( ) exercise NOTE: The word relation (in relational database) is NOT to be confused with the != model): word relationship on E-R Relati(in p Relationshi Chapter 4 Copyright 2016 Pearson Education, Inc. 4-9 KEY FIELDS Prim a ry k ey = Iden tifier
Keys are special fields that serve two main purposes: Primary key is an attribute or combination of attributes that uniquely identifies a row in a relation. Example: employee numbers, social security numbers, etc. -- guarantees that all rows are unique. Foreign keys are identifiers that enable a dependent relation (on the many side of a relationship) to refer to its parent relation (on the one side of the relationship). Keys can be simple (a single field) or composite (more than one field). Keys usually are used as indexes to speed up the A key can have >1
response to user queries Chapter 4 Copyright 2016 Pearson Education, Inc. attribute 4-10 FOREIGN KEY Foreign key: represent the relationship between two tables or relations An attribute in a relation that serves as the primary key of another (foreign) relation P.156: EMOPLYEE1(EmpID, Name, DeptName, Salary) DEPARTMENT(DeptName, Location, Fax) DeptName is a foreign key in EMPLOYEE1. It allows a user to associate any employee w the dept to which s/he is assigned. Chapter 4 Copyright 2016 Pearson Education, Inc.
4-11 PROPERTIES OF RELATION (P. 156) Requirements for a table to qualify as a relation: 1. 2. 3. 4. 5. 6. It must have a unique name. Every attribute value must be atomic 1. (not multivalued, not composite). Every row must be unique (cant have two rows with exactly the same values for all their fields). Attributes (columns) in tables must have unique names. tables ll a t o
n ; le b ta Theorder of the acolumns must be irrelevant. A relation is n s relatio are rows The order of the must be irrelevant. Relation < == > First Normal Form Chapter 4 Copyright 2016 Pearson st Education, Inc. NOTE: all relations are in 1 Normal form 4-12 REMOVING MULTIVALUED ATTRIBUTES FIG 4-2
Identify the multivalued attributes for several records (entity instances) Chapter 4 Copyright 2016 Pearson Education, Inc. 4-13 SCHEMAS (PP. 157-158) The structure of a DB is described thru schemas A DB can have any number of relations Two common methods for expressing schema: 1.
Short text statements (example: Slide 15) 2. RELATION (attribute1, attribute2, attribute3, ) EMPLOYEE (Emp_ID, LastName, FirstName, ) Graphical representation (example: Attr Attr Slide Attr1 Attr2 Attr3 Better means of 5 4 expressing Chapter 4 Each relation Copyrightrepresented 2016 Pearson Education,by
Inc. a rectangle referential integrity 16) 4-14 Primary key key Foreign SHORT TEXT STATEMENT OF PVFC Graphical representation: Lines/curves with arrowhead are used to indicate the referencing relationship (referential integrity) between foreign key and primary key. Chapter 4 Copyright 2016 Pearson Education, Inc. 4-15 Figure 4-3 Schema for four relations (Pine Valley Furniture Company) Primary Key
Foreign Key (implements 1:N relationship between customer and order) at h w is D I h t Cus in whic key ble? ta Intersect ion Combined, these are a composite relation primary key (uniquely identifies the order line)individually they are foreign keys (implement M:N relationship between order and product) Chapter 4 Copyright 2016 Pearson Education, Inc.
4-16 Fig 4-3 Schema for four relations (graphical representation) Primary Key Will be reqd for HW/ Exam Foreign Key (implements 1:N relationship between customer and order) Combined, these are a composite primary key (uniquely identifies the order line) Individually, they are foreign keys (implement M:N relationship between order and product) The curvy arrows here indicate referential integrity (PK FK correspondence) Chapter 4 Copyright 2016 Pearson Education, Inc. 4-17
The composite key of associative entity/intersection relation 1. Combined, these are a composite primary key (uniquely identifies the order line) 2. Individually, they are foreign keys (implement M:N relationship between order and product) Chapter 4 Read end of P. 157Copyright 2016 Pearson Education, Inc. 4-18 INTEGRITY CONSTRAINTS Chapter 4 Copyright 2016 Pearson Education, Inc.
4-19 INTEGRITY CONSTRAINTS Domain Constraints Entity Integrity Allowable values for an attribute (See Table 4-1) No primary key attribute may be null. All primary key fields MUST contain data values. Referential Integrity Rules that maintain consistency between the rows of two related tables.
Chapter 4 Copyright 2016 Pearson Education, Inc. 4-20 Domain definitions enforce domain integrity constraints. Chapter 4 Copyright 2016 Pearson Education, Inc. 4-21 * Online INTEGRITY CONSTRAINTS discussion REFERENTIAL INTEGRITY (P.160) ! Rule states that any foreign key value (in the relation of the many side) MUST match a primary key value (in the relation of the one Exa side). (Or the foreign key can be mpnull) le using IS 312
DB For example: Delete Rules Restrictdont allow delete of parent side if related rows exist in child / dependent side Cascadeautomatically delete dependent side rows that correspond with the parent side row to be deleted Set-to-Nullset the foreign key in the dependent EVERY have a the ref parent integrity siderelation to null if must deleting from side not arrow with at least other Chapterallowed 4 connected Copyright 2016 Pearson
Education,one Inc. 4-22 for weak entities Read end of 160-161 Fig 4-5 Referential integrity constraints Compare with next slide Referential integrity constraints are drawn via arrows from dependent to parent table (from M 1) (from FK PK) What if theres a relation that does NOT have connected Chapter 4ref integrity Copyrightarrow 2016 Pearson
Education, Inc. with at 20% made mista ke about this 4-23 Figure 1-3(b), P.12 Compare w previous slide Arrow direction Chapter 4 (1 ) 1- Prim si d e ary ap k p e ey
ar of s (2) Foreign key departs from ends at Copyright 2016 Pearson Education, Inc. 4-24 Figure 4-6 SQL table definitions Referential integrity constraints are implemented with foreign key to primary key references. Chapter 4 Copyright 2016 Pearson Education, Inc. 4-25 REFERENTIAL INTEGRITY
(RELATIONSHIP) PK-FK pair (referential integrity) is the way a relationship is implemented in relational database PK-FK pair exists when there is 1-M relationship The PK in the table on the 1-side, must appear as FK in the table on the M-side The ref. integ. arrow goes from the M-side to the 1-side, FKPK: referencing the PK on the 1-side Chapter 4 Copyright 2016 Pearson Education, Inc. 4-26 SUMMARY OF PREVIOUS SECTION In ERD In Rela. Note Schema Entity
Table No space in table name Attribute Primary key 1:M relationship Column Primary key Prim. key on 1side Foreign on M-side attribute domains M:N relationship can Associative entity Chapter 4 MUST: New M:N
relation/table for associative the M:N entity Hi error-rate concept; relationship itself table on its own ref previous 4 slides Intersection Copyright 2016 Pearson Education, Inc. 4-27 can be composite Dont flip the two ! ! ! ANOMALIES Three anomalies in this relation/table: 1. 2. 3.
Chapter 4 Insertion anomaly Deletion anomaly Modification anomaly 162~163) (PP. Copyright 2016 Pearson Education, Inc. 4-28 TRANSFORMING EER DIAGRAMS TO RELATIONS Chapter 4 Copyright 2016 Pearson Education, Inc. 4-29 TRANSFORMING EER DIAGRAMS INTO RELATIONS (P. 163) Three types of entities:
Chapter 4 Copyright 2016 Pearson Education, Inc. 4-30 30 TRANSFORMING EER DIAGRAMS INTO RELATIONS REGULAR ENTITIES Mapping Regular Entities to Relations handling attributes: Use 1. Simple attributes: E-R attributes map directly onto the relation (Fig 4-8, next slide) 2. Tear Composite attributes: Use only their apart simple, component attributes
(Figure 4-9) Create a new Multivalued attribute: Becomes Chapter 4 relation Copyright 2016 Pearson Education, Inc. separate relation with a foreign key 3. 4-31 31 Figure 4-8 Mapping a regular entity (a) CUSTOMER entity type with simple attributes (b) CUSTOMER relation Chapter 4 Copyright 2016 Pearson Education, Inc.
4-32 Figure 4-9 Mapping a composite attribute (a) CUSTOMER entity type with composite ng i k a Bre up attribute (b) CUSTOMER relation with address detail Chapter 4 Copyright 2016 Pearson Education, Inc. 4-33 33
Figure 4-10 Mapping an entity with a multivalued attribute (a) Multivalued attribute becomes a Ref back three slides w, o l be n d n I a Q: s 1 o ? wh s M o separate relation wh with foreign key (b) Ima gin e
tab le? LevelOfSk DateAcquir ed ill Onetomany relationship between original entity and new relation Chapter 4 Copyright 2016 Pearson Education, Inc. 4-34 MULTI-VALUED ATTRIBUTES The first relation EMPLOYEE has the primary key Employee_ID The second relation EMPLOYEE_SKILL has attributes Employee_ID and Skill, which form the primary key When in doubt, construct the
tables What would these two tables look like? What other field(s) could be in the second table (EMPLOYEE_SKILL)? Chapter 4 Copyright 2016 Pearson Education, Inc. 4-35 TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) WEAK ENTITIES Mapping Weak Entities Becomes a separate relation with a foreign key taken from the superior entity Figure 4-11(b) Primary key composed of:
Chapter 4 Partial identifier of weak entity Primary key of identifying relation (strong entity) Copyright the 2016 Pearson Education, 4-36 What would table forInc.the weak entity Figure 4-11 Example of mapping a weak entity a) Weak entity DEPENDENT In a relational database, a weak entity is an entity that cannot be uniquely identified by its attributes alone; therefore, it must use a foreign key in conjunction with its attributes to create a primary key. -- https:// en.wikipedia.org/wiki/Weak_entity Chapter 4 Copyright 2016 Pearson Education, Inc.
4-37 Figure 4-11 Example of mapping a weak entity (cont.) b) Relations resulting from weak entity NOTE: the domain constraint for the foreign key should NOT allow null value if DEPENDENT is a weak entity - Why? Foreign key Composite primary key (= ___? + ___?) Chapter 4 n e k a yt ck e a k b ign lides
e r o s a f 2 m o fr Copyright 2016 Pearson Education, Inc. 4-38 TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) BINARY RELATIONSHIPS Called Mapping Binary Relationships intersection 1. One-to-ManyPrimary key on the onerelation 2. 3.
side becomes a foreign key on the many-side Many-to-ManyCreate a new relation with the primary keys of the two entities as its primary key Logically from ______ One-to-OnePrimary key on the entity mandatory side becomes a foreign key on the optional side (curvy) Arrows indicating referential integrity Copyright 2016 Pearson Education, Inc. Chapter 4 4-39 Figure 4-12 Example of mapping a 1:M relationship a) Relationship between customers and orders Note the mandatory one If theres no field name/table
name, can you still tell the table on 1-side from the table on M-side? b) Mapping the relationship Again, no null value in the foreign keythis is because of the mandatory minimum cardinality Forei g Chapter 4 n ke y Copyright 2016 Pearson Education, Inc. 4-40 NEW FA17: SAMENESS OF DIRECTION OF ARROWS
Chapter 4 Copyright 2016 Pearson Education, Inc. ERD (one box, one entity/table) Relational model (one box, one attribute/colu mn) Do not confuse the two 4-41 MAP BINARY MANY-TO-MANY (M:N) RELATIONSHIPS If M:N relationship exists between entity types B and C, we create a new relation A, Entity relation >>>
Associative entity intersection relation include as foreign keys in A the primary keys for B and C, these attributes, together, become the primary key of A These attributes, separately, function EXAMPLE: 3 Inc. Chapter 4 ______________________ Copyright 2016next Pearson Education, 4-42 as MAP BINARY MANY-TO-MANY (M:N) RELATIONSHIPS e Note th liti a n i d r a
c es B C Kb Kc B A C Kb Kb + Kc Kc B Kb
A Kb C Kc Chapter 4 Kc A takes the primary key of B Kb and key of C Kc as its composite primary key; Kb and Kc separately also Inte rsec rela tion tion Copyright 2016 Pearson Education, Inc. 4-43
Figure 4-13 Example of mapping an M:N relationship a) Completes relationship (M:N) Attribute of relationship becomes Attribute of associative ent. (intersection relation) Will be treated as an associative entity The Completes relationship will need to become a separate relation Chapter 4 Copyright 2016 Pearson Education, Inc. 4-44 Figure 4-13 Example of mapping an M:N relationship (cont.) b) Three resulting relations The old Completes
relationship, now intersection relation CERTIFICATE Composite primary key F or e i gn k e y1 ey k n ig Fore 2 Original attribute of relationship What can we say about arrow direction?
Associative entity/intersection relation is always on the Chapter 4 Copyright 2016 Pearson Education, Inc. 4-45 M-side Figure 4-14 Example of mapping a binary 1:1 relationship a) In charge relationship (1:1) Often in 1:1 relationships, one direction is optional Chapter 4 Copyright 2016 Pearson Education, Inc. 4-46 MAP BINARY 1:1 RELATIONSHIPS In a 1:1 relationship, the association in one direction is often optional one, while the association in the other direction is mandatory one
think about STUDENT and PARKING_PERMIT The primary key of one of the relations is included as a foreign key in the other relation The primary key of the Mandatory side The foreign key of the optional side Chapter 4 Copyright 2016 Pearson Education, Inc. 4-47 Figure 4-14 Example of mapping a binary 1:1 relationship (cont.) b) Resulting relations Arrow points from _______ side to ____ side, from ______ key to ____ key Mandat ory side Option
al side Foreign key goes in the relation on the optional side, matching the primary key on the mandatory side Practice the same for the Chapter 4 STUDENT and PARKING_PERMIT relationship Copyright 2016 Pearson Education, Inc. 4-48 TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Associative Entities Scenario 1: Identifier Not Assigned Default primary key for the association relation is composed of the primary keys of the two entities (as in M:N relationship) Scenario 2: Identifier Assigned
It is natural and familiar to end-users Default identifier may not be unique What should we do with the foreign key(?)? Chapter 4 Copyright 2016 Pearson Education, Inc. 4-49 Figure 4-15 Example of mapping an associative entity a) An associative entity (will be transformed to an Intersection Relation) Observe the directions of the crows foot, anticipate direction of ref integrity Regular entity Associative entity
Regular entity Regular relation Intersection relation Regular relation Chapter 4 Copyright 2016 Pearson Education, Inc. 4-50 Figure 4-15 Example of mapping an associative entity (cont.) b) Three resulting relations Associative entity/intersection relation is on _____-side; arrow points from ~~ to ~~ 1. Composite primary key - two primary key attributes from the other two relations 2. TWO foreign keys, referencing the other two entities Chapter 4
Copyright 2016 Pearson Education, Inc. 4-51 Figure 4-15 Example of mapping an associative entity (cont.) b) Three resulting relations OID + PID: (1) Together - composite primary key (PK); (2) Separate - 2 FKs pointing to ORDER and PRODUCT tables Chapter 4 Copyright 2016 Pearson Education, Inc. 4-52 Figure 4-16 Example of mapping an associative entity with an identifier a) SHIPMENT associative entity Chapter 4 Associative entity: ALWAYS on MCopyright 2016 Pearson Education, Inc.
side 4-53 Figure 4-16 Example of mapping an associative entity with an identifier (cont.) b) Three resulting relations Pay attention Primary key differs from foreign keys identifier assigned Chapter 4 Copyright 2016 Pearson Education, Inc. 4-54 TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Unary Relationships
One-to-Many: Recursive foreign key in the same relation Many-to-Many: Two relations: One for the entity type One for an associative relation in which the primary key has two attributes, both taken from the primary key of the entity Chapter 4 Copyright 2016 Pearson Education, Inc. 4-55 Figure 4-17 Mapping a unary 1:M relationship (a) EMPLOYEE entity with unary relationship (b) EMPLOYEE relation with recursive foreign key
Note the direction of the arrow! Chapter 4 Examine the tables: Copyright 2016 Pearson Education, Inc. 4-56 Figure 4-17 Mapping a unary 1:M More explanation YOUR ManagerID is SOMEONE ELSEs EmployeeID Recursive is NOT circular: A records ManagerID does NOT point to ITS OWN EmployeeID; It points to SOMEONE ELSEs EmployeeID the EmployeeID of the persons managers One row points to ANOTHER row Chapter 4 Copyright 2016 Pearson Education, Inc. 4-57
Visualizing unary 1:M EID LName Position MgrID E011 Davis Acct Mgr E014 Edward s Acct I E011 E018
Fowler Acct II E011 E021 Gonzale Mkt Mgr z E023 Hanks Mkt Speclst E021 Recursive is E027 NOT circular: Kong Mkt E021 A records ManagerID does NOT
point to ITS OWN EmployeeID; Speclst It points to SOMEONE ELSEs EmployeeID One row points to ANOTHER row Chapter 4 Copyright 2016 Pearson Education, Inc. 4-58 Figure 4-18 Mapping an unary M:N relationship (a) Bill-of-materials relationships (M:N) Is_contained_in Attribute of M:N Attribute of intersection relation (b) ITEM and COMPONENT relations An ass
ociativ e entity ho know? Chapter 4 w did I Copyright 2016 Pearson Education, Inc. 4-59 Figure 4-18 Mapping an unary M:N More explanation 1001 1003 5 Example: Item #1001 takes Item #1003 as its component, in
the number of 5 (each 1001 needs 5 units of 1003) Chapter 4 Copyright 2016 Pearson Education, Inc. 4-60 Figure 4-18 B Unfolding an unary M:N relationship These 2 are one table Chapter 4 Copyright 2016 Pearson Education, Inc. 4-61 Figure 4-18 Mapping a unary M:N More explanation The PART table is either a top-assembly or a subassembly or a leaf part. It uses a publicly known "part number" to identify its rows, which is not actually a number at all and can contain non-numeric characters. The BOM table models many-to-many relationship of PART by itself. It's really no different from any other junction table, except both "endpoint" tables are actually the same table. This way, one sub-assembly or part can
be reused in multiple parent assemblies. On top of this model, you can fairly naturally add things like "drawing position" or "unit of measure" (e.g. a paint can be part of BOM but is measured in "kilograms" instead of "pieces"). http:// stackoverflow.com/questions/17651424/bill-of-materials-database-model Chapter 4 Copyright 2016 Pearson Education, Inc. 4-62 TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Ternary (and n-ary) Relationships One relation for each entity, and one for the associative entity Associative entity has foreign keys to each of the regular entities in the relationship
Chapter 4 Copyright 2016 Pearson Education, Inc. 4-63 Figure 4-19 Mapping a ternary relationship a) PATIENT TREATMENT Ternary relationship with associative entity Chapter 4 Copyright 2016 Pearson Education, Inc. 4-64 Figure 4-19 Mapping a ternary relationship (cont.) An en a s tit soc y iat i ve b) Mapping the ternary relationship PATIENT TREATMENT
Chapter 4 Remember This is why that the treatment date primary key and time are MUST be included in the composite unique primary key It would be But this makes a better to create a cumbersome surrogate key key like Treatment# Copyright 2016 Pearson Education, Inc. 4-65 TRANSFORMING EER DIAGRAMS INTO RELATIONS
(CONT.) Mapping Supertype/Subtype Relationships One relation for supertype and for each subtype Supertype attributes (including identifier and subtype discriminator) go into supertype relation Subtype attributes go into each subtype; primary key of supertype relation also becomes primary key of subtype relation 1:1 relationship established between supertype and each subtype, with Chapter 4 Copyright 2016 Pearson Education, Inc. 4-66 supertype as primary table
Polygons and Angles. Lesson 5-4. Page 397. Learning goal. Understand how to find the sum of the angle measures of a polygon and the measure of one interior angle of a regular polygon. p. 398. S = (n - 2)180...
In order to address this situation, the City seeks to initiative programmes that will bring activity to former township areas and other areas in economic need. One way of doing this is the proposed creation of Soweto Empowerment Zone.
Deforestation takes out an area half the size of the England, Scotland, and Ireland every year. Deforestation CO2 in 1990's was ¼ of that contributed by Fossil Fuel burning. Cutting trees in tropics is the worst for climate: reduces rainfall,...
It combines the virtues of proportionality with those of preferential voting. It is a system which politicians, given a choice, would probably least like to see introduced, but which voters, given a choice, should choose. " Farrell, Comparing Electoral Systems,...
Strong partnerships = strong foundation. Example Support Services from Primary Partner, KVCC: First Fridays. Dedicated Staff - Counselor, Pathway Advisor. Recognition Night. Faculty Office space. Bi-monthly Meetings between Coordinator & College Dean. Kalamazoo Valley Community College. Lake Michigan College. Southwestern...
In this case, a graphingcalculator can be used to find the inverse matrix._____In the matrix equation Ax=B, matrix A is the coefficient matrix, X is the matrix ofvariables, and B is the matrix of constants. Finding the Inverse of a...
Arial Wingdings Mountain Top Java Web Services CSCI 4300 What are Web Services? Example: Travel Agent Service-Oriented Architecture (SOA) Simple Object Access Protocol (SOAP) Interfacing SOAP with Proprietary business process Example: SOAP over AJAX XHttpRequest lifecycle Java XML Binding (JAXB...
Ready to download the document? Go ahead and hit continue!