creating databases data normalization. integrity and robustness. work session. homework: prepare...

16
Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working on implementation.

Upload: justina-may

Post on 17-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Creating Databases

Data normalization. Integrity and Robustness.Work session.

Homework: Prepare short presentation on enhancement projects. Continue working on

implementation.

Page 2: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

What is normalization?

Data analysis is a process that prepares a data model for implementation as a simple, non-redundant, flexible, and adaptable database. The specific technique is called normalization.

Normalization is a data analysis technique that organizes data attributes such that they are grouped to form non-redundant, stable, flexible, and adaptive entities.

Page 3: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Goals of normalization• Have well-defined tables—at most one

value for each field.• Store each item of information exactly one

place so if/when it changes, only have to change one place.

• Relationships are valid: foreign keys refer to existing primary keys.

• Don't store items that can be calculated so making changes is simplified.

Page 4: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Process of defining database

• May start with the desired end products (sometimes called artifacts)– Reports– Forms

• May be from original, possibly even non-automated version of application

• May be from combination of applications. Goal is to produce single database that serves multiple uses.

Page 5: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

But…

• Problems are common.

• Example: change address [one place] but old information persists.

• Your experience?

Page 6: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Normalization process

• First step is to do what is necessary to get each entity into 1st normal form:– An entity is in first normal form (1NF) if there are no

attributes that can have more than one value for a single instance of the entity. Any attributes that can have multiple values actually describe a separate entity, possibly an entity and relationship.

– Common situation is so-called multiple values, such as distinct items in an order (distinct beneficiaries, game-machines)

– Action is to create new entity

Page 7: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Modifying model to 1st NF

Many items (titles)

Associative entity:Use combination of keys fornew (concatenated) key

Page 8: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Moving to 2nd NF

• If you do not have any concatenated keys, no work is needed. Model is already in 2nd NF.

• If you do have any concatenated (combination) keys, you need to examine these entities.– An entity is in second normal form (2NF) if it is already in

1NF and if the values of all nonprimary key attributes are dependent on the full primary key—not just part of it. Any nonkey attributes that are dependent on only part of the primary key should be moved to any entity where that partial key is actually the full key. This may require creating a new entity and relationship on the model.

Page 9: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Moving to 2nd NF

Some attributes relate to the product itself, not the fact that theproduct is part of this order.Remove these attributes.

Page 10: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

So…

• In my store example, the ordered items records would NOT have information just relating to the order or just relating to the product.

Page 11: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Moving to 3rd NF

• Make sure that all non-primary attributes depend just on the key, not, for example, on another attribute.– An entity is in third normal form (3NF) if it is already in 2NF

and if the values of its nonprimary key attributes are not dependent on any other non-primary key attributes. Any nonkey attributes that are dependent on other nonkey attributes must be moved or deleted. Again, new entities and relationships may have to be added to the data model.

– Typical example is something that can be calculated.

Page 12: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Example of move to 3rd NF

Page 13: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Example of move to 3rd NF

Page 14: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

MEMBERPrimary Key

Member-Number [PK1]Non-Key Attributes

Member-NameMember-StatusMember-Street-AddressMember-Post-Office-BoxMember-CityMember-StateMember-Zip-CodeMember-Daytime-Phone-NumberMember-Date-of-Last-OrderMember-Balance-DueMember-Credit-Card-TypeMember-Credit-Card-NumberMember-Credit-Card-Expire-DateMember-Bonus-Balance-AvailableAudio-Category-PreferenceAudio-Media-PreferenceDate-EnrolledExpiration-DateGame-Category-PreferenceGame-Media-PreferenceNumber-of-Credits-EarnedVideo-Category-PreferenceVideo-Media-PreferenceAgreement-Number [FK]Privacy-CodeEmail-Address

MEMBER ORDERPrimary Key

Order-Number [PK1]Non-Key Attributes

