Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2011 Pearson Education, Inc. Publishing as Prentice Hall

Similar presentations


Presentation on theme: "© 2011 Pearson Education, Inc. Publishing as Prentice Hall"— Presentation transcript:

1 Data Modeling Breaking data into different tables is the first step in data modeling

2 © 2011 Pearson Education, Inc. Publishing as Prentice Hall
Introduction FIGURE 9-1 Systems development life cycle with design phase highlighted Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

3 Relational Database Model
Relation: a named, two-dimensional table of data; each relation consists of a set of named columns and an arbitrary number of unnamed rows Relational database model: data represented as a set of related tables and their relations Relations have several properties that distinguish them from non-relational tables: Entries in cells are simple. Entries in columns are from the same set of values. Each row is unique. The sequence of columns can be interchanged without changing the meaning or use of the relation. The rows may be interchanged or stored in any sequence. Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

4 Transforming E-R Diagrams into Relations
It is useful to transform the conceptual data model into a set of normalized relations. Steps Represent entities. Represent relationships. Normalize the relations (remove redundancies) Merge the relations. Connect the tables (entities) Chapter 9

5 Representing Entities (tables)
Each regular entity is transformed into a table with attributes and a primary key. The identifier of the entity type becomes the primary key of the corresponding relation. The primary key must satisfy the following two conditions. The value of the key must uniquely identify every row in the relation – choose a field that can identify each row (ie customerID) The key should be non-redundant. (no duplicates) Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

6 Binary 1:N Relationships
Binary 1:N Relationship is represented by adding the primary key attribute (or attributes) of the entity on the one side of the relationship as a foreign key in the relation that is on the many side of the relationship. This is the common one to many relationship Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

7 Binary and Higher-Degree M:M Relationships
Create another relation and include primary keys of all relations as primary key of new relation Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

8 Standard Table Notation
11/14/2018Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

9 Normalization and Rules of Normalization
Normalization: the process of converting complex data structures (chaos data) into simple, stable data structures Un-normalized Form Multi-valued Attributes (more than one value in a column) Normal Forms First Normal Form (1NF) Unique rows, no multi-valued attributes (no repeating groups, ie. More than one value in a cell) Second Normal Form (2NF) Each non-primary key attribute is identified by the whole key (called full functional dependency). The columns belong together in a table – belong to the primary key Third Normal Form (3NF) Non-primary key attributes do not depend on each other (i.e. no transitive dependencies). A value in a column in a table is not dependent on a non-primary key value from another table

10 © Shelly and Rosenblatt 2011
Unnormalized Table A table that contains a repeating group (multivalued attributes) is in “unnormalized” form ORDER (ORDER-NUM, ORDER-DATE, (PRODUCT-NUM, PRODUCT-DESC, NUM-ORDERED)) © Shelly and Rosenblatt 2011

11 First Normal Form – 1NF – add more rows
A table is in first normal form(1NF ) if it does not contain a repeating group. To convert an unnormalized design to 1NF, you must expand the table's primary key to include the primary key of the repeating group. ORDER (ORDER-NUM, ORDER-DATE, PRODUCT-NUM, PRODUCT-DESC, NUM-ORDERED) 11/14/2018Chapter 9 © Shelly and Rosenblatt 2011

12 Functional Dependency
For a given relation, attribute B (Region) is functionally dependent on attribute A (customer name) if, for every valid value of A, that value of A uniquely determines the value of B. Customers can belong to only one region. If not create another row of data with a composite primary key The functional dependence of B on A is represented by A→B. Functional dependency is not a mathematical dependency. Knowledge of problem domain is most reliable method for identifying functional dependency. Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

