Alper VAHAPLAR 2016 2017
Relations: viewed as 2-dimensional tables rows x columns Properties: Each column has a unique name. Order of columns are unimportant. Each column contains values about the same attribute. Each row is unique. No repeating rows. Order of the rows is unimportant. Alper VAHAPLAR Database Management - 3 2
Tuple : Values constructing a row, (record) Degree : Number of attributes in a tuple Cardinality : Number of tuples in a relation Domain : Set of possible values for an attribute Alper VAHAPLAR Database Management - 3 3
Alper VAHAPLAR Database Management - 3 4
Alper VAHAPLAR Database Management - 3 5
Öğrenciler Attribute Tuple No AdSoyad Sınıf DogYili DogYeri 123 Ali Veli 3 1982 Muğla 456 Hasan Hüseyin 3 1981 Afyon 789 Ayşe Fatma 2 1983 İzmir 102 Ahmet Mehmet 3 1981 Aydın 260 Fuat Murat 2 1983 Manisa 346 Lale Jale 3 1982 İzmir Alper VAHAPLAR Database Management - 3 6
Normalization is the process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating redundancy and inconsistent dependency. Alper VAHAPLAR Database Management - 3 7
Process of assigning attributes to entities. Aims: reducing data redundancy, eliminating anomalies, producing controlled redundancy to link tables. Alper VAHAPLAR Database Management - 3 8
There are a few rules for database normalization. Each rule is called a "normal form." If the first rule is observed, the database is said to be in "first normal form." If the first three rules are observed, the database is considered to be in "third normal form." Although other levels of normalization are possible, third normal form is considered the highest level necessary for most applications. Alper VAHAPLAR Database Management - 3 9
Alper VAHAPLAR Database Management - 3 10
Alper VAHAPLAR Database Management - 3 11
RPT_FORMAT (PROJ_NUM, PROJ_NAME, EMP_NUM, EMP_NAME, JOB_CLASS, CHG_HOUR, HOURS) Alper VAHAPLAR Database Management - 3 12
Rules: Each relation (table) must represent one and only one entity. No data must repeat redundantly in different relations. All the attributes must be dependant on the key attribute. Alper VAHAPLAR Database Management - 3 13
First Normal Form Eliminate repeating groups in individual tables. Create a separate table for each set of related data. Identify each set of related data with a primary key. Second Normal Form Create separate tables for sets of values that apply to multiple records. Relate these tables with a foreign key. Third Normal Form Eliminate fields that do not depend on the key. Alper VAHAPLAR Database Management - 3 14
First Normal Form Eliminate repeating groups in individual tables. Create a separate table for each set of related data. Identify each set of related data with a primary key. Alper VAHAPLAR Database Management - 3 15
First Normal Form RPT_FORMAT (Proj_num, Proj_name, { Emp_num, Emp_name, Job_class, Chg_hour, Hours) } PROJ (Proj_num, Proj_name) EMPLOYEE (Emp_num, Emp_name, Job_class, Chg_hour, Hours) Alper VAHAPLAR Database Management - 3 16
Second Normal Form Remove Partial Dependencies Create separate tables for sets of values that apply to multiple records. Relate these tables with a foreign key. Each attribute must be FULLY DEPENDANT to the key attribute. Alper VAHAPLAR Database Management - 3 17
Second Normal Form PROJ (Proj_num, Proj_name) EMPLOYEE (Emp_num, Emp_name, Job_class, Chg_hour, Hours) EMPLOYEE (Emp_num, Emp_name, Job_class, Chg_hour) ASSIGN (Emp_num, Proj_num, Hours) Alper VAHAPLAR Database Management - 3 18
Third Normal Form Remove Transitive Dependencies. Eliminate fields that do not depend on the key. Search for another attribute to identify better than the key attribute. Alper VAHAPLAR Database Management - 3 19
Third Normal Form EMPLOYEE (Emp_num, Emp_name, Job_class, Chg_hour) ASSIGN (Emp_num, Proj_num, Hours) EMPLOYEE (Emp_num, Emp_name, Job_class) JOB (Job_class, Chg_hour) Alper VAHAPLAR Database Management - 3 20
1 st NF Convert to Table Format, No repeating fields, Define Key attributes. 2 nd NF 1 st NF Eliminate partial dependencies 3 rd NF 2 nd NF Eliminate transitive dependencies Alper VAHAPLAR Database Management - 3 21
Alper VAHAPLAR Database Management - 3 22
Film (filmno, title, dir_no, dir_name, year, type, pl_no, pl_name, pl_dob, order) 1st Normalization Remove repeating groups Film (filmno, title, dir_no, dir_name, year, type) Player (pl_no, pl_name, pl_dob, order) Alper VAHAPLAR Database Management - 3 23
Film (filmno, title, dir_no, dir_name, year, type) Player(pl_no, pl_name, pl_dob, order) 2nd Normalization Remove partial dependencies Player (pl_no, pl_name, pl_dob) Cast (filmno, pl_no, order) Alper VAHAPLAR Database Management - 3 24
Film (filmno, title, dir_no, dir_name, year, type) Player (pl_no, pl_name, pl_dob) Cast (filmno, pl_no, order) 3rd Normalization Remove transitive dependencies Film (filmno, title dir_no, year, type) Director(dir_no, dir_name) Alper VAHAPLAR Database Management - 3 25
Film (filmno, title, dir_no, dir_name, year, type, pl_no, pl_name, pl_dob, order) Film (filmno, title dir_no, year, type) Player (pl_no, pl_name, pl_dob) Cast (filmno, pl_no, order) Director(dir_no, dir_name) Alper VAHAPLAR Database Management - 3 26
Normalize the following data collection Kütüphane (kitapno, kitapadı, konusu, rafno, yazarno, yazaradı, sayfasayısı, kullanıcıno, kullanıcıadı, adres, telefon, alıştarihi, iadetarihi) Alper VAHAPLAR Database Management - 3 27
Kütüphane (kitapno, kitapadı, konusu, rafno, yazarno, yazaradı, sayfasayısı, { kullanıcıno, kullanıcıadı, adres, telefon, alıştarihi, iadetarihi) } 1st Normalization Remove repeating groups Kitaplar (kitapno, kitapadı, konusu, rafno, yazarno, yazaradı, sayfasayısı) Kullanıcılar(kullanıcıno, kullanıcıadı, adres, telefon, alıştarihi, iadetarihi) Alper VAHAPLAR Database Management - 3 28
Kitaplar (kitapno, kitapadı, konusu, rafno, yazarno, yazaradı, sayfasayısı) Kullanıcılar (kullanıcıno, kullanıcıadı, adres, telefon, alıştarihi, iadetarihi) 2nd Normalization Remove partial dependencies Kullanıcılar (kullanıcıno, kullanıcıadı, adres, telefon) Kira (kullanıcıno, kitapno, alıştarihi, iadetarihi) Alper VAHAPLAR Database Management - 3 29
Kitaplar (kitapno, kitapadı, konusu, rafno, yazarno, yazaradı, sayfasayısı) Kullanıcılar (kullanıcıno, kullanıcıadı, adres, telefon) Kira (kullanıcıno, kitapno, alıştarihi, iadetarihi) 3rd Normalization Remove transitive dependencies Kitaplar (kitapno, kitapadı, konusu, rafno, yazarno, sayfasayısı) Yazar (yazarno, yazaradı) Alper VAHAPLAR Database Management - 3 30
(kitapno, kitapadı, konusu, rafno, yazarno, yazaradı, sayfasayısı, kullanıcıno, kullanıcıadı, adres, telefon, alıştarihi, iadetarihi) Kitaplar (kitapno, kitapadı, konusu, rafno, yazarno, sayfasayısı) Kullanıcılar (kullanıcıno, kullanıcıadı, adres, telefon) Yazar (yazarno, yazaradı) Kira (kullanıcıno, kitapno, alıştarihi, iadetarihi) Alper VAHAPLAR Database Management - 3 31
Araba Kiralama veri tabanı Kira (plaka, marka, model, yıl, motorhacmi, yakıttipi, müş_no, müş_adi, müş_adresi, müş_tel, kira_tarihi, kaçgün, günlükücret) Alper VAHAPLAR Database Management - 3 32
Kira (plaka, marka, model, yıl, motorhacmi, yakıttipi, müş_no, müş_adi, müş_adresi, müş_tel, kira_tarihi, kaçgün, günlükücret) 1st Normalization Araba (plaka, marka, model, yıl, motorhacmi, yakıttipi) Müşteri (müş_no, müş_adi, müş_adresi, müş_tel, kira_tarihi, kaçgün, günlükücret) Alper VAHAPLAR Database Management - 3 33
Araba (plaka, marka, model, yıl, motorhacmi, yakıttipi) Müşteri (müş_no, müş_adi, müş_adresi, müş_tel, kira_tarihi, kaçgün, günlükücret) 2nd Normalization Müşteri (müş_no, müş_adi, müş_adresi, müş_tel) Kiralama (müş_no, plaka, kira_tarihi, kaçgün, günlükücret) Alper VAHAPLAR Database Management - 3 34
Araba (plaka, marka, model, yıl, motorhacmi, yakıttipi) Müşteri (müş_no, müş_adi, müş_adresi, müş_tel) Kiralama (müş_no, plaka, kira_tarihi, kaçgün, günlükücret) 3rd Normalization Not detected Alper VAHAPLAR Database Management - 3 35
Kira (plaka, marka, model, yıl, motorhacmi, yakıttipi, müş_no, müş_adi, müş_adresi, müş_tel, kira_tarihi, kaçgün, günlükücret) Araba (plaka, marka, model, yıl, motorhacmi, yakıttipi) Müşteri (müş_no, müş_adi, müş_adresi, müş_tel) Kiralama (müş_no, plaka, kira_tarihi, kaçgün, günlükücret) Alper VAHAPLAR Database Management - 3 36
Bir firmada çalışan işçilerin kimlik bilgileri (isim, adres, tel, vs ), çalıştığı departmanın kodu, departmanın adı, çalışanın görevi, çalışanların hangi gün saat kaçta giriş ve çıkış yaptıkları bilgisi tutulmak istenmektedir. Bu verilere göre tabloları oluşturup normalizasyon işlemini gerçekleştiriniz Alper VAHAPLAR Database Management - 3 37
Firma (çalışan_no, isim, adres, tel, vs, dep_kod, dep_adi, görevi, tarih, giriş, çıkış) 1st Normalization Kimlik (çalışan_no, isim, adres, dep_kod, dep_adi, görevi, tel, vs) Mesai (tarih, giriş, çıkış) Alper VAHAPLAR Database Management - 3 38
Kimlik (çalışan_no, isim, adres, dep_kod, dep_adi, görevi, tel, vs) Mesai (tarih, giriş, çıkış) 2nd Normalization Mesai (çalışan_no, tarih, giriş, çıkış) Alper VAHAPLAR Database Management - 3 39
Kimlik (çalışan_no, isim, adres, dep_kod, dep_adi, görevi, tel, vs) Mesai (çalışan_no, tarih, giriş, çıkış) 3rd Normalization Kimlik (çalışan_no, isim, adres, dep_kod, görevi, tel, vs) Departman (dep_kod, dep_adi) Alper VAHAPLAR Database Management - 3 40
Firma (çalışan_no, isim, adres, tel, vs, dep_kod, dep_adi, görevi, tarih, giriş, çıkış) Kimlik (çalışan_no, isim, adres, dep_kod, görevi, tel, vs) Departman (dep_kod, dep_adi) Mesai (çalışan_no, tarih, giriş, çıkış) Alper VAHAPLAR Database Management - 3 41
Sales Order Fiction Company 202 N. Main Mahattan, KS 66502 CustomerNumber: 1001 Sales Order Number: 405 Customer Name: ABC Company Sales Order Date: 2/1/2000 Customer Address: 100 Points Clerk Number: 210 Manhattan, KS 66502 Clerk Name: Martin Lawrence Item Ordered Description Quantity Unit Price Total 800 801 805 widgit small tingimajigger thingibob 40 20 10 60.00 20.00 100.00 2,400.00 400.00 1,000.00 Order Total 3,800.00 Alper VAHAPLAR Database Management - 3 42
Sales (SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo, ClerkName, ItemNo, Description, Qty, UnitPrice) 1st Normalization Orders (SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo, ClerkName) Details (ItemNo, Description, Qty, UnitPrice) Alper VAHAPLAR Database Management - 3 43
Orders (SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo, ClerkName) Details (ItemNo, Description, Qty, UnitPrice) 2nd Normalization Items (ItemNo, Description, UnitPrice) Details (SalesOrderNo, ItemNo, Qty) Alper VAHAPLAR Database Management - 3 44
Orders (SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo, ClerkName) Items (ItemNo, Description) Details (SalesOrderNo, ItemNo, Qty, UnitPrice) 3rd Normalization Customers (CustomerNo, CustomerName, CustomerAdd) Clerks (ClerkNo, ClerkName) Sales (SalesOrderNo, Date, CustomerNo, ClerkNo) Alper VAHAPLAR Database Management - 3 45
Customers (CustomerNo, CustomerName, CustomerAdd) Clerks (ClerkNo, ClerkName) Sales (SalesOrderNo, Date, CustomerNo, ClerkNo) Details (SalesOrderNo, ItemNo, Qty, UnitPrice) Items (ItemNo, Description) Alper VAHAPLAR Database Management - 3 46
Analyze and Design (Normalize) the data you collected in the first homework Alper VAHAPLAR Database Management - 3 47