Normalisasi
15 Desember 2011
Integrity Constraint
 Redundancy
    Sumber masalah mengapa perlu Schema Refinement
 Dipecahkan dengan Dekomposisi
    Dekomposisi tidak terbebas dari masalah
    Harus dilakukan dengan hati-hati
 Constraint Anomalies
    Redundant Storage
    Update Anomalies
    Insertion Anomalies
    Deletion Anomalies
              Normal Form                             2
Multi-valued Column
 Seorang pegawai memiliki 1 atau lebih bawahan
 Seorang customer boleh memesan barang 1 kali atau
  lebih




      Ssn             Name        AB1           AB2           AB3
      123-22-3666     Attisho
      231-31-5368     Smiley      123-22-3666
      131-24-3650     Smethurst   231-31-5368   434-26-3751
      434-26-3751     Guldu                     612-67-4134
      612-67-4134       Madayan
                    Normal Form   131-24-3650                       3
Multi-valued Column
 Seorang pegawai memiliki 1 atau lebih bawahan
 Seorang customer boleh memesan barang 1 kali atau
  lebih




      Ssn             Name        AnakBuah
      123-22-3666     Attisho
      231-31-5368     Smiley      123-22-3666
      131-24-3650     Smethurst   231-31-5368, 434-26-3751
      434-26-3751     Guldu       612-67-4134
      612-67-4134      Madayan
                    Normal Form   131-24-3650                4
Bentuk Normal Pertama
 1st Normal Form
    Hilangkan duplicative columns dari setiap tabel
    Dekomposisi setiap kelompok atribut yang
      berhubungan ke dalam masing-masing tabel dengan
      diidentifikasi melalui Primary Key


      Ssn             Name        AnakBuah
      123-22-3666     Attisho
      231-31-5368     Smiley      123-22-3666
      131-24-3650     Smethurst   231-31-5368, 434-26-3751
      434-26-3751     Guldu       612-67-4134
      612-67-4134      Madayan
                    Normal Form   131-24-3650                5
Bentuk Normal Kedua
 2nd Normal Form
    Memenuhi 1st NF
    Pindahkan subset dari data pada sebuah tabel ke tabel
     lain
    Buat relasi antara tabel yang baru dengan tabel parent
     melalui hubungan Foreign Key
 Mengurangi jumlah data yang redundant pada tabel
  dengan memindahkannya ke tabel lain



                Normal Form                                   6
Bentuk Normal Kedua
 Customer (custID, fname, lname, address, city,
  province, postalcode)
 Redundancy
    (101, 'M', 'Najih', 'Gg. Guan I/2', 'Tangerang', 'Banten',
     99102)
    (102, 'Agung', 'Sediyono', 'Gd E lt.8', 'Karawaci', 'Banten',
     99102)




                 Normal Form                                         7
Bentuk Normal Kedua
 Dekomposisi relasi Customer (custID, fname, lname,
  address, city, province, postalcode)
    Customer (custID, fname, lname, address)
    ZIPcode (postalcode, city, province)
 Buat relasi Foreign Key antara Customer dan ZIPCode
   Customer (custID, fname, lname, address,
    postalcode)
   ZIPcode (postalcode, city, province)



              Normal Form                               8
Bentuk Normal Ketiga
 3rd Normal Form
    Memenuhi 1st NF dan 2nd NF
    Hapus atribut yang tidak bergantung kepada Primary
     Key
 Pesanan (IDpesanan, custID, hargaSatuan, jumlah,
  total)
    IDPesanan  hargaSatuan
    IDPesanan, custID  jumlah
 Atribut total bisa dihapus
    total = hargaSatuan × jumlah
               Normal Form                                9
Bentuk Normal Ketiga
 Atribut total bisa dihapus
    total = hargaSatuan × jumlah
 Pesanan (IDpesanan, custID, hargaSatuan, jumlah)
  SELECT IDPesanan, Total
  FROM Pesanan
  diganti dengan
  SELECT IDPesanan, hargaSatuan * jumlah AS Total
  FROM Pesanan




              Normal Form                            10
Boyce-Codd Normal Form
 Candidate Key
    Himpunan atribut yang dapat digunakan untuk
     mengidentifikasi secara unik baris-baris di dalam tabel
     basis data
 Primary Key
    Candidate Key yang dipilih menjadi Kunci dari tabel
 Determinan
    Candidate Key yang tidak dipilih menjadi Kunci




                Normal Form                                    11
Boyce-Codd Normal Form
 BCNF
    Memenuhi 1st NF, 2nd NF, dan 3rd NF
    Semua determinan adalah Candidate Key




              Normal Form                    12
How Far Should You Go?
 4th NF, 5th NF, 6th NF
 Kebanyakan kasus cukup hingga 3rd NF
 4th NF mendekomposisi tabel-tabel terlalu jauh
    Kinerja database turun
    Terlalu banyak join antar tabel




               Normal Form                         13
