SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Κανονικοποίηση Βάσεων
      Δεδοµένων

(Database Normalization)


     Πχης (M) B. Παπαλιάκος ΠΝ
      (vpapaliakos@gmail.com)
Διαδικαστικά θέµατα

Διάρκεια: 20 λεπτά
●




●Η παρουσίαση είναι διαθέσιµη στη διεύθυνση
http://papaliakos.gr/db/presentations
●Επίσης σας έχει διανεµηθεί σε χαρτί ώστε...

●ΝΑ ΚΡΑΤΗΣΕΤΕ ΣΗΜΕΙΩΣΕΙΣ!




●Ερωτήσεις δεκτές, κατά προτίµηση στο τέλος
κάθε ενότητας
Εισαγωγή
●   Υπόθεση: είστε σχετικοί µε το αντικείµενο των
    ΒΔ.
●   Νιώθετε ότι σας λείπουν κάποιες γνώσεις, όµως
    τα καταφέρατε σε µια-δυο περιπτώσεις που
    χρειάστηκε να φτιάξετε ΒΔ στην access.
●   Σας προσφέρουν 2000 € για µια ΒΔ-δουλειά
    µιας εβδοµάδας: pas mal!
Εισαγωγή
Στόχοι

Να µπορούµε να εξηγήσουµε τις έννοιες:

●   Εξάρτηση (data dependency)
●   Πλεονασµός (redundancy) και
●   Ασυνέπεια (inconsistency) δεδοµένων



Να µπορούµε να εξαλείψουµε τα παραπάνω
προβλήµατα µέσω της κανονικοποίησης (normalization).
Βασικές έννοιες - Πυλώνες
●   Εξάρτηση (Dependency)
●   Πλεονασµός δεδοµένων (Data redundancy)
●   Ασυνέπεια δεδοµένων (Data inconsistency)
●   Κανονικοποίηση (Normalization)
●   Κανονικές µορφές (Normal forms)
       ●   1NF – 2NF - 3NF



“Στο πεδίο των Η/Υ όπου κι αν πετάξεις µια πέτρα θα χτυπήσεις µια βάση
                              δεδοµένων”
1. Εξάρτηση (Dependency)
Όταν λέµε: το Y εξαρτάται από το X εννοούµε:

                                Y=f(X)


●   ή µε άλλα λόγια, το Χ καθορίζει το Υ.
●   Αυτή η εξάρτηση σηµειώνεται ως X → Y.


Παράδειγµα:
         invoice_id   line_nr   product_code   product_name   customer_name



Τι εξαρτήσεις έχουµε εδώ;
1. Εξάρτηση (Dependency)
Όταν λέµε: το Y εξαρτάται από το X εννοούµε:

                                         Y=f(X)


●   ή µε άλλα λόγια, το Χ καθορίζει το Υ.
●   Αυτή η εξάρτηση σηµειώνεται ως X → Y.
Παράδειγµα:
     invoice_id   line_nr         product_code   product_name   customer_name


                            product_code             product_name
                                                 →
                            invoice_id
                                                 →   customer_name
1. Εξάρτηση (Dependency)
Δώστε παραδείγµατα εξαρτηµένων µεταβλητών:

●   Σε µια ΒΔ µαθητών-µαθηµάτων-βαθµών
●   Σε µια ΒΔ υλικών-αποθηκών-αποθεµάτων
●   Σε µια ΒΔ αυτοκινήτων
“Καλή” και “Κακή” εξάρτηση

●    “Καλή” εξάρτηση (“Good” dependency):
●    Πρωτεύον κλειδί (Primary Key) → άλλες ιδιότητες


●    “Κακές” εξαρτήσεις (“Bad” dependencies):
●     Μερική εξάρτηση (Partial dependency)
    invoice_id   line_nr      product_code   product_name   customer_name




●    Μεταβατική εξάρτηση (Transitive dependency)
    invoice_id   line_nr      product_code   product_name   customer_name
Αποτέλεσµα;
2Α. Πλεονασµός δεδοµένων
               (Data redundancy)
