Download presentation
Presentation is loading. Please wait.
Published byEzra Jones Modified over 9 years ago
1
Texas State Technical College DISCOVER! Second Normal Form - 2NF It has to be the whole key.
2
Texas State Technical College DISCOVER! Second Normal Form (2NF) 2NF is an extension to 1NF that increases the organization in the database. A database is 2NF when all of the contained tables are 2NF. The focus of 2NF is to eliminate partial dependencies on primary keys. A table that is 1NF and uses a singular primary key is automatically 2NF. Overview
3
Texas State Technical College DISCOVER! In order for a table to be considered 2NF Must be 1NFMust be 1NF All fields should be dependent or related to the whole primary keyAll fields should be dependent or related to the whole primary key If a composite primary key is used, there must not be a field that is only related to a portion of the primary keyIf a composite primary key is used, there must not be a field that is only related to a portion of the primary key The Technical Definition Second Normal Form (2NF)
4
Texas State Technical College DISCOVER! In order for a table to be considered 2NF No repeating groups (1NF)No repeating groups (1NF) All fields must be directly related to the entire primary key.All fields must be directly related to the entire primary key. Tables that utilize a singular primary key are automatically 2NF, provided that they are 1NF.Tables that utilize a singular primary key are automatically 2NF, provided that they are 1NF. The Layman’s Definition Second Normal Form (2NF)
5
Texas State Technical College DISCOVER! Are known as composite primary keys and can be problematic. It is a primary key that is composed of two or more fields. It is very common that fields in a composite key are also foreign keys. These fields are both foreign keys and partial primary keys. Non-Singular Primary Keys Second Normal Form (2NF)
6
Texas State Technical College DISCOVER! Sometimes their use is more logical than creating a new primary key. Sometimes values in fields produce a unique identifier when combined that is more useful than a random or sequential number. For Example Name + Date is easier to remember and use as a primary key than an automatically generated 10 digit number. John-Davis-14may07 VS 3245873245 Why Use Composite Primary Keys? Second Normal Form (2NF)
7
Texas State Technical College DISCOVER! Composite primary keys are the source of the problem that requires normalization to 2NF. Only tables with composite primary keys have to be converted to 2NF. Avoiding the use of composite keys avoids the problems Linking a foreign key to two or more fieldsLinking a foreign key to two or more fields Having to guarantee a database is 2NFHaving to guarantee a database is 2NF It can be summed up as It’s about the key, the whole key. 2NF Second Normal Form (2NF)
8
Texas State Technical College DISCOVER! In the example below, the table is not 2NF because it contains partial dependencies. For Example… [ DMV ] Registration SSN pk/fk VIN pk/fk Registered pk ExpiresCountyMfgMake Text Date Text 521443684A1456714-Jan-0213-Jan-03TaylorFordFocus 884652471RTE78625-Mar-0624-Mar-07JonesDodgeNeon 996335588QW934527-Oct-0026-Oct-01TaylorFordMustang 114225575TS323211-Nov-0410-Nov-05CallahanKiaSpectra Problem: Partial dependencies upon the primary key. Second Normal Form (2NF)
9
Texas State Technical College DISCOVER! Let’s verbalize the relationships. For Example… [ DMV ] Registration SSN pk/fk VIN pk/fk Registered pk ExpiresCountyMfgMake A Registration is the ownership by a person SSN for a vehicle VIN created on date Registered. SSN, VIN, and Registered are the unique identifier for a registration. Expires defines the date of expiration for a registration. The county describes the geographical locale for a registration. Mfg describes the manufacturer of the vehicle in the registration. Make describes the model of the vehicle in the registration Second Normal Form (2NF)
10
Texas State Technical College DISCOVER! From verbalizing we can see… For Example… [ DMV ] Registration SSN pk/fk VIN pk/fk Registered pk ExpiresCountyMfgMake SSN, VIN, and Registered are the fields that compose the primary key, thus it is a composite primary key. Expires and County refer to the whole primary key as they apply to the whole concept of a registration. Mfg and Make are partially dependent upon the primary key because they only describe the vehicle represented by VIN. Second Normal Form (2NF)
11
Texas State Technical College DISCOVER! 1.For each portion of a composite primary key, identify all the partially dependent fields. Find all the fields that are partially dependent upon the same key field. 2.If the key field is also a foreign key, synchronize the two tables and remove the partially dependent fields. Guarantee that the fields and their information are in the parent table, then remove them from the child table. 3.If the key field is not a foreign key, make it one and remove the partially dependent fields. Create a table for the object, move the partially dependent fields and data to the new table, and remove them from the child table. 4.Repeat the process until database is 2NF. The database is 2NF when all tables in the database are 2NF. Converting to 2NF Second Normal Form (2NF)
12
Texas State Technical College DISCOVER! Step One: Identify partially dependent fields. SSN has no partially dependent fields.SSN has no partially dependent fields. VIN has two partially dependent fields.VIN has two partially dependent fields. MfgMfg MakeMake Registered has no partially dependent fields.Registered has no partially dependent fields. For Example… [ DMV ] Registration SSN pk/fk VIN pk/fk Registered pk ExpiresCountyMfgMake Text Date Text Problem: Partial dependencies upon the primary key. Second Normal Form (2NF)
13
Texas State Technical College DISCOVER! Step Two: Move partially dependent fields. In this case, we guarantee that there is a vehicle table that contains Mfg and Make.In this case, we guarantee that there is a vehicle table that contains Mfg and Make. If not, we create the table and make VIN a foreign key linking the two.If not, we create the table and make VIN a foreign key linking the two. For Example… [ DMV ] Registration SSN pk/fk VIN pk/fk Registered pk ExpiresCounty Text Date Text Vehicle VIN pk MfgMake Text FIXED: The table is now 2NF! Second Normal Form (2NF)
14
Texas State Technical College DISCOVER! In Summary… Second normal form (2NF) dictates that all fields in a table must be wholly related to the primary key.Second normal form (2NF) dictates that all fields in a table must be wholly related to the primary key. A table must be 1NF before it can be 2NF.A table must be 1NF before it can be 2NF. Tables that are 1NF and do not use composite primary keys are automatically 2NF.Tables that are 1NF and do not use composite primary keys are automatically 2NF. Second Normal Form (2NF)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.