Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.

Similar presentations


Presentation on theme: "1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management."— Presentation transcript:

1 1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Session 7 Designing a Database (Part 2 – some gentle repetition) ITE 252 Database Management

2 2 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Homework HW#1: Create an E-R diagram modeled after the Good Reading Bookstores E-R diagram (Figure 3-19 in your text and slide 14 here) for a publisher of music (limit to MP3s). Draw the diagram by hand and write up a description similar to the one in section 3.4.3 (pp.95-95) in your text. Some are outstanding

3 3 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Designing Relational Tables Typical process for converting E-R diagrams to relational tables: – Each entity converts to table – For many-to-many relationships, each associative entity converts to table – Attributes become table columns – Ensure foreign keys appear in proper places in tables To convert single entity, create table of same name with column for each attribute

4 4 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Salesperson Entity and Table

5 5 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Converting Binary Relationships Greater importance in selecting identifier and primary key – Identifier and primary key define foreign key that establishes relationships between tables Often more than one way to represent entity relationships as relational tables

6 6 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship

7 7 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship

8 8 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship

9 9 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship Converting one-to-one Salesperson/Office relationship – Options: Convert relationship to single/combined table Convert relationship to two tables

10 10 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship Considerations: – Business environment considers Salesperson and Office as separate entities – Modality of zero at Salesperson entity in E-R diagram (office may have no one assigned) – Salesperson entity in E-R diagram has relationships with other entities

11 11 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship Solution 1: – Combine two entities into one table

12 12 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship Solution 2: – Two separate tables – Office Number as foreign key in Salesperson table

13 13 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Example: Converting 1-1 Binary Relationship Solution 3: – Two separate tables – Salesperson Number as foreign key in Office table

14 14 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting 1-M Binary Relationship

15 15 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting 1-M Binary Relationship Each occurrence of Salesperson is related to zero or more occurrences of Customer Unique identifier of entity on “one” side is placed as foreign key in entity of “many” side

16 16 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting 1-M Binary Relationship

17 17 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Binary Relationship

18 18 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Binary Relationship Most relational DBMS systems DO NOT directly support many-to-many relationships Solution: Include associative entity to establish relationship May use composite key as primary key in associative entity A key that is defined by multiple columns is called a composite key

19 19 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Binary Relationship

20 20 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Binary Relationship not required

21 21 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting 1-1 Unary Relationship

22 22 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting 1-1 Unary Relationship With: – Only one entity type involved, and – One-to-one relationship Conversion requires only one table

23 23 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting 1-M Unary Relationship each salesperson manages zero or more salespersons each salesperson is managed by a manager

24 24 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting 1-M Unary Relationship each salesperson is managed by a manager

25 25 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Unary Relationship Many-to-many unary relationship: – For example: one product can be constructed out of set or subset of other products – General rule in conversion: Number of tables equal to number of entity types plus one more table for many-to-many relationship – M-M unary relationship - 2 tables – M-M binary relationship - 3 tables – M-M ternary relationship - 4 four tables

26 26 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Unary Relationship

27 27 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Unary Relationship

28 28 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Homework Read Chapter 4.1- pp.104-116 Read several times!

29 29 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Key Terms Composite key - A key that is defined by multiple columns Data integrity - Ensuring that data values are properly entered and maintained Defining association - A means of expressing that the value of one particular attribute is associated with a single, specific value of another attribute Null value - An undefined value, usually used to identify that no value is provided for that attribute Referential integrity - Another name for relational integrity, referring to the fact that you are maintaining the relationship between referencing and referenced tables. Relational integrity - Ensuring that relationships between tables are correctly created and maintained.

30 30 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A Which statement best describes the process of converting a one-to-one binary relationship to related tables? a)You should convert the entities into a single related table. b)There will typically be only one way to define the tables. c)There will typically be more than one way to define the tables.

31 31 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A Which statement best describes the process of converting a one-to-one binary relationship to related tables? a)You should convert the entities into a single related table. b)There will typically be only one way to define the tables. c)There will typically be more than one way to define the tables.

32 32 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A You are converting a many-to-many unary relationship. How many relational tables will result from this conversion? a)one b)two c)three d)four

33 33 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A You are converting a many-to-many unary relationship. How many relational tables will result from this conversion? a)one b)two c)three d)four

34 34 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A Manager-to-Employee is a one-to-many unary relationship. You create an EMPLOYEE table. How any additional tables do you need? a)none b)one c)two