FD dan NF
 For a table to be in second normal form (2NF), there
  must be no case of a non-prime attribute in the table
  that is functionally dependendent upon a subset of
  a candidate key.
 For a table to be in third normal form (3NF), every
  non-prime attribute must have a non-transitive
  functional dependency on every candidate key.




               Normal Form                                14
FD dan NF
 For a table to be in Boyce-Codd Normal Form (BCNF),
  every functional dependency (other than trivial
  dependencies) must be on a superkey.
 For a table to be in fourth normal form (4NF), it must
  have no multivalued dependencies.




               Normal Form                                 15
Kasus Kardinalitas
 1-to-N
    Seorang Dosen membimbing beberapa mahasiswa PA
    Satu mahasiswa dibimbing oleh seorang Dosen PA
 mhs(nim, nama, e-mail, nik)
 dosen(nik, nama, e-mail)




              Normal Form                             16
Kasus Kardinalitas
 M-to-N
   Seorang Mahasiswa mengambil beberapa Mata Kuliah
   Satu Mata Kuliah diikuti oleh beberapa orang
    Mahasiswa
 mhs(nim, nama, e-mail, nik)
 mk (kodemk, nama, konsentrasi)
 krs (kodemk, nim, grade)




              Normal Form                              17
Kasus Kardinalitas
 CREATE TABLE mhs (
    nim CHAR(8) PRIMARY KEY,
    nama VARCHAR(20) NOT NULL,
    email VARCHAR(30),
 );
 CREATE TABLE mk (
    kodemk CHAR(6) PRIMARY KEY,
    nama VARCHAR(20) NOT NULL,
    konsentrasi VARCHAR(20) NOT NULL
 );



            Normal Form                18
Kasus Kardinalitas
 CREATE TABLE krs (
    kodemk CHAR(6) NOT NULL,
    nim CHAR(8) NOT NULL,
    FOREIGN KEY (kodemk) REFERENCES mk (kodemk),
    FOREIGN KEY (nim) REFERENCES mhs (nim)
 );




            Normal Form                            19
Pustaka
 Ramakhrisnan, Raghu & Johannes Gehrke, "Database
  Management Systems", 2nd ed., McGraw-Hill, 2000.
 Elmasri dan Navathe, "Foundation of Database System"
 http://databases.about.com/od/specificproducts/a/Databa
  se-Dependency.htm
 http://tjerdastangkas.blogspot.com/search/label/ikd312




               Normal Form                              20
Kamis, 15 Desember 2011

