Normalization Exercises


 

ANOTHER EXAMPLE

One approach is to fool the system by defining a fixed number of separate fields with different names, when they are really repetitions of the same field. The result is a violation of first normal form. Normalization can improve the quality of a database design. The following table, UnPerson, is not normalized because it has multiple values for language for each person.

 

UnPerson        
Personcode FirstName Lang1 Lang2 Lang3
1 Rita German English Dutch
2 Wei Mandarin English  
3 Alice English French  
4 Ned English Japanese  
5 Sophie   English  

To appreciate the problems of using an unnormalize database, write the following queries

  1. List all people who speak French.
  2. List those who speak English and no other language.
  3. Who speaks the most languages?
  4. Add the fact that Rita speaks French.
  5. Suppose that Lang1 is considered the primary or native language or each person. After many years in New Zealand, Wei wants English listed as his primary language.
  6. George, whose record is not shown, just joined the firm. He speaks English and French.

A normalized design

The correct data model, which recognizes a m:m relationship between person and language, generally requires three tables. In this particular case, the Lang table is not necessary since there are no additional attributes of language to be stored. A separate Lang table would be necessary if you wanted to keep a master list of all languages, to control the set of valid values for language, or to store any languages which did not appear in the UnPerson table. Whether you decide to include the the Lang table is not a major issue since it takes little effort to create and maintain, and takes little storage space.

 

Person  
Personcode FirstName
1 Rita
2 Wei
3 Alice
4 Ned
5 Sophie
PersonLang  
Personcode Language
1 German
1 English
1 Dutch
2 Mandarin
2 English
3 English
3 French
4 English
4 Japanese
5 English
Lang
Language
German
English
Dutch
Mandarin
French
Japanese

A 1:m relationship between lang and person can record the fact that a person has a single primary language and that a language can be a primary language for many people. The revised tables, showing the foreign key for the new relationship, are:

 

Person    
Personcode FirstName PrimeLang
1 Rita German
2 Wei Mandarin
3 Alice English
4 Ned English
5 Sophie English
PersonLang  
Personcode Language
1 German
1 English
1 Dutch
2 Mandarin
2 English
3 English
3 French
4 English
4 Japanese
5 English
Lang
Language
German
English
Dutch
Mandarin
French
Japanese

Normalization Problems


 

1. The following set of data refers to information utilized in an animal clinic. Assume that people's names in this set of data are unique. An agent is a person who may authorize treatment for the pet in the owner's absence (typically a family member, friend or neighbor). Fully describe the process of normalizing this data and show each table produced when going to each normal form. Be certain to explain any other assumptions which you make concerning the data. When showing the tables you create, you need only give the table name, fields in the table, and the primary key for that table.

 

Owner Name Owner Phone Pet Name Type Gender Last Exam Date Exam Comments Agent Name Agent Phone
Jim Jones 623-7494 Amber Cat F 2/12/96 Feline leukemia shot Martha Jones 623-7494
    Bonzo Chimp M 2/19/96 Flu shot Todd Jones 623-7494
              Sam Martin 623-8200
Sam Martin 623-8200 Queenie Dog F 4/17/96 Parvo shot Jim Jones 623-7494
Jane Doe 887-4201 Max Dog M 7/15/96 Distemper shot Todd Jones 623-7494

2. The following set of data refers to information utilized in tracking grades. Assume that people's names in this set of data are unique. An Item # is a unique identifier for a particular class and section for a particular quarter; Class Id is the unique identifier for a particular course but does not change for different sections or quarters; Professor Id, Student Id, Name and Grade are just what you think they would be. Fully describe the process of normalizing this data and show each table produced when going to each normal form. Show all intermediate steps and clearly list any assumptions made. When showing the tables you create, you need only give the table name, fields in the table, and the primary key for that table.

 

Item # Class Id Class Name Student Id Student Name Prof Id Prof Name Grade
1985 CMPTR245 Struct Anal&Design 381161772 Harry Henderson 1001 Ms Evelyn Appel 2.3
1985 CMPTR245 Struct Anal&Design 365897890 Holly Hunter 1001 Ms Evelyn Appel 4.0
2105 CMPTR285 Prog with C++ 381161772 Harry Henderson 2108 Dr Ted Smith 2.3
2105 CMPTR285 Prog with C++ 365897890 Holly Hunter 2108 Dr Ted Smith 3.7
3487 ENGL104 Technical Writing 365897890 Holly Hunter 1917 Dr Cathryn Quinell 3.3
3488 ENGL104 Technical Writing 381161772 Harry Henderson 1181 Dr Margaret Jones 2.7