Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Normalize to Third Normal Form
00:00
5 left

Normalize to Third Normal Form

HardSQL · PostgreSQL

Problem

Write queries to analyze data normalization levels and demonstrate converting an unnormalized transactional table into Third Normal Form (3NF).

Use the provided unnormalized_transactions relation and create a 3NF representation with separate customer, product, and sales relations. Also report whether the source satisfies 1NF, 2NF, and 3NF.

Output

  1. Return one row per normalization level with normalization_level, status, source_row_count, and normalized_relation_count.
  2. Include levels 1NF, 2NF, and 3NF in that order.
  3. Create the normalized relations and preserve every transaction.

Schema

unnormalized_transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
customer_idINTEGERCustomer identifier repeated in the source
customer_nameVARCHAR(100)Customer name
customer_emailVARCHAR(255)Customer email address
customer_addressVARCHAR(255)Customer shipping address
product_idINTEGERProduct identifier repeated in the source
product_nameVARCHAR(150)Product name
product_categoryVARCHAR(100)Product category
transaction_dateDATEDate of purchase
quantityINTEGERQuantity purchased
unit_priceNUMERIC(12,2)Price per unit at transaction time
customers
ColumnTypeDescription
customer_idPKINTEGERUnique customer identifier
customer_nameVARCHAR(100)Customer name
customer_emailVARCHAR(255)Customer email address
customer_addressVARCHAR(255)Customer shipping address
products
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(150)Product name
product_categoryVARCHAR(100)Product category
standard_priceNUMERIC(12,2)Product standard price
sales
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
customer_idINTEGERReferenced customer
product_idINTEGERReferenced product
transaction_dateDATEDate of purchase
quantityINTEGERQuantity purchased
unit_priceNUMERIC(12,2)Price per unit at transaction time
Tablesunnormalized_transactionscustomersproductssales
Interviewer

Your question is Normalize to Third Normal Form. Start with the requirements and the four tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.