Order-Creation-DateOrder-Fill-DateShipping-Address-NameShipping-Street-AddressShipping-CityShipping-StateShipping-ZipShipping-InstructionsOrder-Sub-TotalOrder-Sales-TaxOrder-Shipping-MethodOrder-Shipping-&-Handling-CostOrder-StatusOrder-Prepaid-AmountOrder-Prepayment-MethodPromotion-Number [FK]Member-Number [FK]Member-Number-1 . Member-Number [FK]

PRODUCTPrimary Key

Product-Number [PK1]Non-Key Attributes

"Universal-Product-Code (Alternate Key)"Quantity-in-StockProduct-TypeSuggested-Retail-PriceDefault-Unit-PriceCurrent-Special-Unit-PriceCurrent-Month-Units-SoldCurrent-Year-Units-SoldTotal-Lifetime-Units-Sold

VIDEO TITLEPrimary Key

Product-Number [PK1] [FK]Non-Key Attributes

ProducerDirectorVideo-CategoryVideo-Sub-CategoryClosed-CaptionedLanguageRunning-TimeVideo-Media-TypeVideo-EncodingScreen-AspectMPA-Rating-Code

AUDIO TITLEPrimary Key

Product-Number [PK1] [FK]Non-Key Attributes

ArtistAudio-CategoryAudio-Sub-CategoryNumber-of-Units-in-PackageAudio-Media-CodeContent-Advisory-Code

GAME TITLEPrimary Key

Product-Number [PK1] [FK]Non-Key Attributes

ManufacturerGame-CategoryGame-Sub-CategoryGame-PlatformGame-Media-TypeNumber-of-PlayersParent-Advisory-Code

TRANSACTIONPrimary Key

Transaction-Reference-Number [PK1]Non-Key Attributes

Transaction-DateTransaction-TypeTransaction-DescriptionTransaction-AmountMember-Number [FK]Order-Number [FK]

TITLEPrimary Key

Product-Number [PK1] [FK]Non-Key Attributes

Title-of-WorkTitle-CoverCatalog-DescriptionCopyright-DateEntertainment-CategoryCredit-Value

MEMBER ORDERED PRODUCTPrimary Key

Order-Number [PK1] [FK]Product-Number [PK2] [FK]Non-Key Attributes

Quantity-OrderedQuantity-ShippedQuantity-BackorderedPurchase-Unit-PriceCredits-Earned

MERCHANDISEPrimary Key

Product-Number [PK1] [FK]Non-Key Attributes

Merchandise-NameMerchandise-DescriptionMerchandise-TypeUnit-of-Measure

AGREEMENTPrimary Key

Agreement-Number [PK1]Non-Key Attributes

Agreement-Expire-DateAgreement-Active-DateFulfillment-PeriodRequired-Number-of-Credits

PROMOTIONPrimary Key

Promotion-Number [PK1]Non-Key Attributes

Promotion-Release-DatePromotion-StatusPromotion-Type

3NF Member Services (EntityRelation Subject Area)

SA/2001Tue May 02, 2000 10:41

CommentSandra Shepherd

TITLE PROMOTIONPrimary Key

Product-Number [PK1] [FK]Promotion-Number [PK2] [FK]

places

binds

features

is featured as

is a

hasconducted

respondsto

is ais ais a

is ais a

generates

sold as

sells

Page 15: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Normalization

• …. is a process. It is [somewhat] mechanical. There is chance that your model may be in 1st, 2nd, or even 3rd without action or much action on your part, but it is good to go through the process.

• Note: Some may argue for certain redundancies, for example, storing a calculated value. Why or why not?

Page 16: Creating Databases Data normalization. Integrity and Robustness. Work session. Homework: Prepare short presentation on enhancement projects. Continue working

Homework

• Prepare short presentation on enhancement project, including Entity-Relationship diagrams (which may not have changed from original) and Data Flow Diagram (which probably did change)

• Work on enhancement projects.