CS103_ Databases_ Normalizing a Database Cheatsheet _ Codecademy
CS103_ Databases_ Normalizing a Database Cheatsheet _ Codecademy
Normalizing a Database
Database Normalization
https://www.codecademy.com/learn/cspath-databases/modules/cspath-normalizing-a-database/cheatsheet 1/7
3/11/24, 11:35 AM CS103: Databases: Normalizing a Database Cheatsheet | Codecademy
Independent Columns
If the same information is stored in multiple locations in |order_id |price |cust_id |cust_email
a database table, a database manager needs to be
|
careful when updating the table. For example, in the
database table shown here, each customer’s email | ----- | -----| -------| -------------
address is stored in multiple rows. Therefore, in order - |
to update a customer email, multiple fields will need to
| 1 |20.43 | 1
be changed. Normalizing the table gets rid of
duplicated data and therefore makes data errors less |[email protected] |
likely. | 2 |51.33 | 1
|[email protected] |
| 3 |80.01 | 2
|[email protected] |
| 4 |33.27 | 2
|[email protected] |
https://www.codecademy.com/learn/cspath-databases/modules/cspath-normalizing-a-database/cheatsheet 2/7
3/11/24, 11:35 AM CS103: Databases: Normalizing a Database Cheatsheet | Codecademy
1NF Databases
A 1NF database is an atomic database. In this case, // This would be a non-atomic table
atomic means that each cell contains one value and
| Title | Length | Type |
each row is unique. In the given example, we can see
that the non-atomic table has cells with more than one |-----------------|------------|------|
value and non-unique rows. | Example A, B, C | 125 inches | B, C |
| Example A, B, C | 125 inches | B, C |
// This would be an atomic table
| ID | Title | Length | Type |
|----|-----------|------------|------|
| 1 | Example A | 125 inches | B |
| 2 | Example A | 125 inches | C |
https://www.codecademy.com/learn/cspath-databases/modules/cspath-normalizing-a-database/cheatsheet 3/7
3/11/24, 11:35 AM CS103: Databases: Normalizing a Database Cheatsheet | Codecademy
A 2NF Database
When a database is said to be 2NF, that means the // A 1NF Database with partial
database is both 1NF and contains no partial
dependencies
dependencies. A partial dependency is when an
attribute depends partly on the table’s primary key. | ID | Name | Address ID | Address
|
|----|---------|------------|------------
-----------|
| 1 | Logan | 1 | 7777 Willow
Drive |
| 2 | Charlie | 2 | 8888 Blue
Bonnet Road |
| 3 | Johanna | 1 | 7777 Willow
Drive |
// A 2NF database
*Name.db
| ID | Name | Address ID |
|----|---------|------------|
| 1 | Logan | 1 |
| 2 | Charlie | 2 |
| 3 | Johanna | 1 |
*Address.db
| Address ID | Address |
|------------|-----------------------|
| 1 | 7777 Willow Drive |
| 2 | 8888 Blue Bonnet Road |
https://www.codecademy.com/learn/cspath-databases/modules/cspath-normalizing-a-database/cheatsheet 4/7
3/11/24, 11:35 AM CS103: Databases: Normalizing a Database Cheatsheet | Codecademy
A 3NF database
When making a 3NF database, two goals need to be // A 2NF database with transitive
accomplished. The first being that the database is
functional dependency.
already 2NF, and the second being that the database
contains no transitive functional dependencies. A | ID | Name | Address |
transitive functional dependency is when a non-prime |----|---------|-----------------------|
attribute is dependent on another non-prime attribute.
| 1 | Logan | 7777 Willow Drive |
| 2 | Charlie | 4444 Blue Bonnet Road |
| 4 | Hannah | 4444 Blue Bonnet Road |
// A 3NF database with no transitive
functional dependencies.
*name.db
| ID | Name | Address ID |
|----|---------|------------|
| 1 | Logan | 1 |
| 2 | Charlie | 2 |
| 4 | Hannah | 2 |
*Address.db
| Address ID | Address |
|------------|-----------------------|
| 1 | 7777 Willow Drive |
| 2 | 4444 Blue Bonnet Road |
https://www.codecademy.com/learn/cspath-databases/modules/cspath-normalizing-a-database/cheatsheet 5/7
3/11/24, 11:35 AM CS103: Databases: Normalizing a Database Cheatsheet | Codecademy
Update Anomalies
Insertion Anomalies
https://www.codecademy.com/learn/cspath-databases/modules/cspath-normalizing-a-database/cheatsheet 6/7
3/11/24, 11:35 AM CS103: Databases: Normalizing a Database Cheatsheet | Codecademy
Deletion Anomalies
Print Share
https://www.codecademy.com/learn/cspath-databases/modules/cspath-normalizing-a-database/cheatsheet 7/7