3. Normalization
Activity 3.01: Building a Relationship between the Orders and the OrderItems table
Solution:
- Create the
OrderItems
table:Use packt_online_shop; CREATE TABLE OrderItems ( OrderItemID INT NOT NULL AUTO_INCREMENT, OrderID INT NOT NULL, ProductID INT NOT NULL, Quantity INT NOT NULL, UnitPrice DECIMAL(10, 2) NOT NULL, Discount DECIMAL(10, 2) NULL, Notes VARCHAR(750) NULL, PRIMARY KEY (OrderItemID) );
- Create the
Orders
(child) table:Create Table Orders( OrderID INT NOT NULL AUTO_INCREMENT, CustomerID INT NOT NULL, OrderNumber CHAR(50) NOT NULL, OrderDate DATETIME NOT NULL, ShipmentDate DATETIME NULL, OrderStatus CHAR(10) NULL...