Struggling with 3NF in E-commerce Database Project
Hi everyone,
I'm working on a project for my Database Management course and I've hit a wall with normalizing one of my main tables. I'd really appreciate some advice on the best way to structure it.
The project is a simple e-commerce site. I started with a single `orders` table to track customer orders and the products within them, but I know it's not designed correctly and violates normalization rules.
Right now, my table looks something like this:
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
customer_name VARCHAR(100),
order_date DATE,
product_id_1 INT,
product_name_1 VARCHAR(100),
product_quantity_1 INT,
product_id_2 INT,
product_name_2 VARCHAR(100),
product_quantity_2 INT
-- and so on for more products...
);
I know this violates First Normal Form (1NF) because of the repeating groups for products. I also have a transitive dependency, since `customer_name` depends on `customer_id`, which is not the primary key.
I believe I need to break this down into multiple tables: `Customers`, `Products`, `Orders`, and a linking table like `Order_Items`.
My main question is: Is creating an `Order_Items` table with columns like `(order_item_id, order_id, product_id, quantity)` the standard and best way to achieve Third Normal Form (3NF) in this situation? Am I missing any potential issues with that approach?
Any guidance or examples would be a huge help!
Thanks in advance.