35 35 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A Manager-to-Employee is a one-to-many unary relationship. You create an EMPLOYEE table. How any additional tables do you need? a)none b)one c)two

36 36 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A Data integrity ensures that data is entered and stored correctly. True or False?

37 37 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Q&A Data integrity ensures that data is entered and stored correctly. True or False?

38 38 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Good Reading Bookstores

39 39 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Good Reading Bookstores

40 40 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Good Reading Bookstores

41 41 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Normalizing Data Data normalization: Methodology for organizing attributes into tables to eliminate redundancy among non-key attributes Goals: – Each resultant table describes single entity type or single many-to-many relationship – Foreign keys appear exactly where needed – Properly structured relational database

42 42 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Normalization Techniques Two types of input needed for data normalization process 1.List of all attributes to be incorporated in database, including intersection data attributes 2.List of functional dependencies: all defining associations between attributes In functional dependencies, one attribute (determinate attribute – left side) defines value of another attribute – functionally dependent on the left side Salesperson Number → Salesperson Name

43 43 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Converting M-M Binary Relationship

44 44 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Entity Attributes Assume the salespersons are organized into departments and that each department has a manger who is not herself a sales person We get this list of attributes…

45 45 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Salesperson Entity Attributes

46 46 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Salesperson Entity Functional Dependencies (Defining Associations)

47 47 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Defining Attributes and Functional Dependencies Quantity is defined by two combined attributes Manager is defined independently by two attributes – Department Number and Salesperson Number Salesperson Number also defines Department Number

48 48 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Normalizing Data Normal forms: Rules for data normalization Three main normal forms – First normal form – Second normal form – Third normal form Normalization: – Uses normal forms to step through “decomposition process” that decomposes attributes into subgroups In third normal form, group of tables is well-structured relational database with no data redundancy Goal: no data redundancy

49 49 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Normalizing Data First normal form: – Eliminates multiple values Second normal form: – Eliminates partial functional dependencies (data dependent on part of primary key) – Every nonkey attribute must be fully functionally dependent on entire key of table Third normal form: – Eliminates transitive dependencies (one nonkey attribute is functionally dependent on another) – Nonkey attributes are not allowed to define other nonkey attributes

50 50 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Example: Unnormalized Data multiple values

51 51 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management First Normal Form multiple values

52 52 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Second Normal Form eliminate partial functional dependencies (See figure 4-29 in text; some redundant data)

53 53 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Third Normal Form (See figure 4-31 in text; notice DEPARTMENT table)

54 54 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Denormalizing Data Denormalizing may be needed when: – Normalization has been taken to extreme Too many small tables creating more work and storage space – E.g. Using State table to be referenced instead of entering two-digit code) – More efficient data retrieval is needed: Many queries requiring resource-intensive joining In denormalizing, you join two or more tables into one less normalized table

55 55 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Summary In converting E-R diagrams to relational tables, each entity typically converted into table, with attributes as table columns. Considerations in conversion: Business needs, cardinalities, modalities, and defining foreign keys to establish relationships. Normalization: Uses three main normal forms to step through “decomposing” attributes into subgroups that allow data redundancies to be eliminated. Denormalizing may be needed in cases where storage space and speed of data retrieval are important factors.

56 56 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Key Terms Data normalization - A methodology for organizing attributes into tables so that redundancy among the nonkey attributes is eliminated Decomposition process - Another term for the data normalization process. Also called “non-loss decomposition” Determinant attribute - The attribute in a defining association whose value determines the value of the attribute on the right side of the association Exception conditions - Less commonly used normal forms First normal form - Each attribute value is atomic, that is, no attribute is multivalued Functional dependency - See Defining association

57 57 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management Key Terms Joining - Combining the data from two tables based on linking columns Non-loss decomposition - Normalization process in which neither data nor relationships are lost Normal forms - Defined rules for data normalization Partial functional dependency - A dependency where data is dependent on part of the primary key Second normal form - Every nonkey attribute must be fully functionally dependent on the entire key Third normal form (3NF) - Transitive dependencies are not allowed Transitive dependency - One nonkey attribute is functionally dependent

58 58 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management international, open membership, not- for-profit technology standards consortium. Important Links Database Normalization - good description from Wikipedia Database Normalization An Introduction to Database Normalization – if you can get past the computerized female voice, it’s a pretty good overview An Introduction to Database Normalization Database Normalizaion Basics – Microsoft Overview Database Normalizaion Basics


Download ppt "1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management."

Similar presentations


Ads by Google