Η ίδια πληροφορία φυλάσσεται σε διάφορα µέρη (διπλο-εγγραφή).
Παράδειγµα: η διεύθυνση και το τηλέφωνο ενός πελάτη µπορεί να φυλάσεται στο αρχείο των
λογαριασµών όψεως και στο αντίστοιχο αρχείο των λογαριασµών ταµιευτηρίου µιας τράπεζας.

 κωδ_λογαρ.       πελ_όνοµα         πελ_διευθ        πελ_τηλ
 οψ-004           Παπαλιάκος        Κρυστάλλη        6943483457
                     κωδ_λογαρ.       πελ_όνοµα        πελ_διευθ         πελ_τηλ
                     ταµ-037          Παπαλιάκος       Κρυστάλλη         6943483457
                                   Αυτό ονοµάζεται
                            πλεονασµός δεδοµένων
                                (data redundancy).
2Α. Πλεονασµός δεδοµένων
          (Data redundancy)
●   Παράδειγµα:




Τι µπορεί να πάει στραβά???
2Β. Ασυνέπεια δεδοµένων
           (Data inconsistency)
●   Αυτός ο πλεονασµός µπορεί να οδηγήσει σε


          ασυνέπεια δεδοµένων (data inconsistency)


δηλαδή σε
●   διαφορετικά αντίγραφα των ιδίων δεδοµένων τα οποία
●   µπορεί να µη συµφωνούν µεταξύ τους.
2Β. Ασυνέπεια δεδοµένων
               (Data inconsistency)
●   διαφορετικά αντίγραφα των ιδίων δεδοµένων
●   µπορεί να µη συµφωνούν µεταξύ τους.
●   Παράδειγµα: αν αλλάξουµε τη διεύθυνση ενός πελάτη στο αρχείο των λογαριασµών
    ταµιευτηρίου, τότε αυτή η αλλαγή δεν θα φαίνεται οπουδήποτε αλλού (πχ. στο αρχείο των
    λογαριασµών όψεως).

    κωδ_λογαρ.     πελ_όνοµα         πελ_διευθ        πελ_τηλ
    οψ-004         Παπαλιάκος        Κρυστάλλη        6943483457
                      κωδ_λογαρ.       πελ_όνοµα        πελ_διευθ        πελ_τηλ
                      ταµ-037          Παπαλιάκος       Καβάφη           6947159333
2Β. Ασυνέπεια δεδοµένων
           (Data inconsistency)
●   διαφορετικά αντίγραφα των ιδίων δεδοµένων
●   συµφωνούν µεταξύ τους;
Προβλήµατα στα δεδοµένα µας
         (Data anomalies)


Update anomaly




                         Insertion anomaly


Deletion anomaly
Τι κάνουµε ???
                                   I am superhero
                                         2NF
                                       (arghh!)
 ●   Normalization to the rescue

                                                    I am super-
                                                     superhero
I am superhero
                                                        3NF
      1NF
                                                      (arghh!)
    (arghh!)
3. Normal forms & normalization
1η κανονική µορφή - First           “The key...”
  Normal Form (1NF)


2η κανονική µορφή - Second       “the whole key...”
  Normal Form (2NF)


3η κανονική µορφή - Third    “and nothing but the key!”
  Normal Form (3NF)
3. Normal forms & normalization
Η διαδικασία κανονικοποίησης (για κάθε πίνακα)

●   Συµµόρφωση των δεδοµένων µας σε διαδοχικές κανονικές
    µορφές (1NF → 2NF → 3NF)
●   Κάθε στήλη (σε κάθε πίνακα) εξαρτάται από
         ●   Το κλειδί,
         ●   ολόκληρο το κλειδί και
         ●   τίποτα άλλο εκτός από το κλειδί

●   1NF (the key) → 2NF (the whole key) → 3NF (& nothing but the key)
3Α. 1η κανονική µορφή
              st
             1 Normal Form (1NF)
1η κανονική µορφή
First Normal Form (1NF): “the Key”

●   Το κλειδί καθορίζει όλες τις ιδιότητες (στήλες) του πίνακα
●   ΟΧΙ πολλαπλές τιµές σε µία στήλη




●   ΟΧΙ οµάδες δεδοµένων: µία στήλη = µία ιδιότητα
3Α. 1η κανονική µορφή
          st
         1 Normal Form (1NF)
●   Ο παρακάτω πίνακας είναι σε 1NF;
3Β. 2η κανονική µορφή
            nd
           2 Normal Form (2NF)
2η κανονική µορφή
Second Normal Form (2NF): “the whole key...”

●   1η κανονική µορφή (1NF)

                                +