13 Second Normal Form (2NF)
Common to drop other columns into this top- level table like totals Second Normal Form (2NF) A relation is in second normal form (2NF) if any of the following conditions apply: Every non-primary key attribute is functionally dependent on the full set of primary key attributes. The primary key consists of only one attribute. No non-primary key attributes exist in the relation. (one to many relationship has no composite PK’s ORDER (ORDER-NUM, ORDER-DATE), PRODUCT (PRODUCT-NUM, PRODUCT-DESC) ORDER-LINE (ORDER-NUM, PRODUCT-NUM, NUM-ORDERED) 11/14/2018Chapter 9

14 How to convert from 1NF to 2NF – Step 1 – break tables apart
Step 1: Create and name a separate table for each field in the existing primary key. For example, in the previous example, the ORDER table's primary key has two fields, ORDER-NUM and PRODUCT-NUM, so you must create two tables. The ellipsis (…) indicates that fields will be assigned later. The result is: ORDER (ORDER-NUM,…) PRODUCT (PRODUCT-NUM,…) © Shelly and Rosenblatt 2011

15 How to convert from 1NF to 2NF – Step 2
Step 2: Create a new table for each possible combination of the original primary key fields. In the example, you would create and name a new table with a combination primary key of ORDER-NUM and PRODUCT-NUM. This table describes individual lines in an order, so it is named ORDER-LINE, as shown: ORDER-LINE (ORDER-NUM, PRODUCT-NUM,…) © Shelly and Rosenblatt 2011

16 How to convert from 1NF to 2NF – Step 3
Step 3: Study the three tables and place each field with its appropriate primary key, which is the minimal key on which it functionally depends. When you finish placing all the fields, remove any table that did not have any additional fields assigned to it. The remaining tables are the 2NF version of your original table. In the example, the three tables would be shown as: ORDER (ORDER-NUM, ORDER-DATE) PRODUCT (PRODUCT-NUM, PRODUCT-DESC) ORDER-LINE (ORDER-NUM, PRODUCT-NUM, NUM-ORDERED) © Shelly and Rosenblatt 2011

17 © Shelly and Rosenblatt 2011
Third Normal Form (3NF) A relation is in third normal form (3NF) if it is in second normal form (2NF) and there are no functional (transitive) dependencies between two (or more) nonprimary key attributes. To convert the table from 2NF to 3NF, you must remove all fields from the 2NF table that depend on another nonkey field and place them in a new table that uses the nonkey field as a primary key. © Shelly and Rosenblatt 2011

18 Third Normal Form (3NF) – Another example
A relation is in third normal form (3NF) if it is in second normal form (2NF) and there are no functional (transitive) dependencies between two (or more) nonprimary key attributes. Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

19 A Normalization Example
© Shelly and Rosenblatt 2011

20 Q1. Represent this table in standard Table notation.
STUDENT (STUDENT-NUMBER, STUDENT-NAME, TOTAL-CREDITS, GPA, ADVISOR-NUMBER, ADVISOR-NAME, (COURSE-NUMBER, COURSE-DESC, NUM-CREDITS, GRADE)) © Shelly and Rosenblatt 2011

21 Q2. What form is this table in? Unnormalized? 1NF? 2NF?3NF?
This table is in Unnormalized form. Why? Because it contains a repeating group. © Shelly and Rosenblatt 2011

22 © Shelly and Rosenblatt 2011
Q3. Convert the table to first normal form and represent it in standard table notation. STUDENT (STUDENT-NUMBER, STUDENT-NAME, TOTAL-CREDITS, GPA, ADVISOR-NUMBER, ADVISOR-NAME, COURSE-NUMBER, COURSE-DESC, NUM-CREDITS, GRADE) © Shelly and Rosenblatt 2011

23 © Shelly and Rosenblatt 2011
Q3. Convert the table to second normal form and represent it in standard table notation. Step 1: Create Tables with primary keys and combinations STUDENT (STUDENT-NUMBER, … ) COURSE(COURSE-NUMBER, …) GRADEINFO(STUDENT-NUMBER, COURSE-NUMBER,…) Step 2: Add the non-key attributes which are functionally dependent on minimal keys STUDENT (STUDENT-NUMBER, STUDENT-NAME, TOTAL-CREDITS, GPA, ADVISOR-NUMBER, ADVISOR-NAME) COURSE(COURSE-NUMBER, COURSE-DESC, NUM-CREDITS) GRADEINFO(STUDENT-NUMBER, COURSE-NUMBER, GRADE) Step 3: Drop any tables where there is no additional column other than the primary key. Step 4:Remaining tables are in 2NF form. Verify that condition for 2NF is satisfied: Table is in 1NF and Every non primary-key attribute is functionally dependent on whole primary key. © Shelly and Rosenblatt 2011

24 © Shelly and Rosenblatt 2011
Q3. Convert the table to third normal form and represent it in standard table notation. Table is in 3NF if it is in 2NF and there are no transitive dependencies (No non-primary key attributes are functionally dependent on each other). Separate them into a separate table. STUDENT (STUDENT-NUMBER, STUDENT-NAME, TOTAL-CREDITS, GPA, ADVISOR-NUMBER) ADVISOR (ADVISOR-NUMBER, ADVISOR-NAME) COURSE(COURSE-NUMBER, COURSE-DESC, NUM-CREDITS) GRADEINFO(STUDENT-NUMBER, COURSE-NUMBER, GRADE) © Shelly and Rosenblatt 2011

25 © 2011 Pearson Education, Inc. Publishing as Prentice Hall
Choosing Data Types Selecting a data type balances four objectives: Minimize storage space. Represent all possible values of the field. Improve data integrity of the field. Support all data manipulations desired on the field. Examples: CHAR, LONG, NUMBER Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

26 Controlling Data Integrity
Default Value: a value a field will assume unless an explicit value is entered for that field Range Control: limits range of values that can be entered into field Both numeric and alphanumeric data Referential Integrity: an integrity constraint specifying that the value (or existence) of an attribute in one relation depends on the value (or existence) of the same attribute in another relation Null Value: a special field value, distinct from zero, blank, or any other value, that indicates that the value for the field is missing or otherwise unknown Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall

27 © 2011 Pearson Education, Inc. Publishing as Prentice Hall
Summary Normalization, functional dependency, foreign key, referential integrity, field, data type, null value, Explain the role of designing databases in the analysis and design of an information system. Chapter 9 © 2011 Pearson Education, Inc. Publishing as Prentice Hall


Download ppt "© 2011 Pearson Education, Inc. Publishing as Prentice Hall"

Similar presentations


Ads by Google