Prevent insert anomaly in raw table
SQL
Hard
2 views
Problem Description
In raw InvoiceRaw(invoice_id, customer_name, customer_city, line_items). Show a normalized design that allows storing customer even without invoices.
Output Format
DDL statement(s)
Sample Test Case
Output:
Normalized tables
Constraints
Separate entity tables
Official Solution
CREATE TABLE Customers (customer_id INT PRIMARY KEY, name VARCHAR(100), city VARCHAR(100)); CREATE TABLE Invoices (invoice_id INT PRIMARY KEY, customer_id INT, invoice_date DATE, FOREIGN KEY(customer_id) REFERENCES Customers(customer_id)); CREATE TABLE InvoiceItems (invoice_id INT, product_id INT, qty INT, price DECIMAL(10,2), PRIMARY KEY(invoice_id, product_id));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!