Upload
gwenda-carroll
View
213
Download
0
Embed Size (px)
Citation preview
Create Databases for Web Applications
Database normalization.Classwork/Homework: determine
teams for basic projects explain and enhance assignment
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.
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
• Don't store items that can be calculated so making changes is simplified.
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 application. Goal is to produce single database that serves multiple uses.
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
Modifying model to 1st NF
Many items (titles)
Associative entity:Use combination of keys fornew (concatenated) key
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.
Moving to 2nd NF
Some attributes relate to the product itself, not the fact that theproduct is part of this order.Remove these attributes.
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.
Example of move to 3rd NF
Example of move to 3rd NF
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
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?
Classwork / Homework
• Determine teams to explain and enhance and explain sample projects– HTML JavaScript
• Orders• Trivia quiz• Songs with features
– Flash ActionScript• Grid design• Video clip archive