●   ΟΧΙ µερικές εξαρτήσεις (partial dependencies),


                           Άρα............
Θεραπεία για τις “κακές εξαρτήσεις”
Αφαιρούµε τις µερικές εξαρτήσεις




   invoice_id   line_nr        product_code    product_name   customer_name




   invoice_id   line_nr         product_code   product_name




   invoice_id       customer_name
3Γ. 3η κανονική µορφή
            rd
           3 Normal Form (3NF)
3η κανονική µορφή
Third Normal Form (3NF): “...and nothing but the key!”

●   2η κανονική µορφή (2NF)

                               +
●   ΟΧΙ µεταβατικές εξαρτήσεις (transitive dependencies)


                       Οπότε..............
Θεραπεία για τις “κακές εξαρτήσεις”
Αφαιρούµε τις µεταβατικές εξαρτήσεις

   invoice_id   line_nr        product_code   product_name



   invoice_id       customer_name




   invoice_id   line_nr        product_code          product_code   product_name



   invoice_id       customer_name
Κανονικοποίηση στην πράξη
Συνεπώς...
●   Αφαιρούµε
       –   Πολλαπλές στήλες – πολλαπλές τιµές
       –   Μερικές εξαρτήσεις
       –   Μεταβατικές εξαρτήσεις
●   Εξαλείφουµε προβλήµατα στα δεδοµένα µας

●   Κανονικοποίηση όλων των πινάκων
●   Κανονικοποίηση όλης της ΒΔ
Επίλογος
●   Βασικές έννοιες
        –   Εξάρτηση (Dependency)
        –   Πλεονασµός δεδοµένων (Data redundancy)
        –   Ασυνέπεια δεδοµένων (Data inconsistency)
        –   Κανονικοποίηση (Normalization)
        –   Κανονικές µορφές (Normal forms)
                      1NF – 2NF - 3NF
Επίλογος

Στόχοι:
1.Να µπορούµε να εξηγήσουµε τις έννοιες:
      – Εξάρτηση (data dependency)

      –   Πλεονασµός (redundancy) και
      –   Ασυνέπεια (inconsistency) δεδοµένων
2.Να µπορούµε να εξαλείψουµε τα παραπάνω
  προβλήµατα µέσω της κανονικοποίησης
  (normalization).
Πηγές
●   http://en.wikipedia.org/wiki/Database_normaliza
    tion (click here)
●   http://databases.about.com/od/specificproducts/
    a/normalization.htm (click here)
Ερωτήσεις ???