ikd312-09-normalisasi

  • 1.
  • 2.
    Integrity Constraint  Redundancy  Sumber masalah mengapa perlu Schema Refinement  Dipecahkan dengan Dekomposisi  Dekomposisi tidak terbebas dari masalah  Harus dilakukan dengan hati-hati  Constraint Anomalies  Redundant Storage  Update Anomalies  Insertion Anomalies  Deletion Anomalies Normal Form 2
  • 3.
    Multi-valued Column  Seorangpegawai memiliki 1 atau lebih bawahan  Seorang customer boleh memesan barang 1 kali atau lebih Ssn Name AB1 AB2 AB3 123-22-3666 Attisho 231-31-5368 Smiley 123-22-3666 131-24-3650 Smethurst 231-31-5368 434-26-3751 434-26-3751 Guldu 612-67-4134 612-67-4134 Madayan Normal Form 131-24-3650 3
  • 4.
    Multi-valued Column  Seorangpegawai memiliki 1 atau lebih bawahan  Seorang customer boleh memesan barang 1 kali atau lebih Ssn Name AnakBuah 123-22-3666 Attisho 231-31-5368 Smiley 123-22-3666 131-24-3650 Smethurst 231-31-5368, 434-26-3751 434-26-3751 Guldu 612-67-4134 612-67-4134 Madayan Normal Form 131-24-3650 4
  • 5.
    Bentuk Normal Pertama 1st Normal Form  Hilangkan duplicative columns dari setiap tabel  Dekomposisi setiap kelompok atribut yang berhubungan ke dalam masing-masing tabel dengan diidentifikasi melalui Primary Key Ssn Name AnakBuah 123-22-3666 Attisho 231-31-5368 Smiley 123-22-3666 131-24-3650 Smethurst 231-31-5368, 434-26-3751 434-26-3751 Guldu 612-67-4134 612-67-4134 Madayan Normal Form 131-24-3650 5
  • 6.
    Bentuk Normal Kedua 2nd Normal Form  Memenuhi 1st NF  Pindahkan subset dari data pada sebuah tabel ke tabel lain  Buat relasi antara tabel yang baru dengan tabel parent melalui hubungan Foreign Key  Mengurangi jumlah data yang redundant pada tabel dengan memindahkannya ke tabel lain Normal Form 6
  • 7.
    Bentuk Normal Kedua Customer (custID, fname, lname, address, city, province, postalcode)  Redundancy  (101, 'M', 'Najih', 'Gg. Guan I/2', 'Tangerang', 'Banten', 99102)  (102, 'Agung', 'Sediyono', 'Gd E lt.8', 'Karawaci', 'Banten', 99102) Normal Form 7
  • 8.
    Bentuk Normal Kedua Dekomposisi relasi Customer (custID, fname, lname, address, city, province, postalcode)  Customer (custID, fname, lname, address)  ZIPcode (postalcode, city, province)  Buat relasi Foreign Key antara Customer dan ZIPCode  Customer (custID, fname, lname, address, postalcode)  ZIPcode (postalcode, city, province) Normal Form 8
  • 9.
    Bentuk Normal Ketiga 3rd Normal Form  Memenuhi 1st NF dan 2nd NF  Hapus atribut yang tidak bergantung kepada Primary Key  Pesanan (IDpesanan, custID, hargaSatuan, jumlah, total)  IDPesanan  hargaSatuan  IDPesanan, custID  jumlah  Atribut total bisa dihapus  total = hargaSatuan × jumlah Normal Form 9
  • 10.
    Bentuk Normal Ketiga Atribut total bisa dihapus  total = hargaSatuan × jumlah  Pesanan (IDpesanan, custID, hargaSatuan, jumlah) SELECT IDPesanan, Total FROM Pesanan diganti dengan SELECT IDPesanan, hargaSatuan * jumlah AS Total FROM Pesanan Normal Form 10
  • 11.
    Boyce-Codd Normal Form Candidate Key  Himpunan atribut yang dapat digunakan untuk mengidentifikasi secara unik baris-baris di dalam tabel basis data  Primary Key  Candidate Key yang dipilih menjadi Kunci dari tabel  Determinan  Candidate Key yang tidak dipilih menjadi Kunci Normal Form 11
  • 12.
    Boyce-Codd Normal Form BCNF  Memenuhi 1st NF, 2nd NF, dan 3rd NF  Semua determinan adalah Candidate Key Normal Form 12
  • 13.
    How Far ShouldYou Go?  4th NF, 5th NF, 6th NF  Kebanyakan kasus cukup hingga 3rd NF  4th NF mendekomposisi tabel-tabel terlalu jauh  Kinerja database turun  Terlalu banyak join antar tabel Normal Form 13
  • 14.
    FD dan NF For a table to be in second normal form (2NF), there must be no case of a non-prime attribute in the table that is functionally dependendent upon a subset of a candidate key.  For a table to be in third normal form (3NF), every non-prime attribute must have a non-transitive functional dependency on every candidate key. Normal Form 14
  • 15.
    FD dan NF For a table to be in Boyce-Codd Normal Form (BCNF), every functional dependency (other than trivial dependencies) must be on a superkey.  For a table to be in fourth normal form (4NF), it must have no multivalued dependencies. Normal Form 15
  • 16.
    Kasus Kardinalitas  1-to-N  Seorang Dosen membimbing beberapa mahasiswa PA  Satu mahasiswa dibimbing oleh seorang Dosen PA  mhs(nim, nama, e-mail, nik)  dosen(nik, nama, e-mail) Normal Form 16
  • 17.
    Kasus Kardinalitas  M-to-N  Seorang Mahasiswa mengambil beberapa Mata Kuliah  Satu Mata Kuliah diikuti oleh beberapa orang Mahasiswa  mhs(nim, nama, e-mail, nik)  mk (kodemk, nama, konsentrasi)  krs (kodemk, nim, grade) Normal Form 17
  • 18.
    Kasus Kardinalitas CREATETABLE mhs ( nim CHAR(8) PRIMARY KEY, nama VARCHAR(20) NOT NULL, email VARCHAR(30), ); CREATE TABLE mk ( kodemk CHAR(6) PRIMARY KEY, nama VARCHAR(20) NOT NULL, konsentrasi VARCHAR(20) NOT NULL ); Normal Form 18
  • 19.
    Kasus Kardinalitas CREATETABLE krs ( kodemk CHAR(6) NOT NULL, nim CHAR(8) NOT NULL, FOREIGN KEY (kodemk) REFERENCES mk (kodemk), FOREIGN KEY (nim) REFERENCES mhs (nim) ); Normal Form 19
  • 20.
    Pustaka  Ramakhrisnan, Raghu& Johannes Gehrke, "Database Management Systems", 2nd ed., McGraw-Hill, 2000.  Elmasri dan Navathe, "Foundation of Database System"  http://databases.about.com/od/specificproducts/a/Databa se-Dependency.htm  http://tjerdastangkas.blogspot.com/search/label/ikd312 Normal Form 20
  • 21.