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...