Weitere ähnliche Inhalte

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Db crash_course-normalization

  • 1. Κανονικοποίηση Βάσεων Δεδοµένων (Database Normalization) Πχης (M) B. Παπαλιάκος ΠΝ (vpapaliakos@gmail.com)
  • 2. Διαδικαστικά θέµατα Διάρκεια: 20 λεπτά ● ●Η παρουσίαση είναι διαθέσιµη στη διεύθυνση http://papaliakos.gr/db/presentations ●Επίσης σας έχει διανεµηθεί σε χαρτί ώστε... ●ΝΑ ΚΡΑΤΗΣΕΤΕ ΣΗΜΕΙΩΣΕΙΣ! ●Ερωτήσεις δεκτές, κατά προτίµηση στο τέλος κάθε ενότητας
  • 3. Εισαγωγή ● Υπόθεση: είστε σχετικοί µε το αντικείµενο των ΒΔ. ● Νιώθετε ότι σας λείπουν κάποιες γνώσεις, όµως τα καταφέρατε σε µια-δυο περιπτώσεις που χρειάστηκε να φτιάξετε ΒΔ στην access. ● Σας προσφέρουν 2000 € για µια ΒΔ-δουλειά µιας εβδοµάδας: pas mal!
  • 5. Στόχοι Να µπορούµε να εξηγήσουµε τις έννοιες: ● Εξάρτηση (data dependency) ● Πλεονασµός (redundancy) και ● Ασυνέπεια (inconsistency) δεδοµένων Να µπορούµε να εξαλείψουµε τα παραπάνω προβλήµατα µέσω της κανονικοποίησης (normalization).
  • 6. Βασικές έννοιες - Πυλώνες ● Εξάρτηση (Dependency) ● Πλεονασµός δεδοµένων (Data redundancy) ● Ασυνέπεια δεδοµένων (Data inconsistency) ● Κανονικοποίηση (Normalization) ● Κανονικές µορφές (Normal forms) ● 1NF – 2NF - 3NF “Στο πεδίο των Η/Υ όπου κι αν πετάξεις µια πέτρα θα χτυπήσεις µια βάση δεδοµένων”
  • 7. 1. Εξάρτηση (Dependency) Όταν λέµε: το Y εξαρτάται από το X εννοούµε: Y=f(X) ● ή µε άλλα λόγια, το Χ καθορίζει το Υ. ● Αυτή η εξάρτηση σηµειώνεται ως X → Y. Παράδειγµα: invoice_id line_nr product_code product_name customer_name Τι εξαρτήσεις έχουµε εδώ;
  • 8. 1. Εξάρτηση (Dependency) Όταν λέµε: το Y εξαρτάται από το X εννοούµε: Y=f(X) ● ή µε άλλα λόγια, το Χ καθορίζει το Υ. ● Αυτή η εξάρτηση σηµειώνεται ως X → Y. Παράδειγµα: invoice_id line_nr product_code product_name customer_name product_code product_name → invoice_id → customer_name
  • 9. 1. Εξάρτηση (Dependency) Δώστε παραδείγµατα εξαρτηµένων µεταβλητών: ● Σε µια ΒΔ µαθητών-µαθηµάτων-βαθµών ● Σε µια ΒΔ υλικών-αποθηκών-αποθεµάτων ● Σε µια ΒΔ αυτοκινήτων
  • 10. “Καλή” και “Κακή” εξάρτηση ● “Καλή” εξάρτηση (“Good” dependency): ● Πρωτεύον κλειδί (Primary Key) → άλλες ιδιότητες ● “Κακές” εξαρτήσεις (“Bad” dependencies): ● Μερική εξάρτηση (Partial dependency) invoice_id line_nr product_code product_name customer_name ● Μεταβατική εξάρτηση (Transitive dependency) invoice_id line_nr product_code product_name customer_name
  • 12. 2Α. Πλεονασµός δεδοµένων (Data redundancy) Η ίδια πληροφορία φυλάσσεται σε διάφορα µέρη (διπλο-εγγραφή). Παράδειγµα: η διεύθυνση και το τηλέφωνο ενός πελάτη µπορεί να φυλάσεται στο αρχείο των λογαριασµών όψεως και στο αντίστοιχο αρχείο των λογαριασµών ταµιευτηρίου µιας τράπεζας. κωδ_λογαρ. πελ_όνοµα πελ_διευθ πελ_τηλ οψ-004 Παπαλιάκος Κρυστάλλη 6943483457 κωδ_λογαρ. πελ_όνοµα πελ_διευθ πελ_τηλ ταµ-037 Παπαλιάκος Κρυστάλλη 6943483457 Αυτό ονοµάζεται πλεονασµός δεδοµένων (data redundancy).
  • 13. 2Α. Πλεονασµός δεδοµένων (Data redundancy) ● Παράδειγµα: Τι µπορεί να πάει στραβά???
  • 14. 2Β. Ασυνέπεια δεδοµένων (Data inconsistency) ● Αυτός ο πλεονασµός µπορεί να οδηγήσει σε ασυνέπεια δεδοµένων (data inconsistency) δηλαδή σε ● διαφορετικά αντίγραφα των ιδίων δεδοµένων τα οποία ● µπορεί να µη συµφωνούν µεταξύ τους.
  • 15. 2Β. Ασυνέπεια δεδοµένων (Data inconsistency) ● διαφορετικά αντίγραφα των ιδίων δεδοµένων ● µπορεί να µη συµφωνούν µεταξύ τους. ● Παράδειγµα: αν αλλάξουµε τη διεύθυνση ενός πελάτη στο αρχείο των λογαριασµών ταµιευτηρίου, τότε αυτή η αλλαγή δεν θα φαίνεται οπουδήποτε αλλού (πχ. στο αρχείο των λογαριασµών όψεως). κωδ_λογαρ. πελ_όνοµα πελ_διευθ πελ_τηλ οψ-004 Παπαλιάκος Κρυστάλλη 6943483457 κωδ_λογαρ. πελ_όνοµα πελ_διευθ πελ_τηλ ταµ-037 Παπαλιάκος Καβάφη 6947159333
  • 16. 2Β. Ασυνέπεια δεδοµένων (Data inconsistency) ● διαφορετικά αντίγραφα των ιδίων δεδοµένων ● συµφωνούν µεταξύ τους;
  • 17. Προβλήµατα στα δεδοµένα µας (Data anomalies) Update anomaly Insertion anomaly Deletion anomaly
  • 18. Τι κάνουµε ??? I am superhero 2NF (arghh!) ● Normalization to the rescue I am super- superhero I am superhero 3NF 1NF (arghh!) (arghh!)
  • 19. 3. Normal forms & normalization 1η κανονική µορφή - First “The key...” Normal Form (1NF) 2η κανονική µορφή - Second “the whole key...” Normal Form (2NF) 3η κανονική µορφή - Third “and nothing but the key!” Normal Form (3NF)
  • 20. 3. Normal forms & normalization Η διαδικασία κανονικοποίησης (για κάθε πίνακα) ● Συµµόρφωση των δεδοµένων µας σε διαδοχικές κανονικές µορφές (1NF → 2NF → 3NF) ● Κάθε στήλη (σε κάθε πίνακα) εξαρτάται από ● Το κλειδί, ● ολόκληρο το κλειδί και ● τίποτα άλλο εκτός από το κλειδί ● 1NF (the key) → 2NF (the whole key) → 3NF (& nothing but the key)
  • 21. 3Α. 1η κανονική µορφή st 1 Normal Form (1NF) 1η κανονική µορφή First Normal Form (1NF): “the Key” ● Το κλειδί καθορίζει όλες τις ιδιότητες (στήλες) του πίνακα ● ΟΧΙ πολλαπλές τιµές σε µία στήλη ● ΟΧΙ οµάδες δεδοµένων: µία στήλη = µία ιδιότητα
  • 22. 3Α. 1η κανονική µορφή st 1 Normal Form (1NF) ● Ο παρακάτω πίνακας είναι σε 1NF;
  • 23. 3Β. 2η κανονική µορφή nd 2 Normal Form (2NF) 2η κανονική µορφή Second Normal Form (2NF): “the whole key...” ● 1η κανονική µορφή (1NF) + ● ΟΧΙ µερικές εξαρτήσεις (partial dependencies), Άρα............
  • 24. Θεραπεία για τις “κακές εξαρτήσεις” Αφαιρούµε τις µερικές εξαρτήσεις invoice_id line_nr product_code product_name customer_name invoice_id line_nr product_code product_name invoice_id customer_name
  • 25. 3Γ. 3η κανονική µορφή rd 3 Normal Form (3NF) 3η κανονική µορφή Third Normal Form (3NF): “...and nothing but the key!” ● 2η κανονική µορφή (2NF) + ● ΟΧΙ µεταβατικές εξαρτήσεις (transitive dependencies) Οπότε..............
  • 26. Θεραπεία για τις “κακές εξαρτήσεις” Αφαιρούµε τις µεταβατικές εξαρτήσεις invoice_id line_nr product_code product_name invoice_id customer_name invoice_id line_nr product_code product_code product_name invoice_id customer_name
  • 28. Συνεπώς... ● Αφαιρούµε – Πολλαπλές στήλες – πολλαπλές τιµές – Μερικές εξαρτήσεις – Μεταβατικές εξαρτήσεις ● Εξαλείφουµε προβλήµατα στα δεδοµένα µας ● Κανονικοποίηση όλων των πινάκων ● Κανονικοποίηση όλης της ΒΔ
  • 29. Επίλογος ● Βασικές έννοιες – Εξάρτηση (Dependency) – Πλεονασµός δεδοµένων (Data redundancy) – Ασυνέπεια δεδοµένων (Data inconsistency) – Κανονικοποίηση (Normalization) – Κανονικές µορφές (Normal forms) 1NF – 2NF - 3NF
  • 30. Επίλογος Στόχοι: 1.Να µπορούµε να εξηγήσουµε τις έννοιες: – Εξάρτηση (data dependency) – Πλεονασµός (redundancy) και – Ασυνέπεια (inconsistency) δεδοµένων 2.Να µπορούµε να εξαλείψουµε τα παραπάνω προβλήµατα µέσω της κανονικοποίησης (normalization).
  • 31. Πηγές ● http://en.wikipedia.org/wiki/Database_normaliza tion (click here) ● http://databases.about.com/od/specificproducts/ a/normalization.htm (click here)