diff --git a/.DS_Store b/.DS_Store index 11a3b81cd9d26bf9a1ff7ebf46ee3ff457d54f07..0a39fe1d3f7f425635bfd8949cd8295ff66eb186 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/sqlScript/databaseCreation.sql b/sqlScript/databaseCreation.sql new file mode 100644 index 0000000000000000000000000000000000000000..05bf0048518de326ef50f89cd288647534ae7c7e --- /dev/null +++ b/sqlScript/databaseCreation.sql @@ -0,0 +1,249 @@ +-- Database creation for each entity + +-- User Table Creation +CREATE TABLE `User` ( + `UserID` int(11) NOT NULL, + `Username` varchar(50) NOT NULL, + `Password` varchar(50) NOT NULL, + `Email` varchar(75) NOT NULL, + `FirstName` varchar(255) DEFAULT NULL, + `LastName` varchar(255) DEFAULT NULL, + `ProfilePicURL` varchar(255) DEFAULT NULL, + `DateOfBirth` date DEFAULT NULL, + `LastLogin` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- User Table Modifications +ALTER TABLE `User` +ADD PRIMARY KEY (`UserID`), +ADD UNIQUE KEY `Username` (`Username`), +ADD UNIQUE KEY `Email` (`Email`); +ALTER TABLE `User` +MODIFY `UserID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- Address Table Creation +CREATE TABLE `Address` ( + `AddressID` int(11) NOT NULL, + `UserID` int(11) DEFAULT NULL, + `Street` varchar(255) DEFAULT NULL, + `City` varchar(100) DEFAULT NULL, + `State` varchar(100) DEFAULT NULL, + `PostalCode` varchar(20) DEFAULT NULL, + `Country` varchar(100) DEFAULT NULL, + `IsDefault` tinyint(1) NOT NULL DEFAULT 0, + `AddressType` enum('Shipping','Billing','Other') DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Address Table Modifications +ALTER TABLE `Address` +ADD PRIMARY KEY (`AddressID`), +ADD KEY `fk_user_address` (`UserID`); +ALTER TABLE `Address` +ADD CONSTRAINT `fk_user_address` FOREIGN KEY (`UserID`) REFERENCES `User` (`UserID`); +ALTER TABLE `Address` +MODIFY `AddressID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- Product Table Creation +CREATE TABLE `Product` ( + `ProductID` int(11) NOT NULL, + `Name` varchar(75) DEFAULT NULL, + `Description` text DEFAULT NULL, + `Price` decimal(10,2) DEFAULT NULL, + `StockQuantity` int(11) DEFAULT NULL, + `BrandID` int(11) DEFAULT NULL, + `CategoryID` int(11) DEFAULT NULL, + `ImageURL` varchar(225) DEFAULT NULL, + `SKU` varchar(255) NOT NULL, + `Weight` decimal(5,2) DEFAULT NULL, + `Dimensions` varchar(225) DEFAULT NULL, + `IsActive` tinyint(1) NOT NULL DEFAULT 1 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Product Table Modifications +ALTER TABLE `Product` +ADD PRIMARY KEY (`ProductID`), +ADD UNIQUE KEY `SKU` (`SKU`), +ADD KEY `BrandID` (`BrandID`), +ADD KEY `CategoryID` (`CategoryID`); +ALTER TABLE `Product` +ADD CONSTRAINT `product_ibfk_1` FOREIGN KEY (`BrandID`) REFERENCES `Brand` (`BrandID`), +ADD CONSTRAINT `product_ibfk_2` FOREIGN KEY (`CategoryID`) REFERENCES `Category` (`CategoryID`); +ALTER TABLE `Product` +MODIFY `ProductID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13; + +-- Brand Table Creation +CREATE TABLE `Brand` ( + `BrandID` int(11) NOT NULL, + `Name` varchar(75) NOT NULL, + `Description` text DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Brand Table Modifications +ALTER TABLE `Brand` +ADD PRIMARY KEY (`BrandID`); +ALTER TABLE `Brand` +MODIFY `BrandID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; + +-- Category Table Creation +CREATE TABLE `Category` ( + `CategoryID` int(11) NOT NULL, + `Name` varchar(75) DEFAULT NULL, + `Description` text DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Category Table Modifications +ALTER TABLE `Category` +ADD PRIMARY KEY (`CategoryID`); +ALTER TABLE `Category` +MODIFY `CategoryID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; + +-- Order Table Creation +CREATE TABLE `Order` ( + `OrderID` int(11) NOT NULL, + `UserID` int(11) DEFAULT NULL, + `OrderDate` date NOT NULL, + `TotalAmount` decimal(10,2) NOT NULL, + `OrderStatusID` int(11) DEFAULT NULL, + `PaymentConfirmedDate` date DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Order Table Modifications +ALTER TABLE `Order` +ADD PRIMARY KEY (`OrderID`), +ADD KEY `fk_order_user` (`UserID`), +ADD KEY `fk_order_orderstatus` (`OrderStatusID`); +ALTER TABLE `Order` +ADD CONSTRAINT `fk_order_user` FOREIGN KEY (`UserID`) REFERENCES `User` (`UserID`), +ADD CONSTRAINT `fk_order_orderstatus` FOREIGN KEY (`OrderStatusID`) REFERENCES `OrderStatus` (`OrderStatusID`); +ALTER TABLE `Order` +MODIFY `OrderID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- OrderItem Table Creation +CREATE TABLE `OrderItem` ( + `OrderID` int(11) NOT NULL, + `ProductID` int(11) NOT NULL, + `Quantity` int(11) NOT NULL, + `Subtotal` decimal(10,2) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- OrderItem Table Modifications +ALTER TABLE `OrderItem` +ADD PRIMARY KEY (`OrderID`,`ProductID`), +ADD KEY `fk_orderitem_product` (`ProductID`); +ALTER TABLE `OrderItem` +ADD CONSTRAINT `fk_orderitem_order` FOREIGN KEY (`OrderID`) REFERENCES `Order` (`OrderID`), +ADD CONSTRAINT `fk_orderitem_product` FOREIGN KEY (`ProductID`) REFERENCES `Product` (`ProductID`); + +-- OrderStatus Table Creation +CREATE TABLE `OrderStatus` ( + `OrderStatusID` int(11) NOT NULL, + `StatusName` varchar(255) NOT NULL, + `Description` text DEFAULT NULL, + `CreatedAt` datetime DEFAULT current_timestamp(), + `UpdatedAt` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp() +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- OrderStatus Table Modifications +ALTER TABLE `OrderStatus` +ADD PRIMARY KEY (`OrderStatusID`); +ALTER TABLE `OrderStatus` +MODIFY `OrderStatusID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; + +-- Payment Table Creation +CREATE TABLE `Payment` ( + `PaymentID` int(11) NOT NULL, + `OrderID` int(11) DEFAULT NULL, + `PaymentMethod` varchar(255) NOT NULL, + `Amount` decimal(10,2) NOT NULL, + `PaymentDate` date NOT NULL, + `PaymentStatusID` int(11) DEFAULT NULL, + `TransactionID` varchar(225) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Payment Table Modifications +ALTER TABLE `Payment` +ADD PRIMARY KEY (`PaymentID`), +ADD KEY `fk_payment_order` (`OrderID`), +ADD KEY `fk_payment_status` (`PaymentStatusID`); +ALTER TABLE `Payment` +ADD CONSTRAINT `fk_payment_order` FOREIGN KEY (`OrderID`) REFERENCES `Order` (`OrderID`), +ADD CONSTRAINT `fk_payment_status` FOREIGN KEY (`PaymentStatusID`) REFERENCES `PaymentStatus` (`PaymentStatusID`); +ALTER TABLE `Payment` +MODIFY `PaymentID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- PaymentStatus Table Creation +CREATE TABLE `PaymentStatus` ( + `PaymentStatusID` int(11) NOT NULL, + `StatusName` varchar(75) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- PaymentStatus Table Modifications +ALTER TABLE `PaymentStatus` +ADD PRIMARY KEY (`PaymentStatusID`); +ALTER TABLE `PaymentStatus` +MODIFY `PaymentStatusID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; + +-- ShippingDetail Table Creation +CREATE TABLE `ShippingDetail` ( + `ShippingID` int(11) NOT NULL, + `OrderID` int(11) DEFAULT NULL, + `RecipientName` varchar(255) DEFAULT NULL, + `AddressID` int(11) DEFAULT NULL, + `ShippingMethod` varchar(100) DEFAULT NULL, + `ShippingCost` decimal(10,2) NOT NULL, + `ExpectedDeliveryDate` date DEFAULT NULL, + `TrackingNumber` varchar(255) DEFAULT NULL, + `IsDelivered` tinyint(1) NOT NULL DEFAULT 0, + `DeliveryDate` date DEFAULT NULL, + `BaseCost` decimal(10,2) DEFAULT NULL, + `WeightSurcharge` decimal(10,2) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- ShippingDetail Table Modifications +ALTER TABLE `ShippingDetail` +ADD PRIMARY KEY (`ShippingID`), +ADD KEY `fk_shipping_order` (`OrderID`), +ADD KEY `fk_shipping_address` (`AddressID`); +ALTER TABLE `ShippingDetail` +ADD CONSTRAINT `fk_shipping_order` FOREIGN KEY (`OrderID`) REFERENCES `Order` (`OrderID`), +ADD CONSTRAINT `fk_shipping_address` FOREIGN KEY (`AddressID`) REFERENCES `Address` (`AddressID`); +ALTER TABLE `ShippingDetail` +MODIFY `ShippingID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- Taxes Table Creation +CREATE TABLE `Taxes` ( + `TaxID` int(11) NOT NULL, + `Description` text DEFAULT NULL, + `TaxPercent` decimal(5,2) DEFAULT NULL, + `ApplicableToCategoryID` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Taxes Table Modifications +ALTER TABLE `Taxes` +ADD PRIMARY KEY (`TaxID`), +ADD KEY `ApplicableToCategoryID` (`ApplicableToCategoryID`); +ALTER TABLE `Taxes` +ADD CONSTRAINT `taxes_ibfk_1` FOREIGN KEY (`ApplicableToCategoryID`) REFERENCES `Category` (`CategoryID`); +ALTER TABLE `Taxes` +MODIFY `TaxID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; + +-- Wishlist Table Creation +CREATE TABLE `Wishlist` ( + `WishlistID` int(11) NOT NULL, + `UserID` int(11) NOT NULL, + `ProductID` int(11) NOT NULL, + `AddedDate` date DEFAULT NULL, + `Name` varchar(75) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_danish_ci; + +-- Wishlist Table Modifications +ALTER TABLE `Wishlist` +ADD PRIMARY KEY (`WishlistID`, `UserID`, `ProductID`), +ADD KEY `fk_wishlist_user` (`UserID`), +ADD KEY `fk_wishlist_product` (`ProductID`); +ALTER TABLE `Wishlist` +ADD CONSTRAINT `fk_wishlist_product` FOREIGN KEY (`ProductID`) REFERENCES `Product` (`ProductID`), +ADD CONSTRAINT `fk_wishlist_user` FOREIGN KEY (`UserID`) REFERENCES `User` (`UserID`); +ALTER TABLE `Wishlist` +MODIFY `WishlistID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + diff --git a/sqlScript/databasePopulation.sql b/sqlScript/databasePopulation.sql new file mode 100644 index 0000000000000000000000000000000000000000..4fb46dc6118e3a201813f4655e7ac2414f3d03e4 --- /dev/null +++ b/sqlScript/databasePopulation.sql @@ -0,0 +1,71 @@ +-- Populate the User table +INSERT INTO `User` (`UserID`, `Username`, `Password`, `Email`, `FirstName`, `LastName`, `ProfilePicURL`, `DateOfBirth`, `LastLogin`) VALUES +(1, 'aliceblue', 'hashed_password_123', 'alice.blue@example.com', 'Alice', 'Blue', 'https://example.com/aliceblue.png', '1990-06-01', '2024-04-14 10:58:22'), +(2, 'bobsmith', 'hashed_password_456', 'bob.smith@example.com', 'Bob', 'Smith', 'https://example.com/bobsmith.png', '1985-08-15', '2024-04-14 10:58:22'); + +-- Populate the Address table +INSERT INTO `Address` (`AddressID`, `UserID`, `Street`, `City`, `State`, `PostalCode`, `Country`, `IsDefault`, `AddressType`) VALUES +(1, 1, 'Karl Johans gate 23', 'Oslo', 'Oslo', '0162', 'Norway', 1, 'Shipping'), +(2, 2, 'Nedre Bakklandet 58', 'Trondheim', 'Trøndelag', '7014', 'Norway', 1, 'Billing'); + +-- Populate the Product table +INSERT INTO `Product` (`ProductID`, `Name`, `Description`, `Price`, `StockQuantity`, `BrandID`, `CategoryID`, `ImageURL`, `SKU`, `Weight`, `Dimensions`, `IsActive`) VALUES +(1, 'Samsung Galaxy S21', 'High-end smartphone with advanced photography features.', 799.99, 150, 1, 1, 'https://example.com/galaxys21.png', 'SKU9001', 0.17, '151.7 x 71.2 x 7.9 mm', 1), +(2, 'iPhone 13', 'Latest model with A15 Bionic chip and advanced dual-camera system.', 899.99, 100, 2, 1, 'https://example.com/iphone13.png', 'SKU9002', 0.17, '146.7 x 71.5 x 7.65 mm', 1); + +-- Populate the Brand table +INSERT INTO `Brand` (`BrandID`, `Name`, `Description`) VALUES +(1, 'Samsung', 'South Korean multinational electronics company known for its smartphones and consumer electronics.'), +(2, 'Apple', 'American multinational technology company known for its innovative consumer electronics.'); + +-- Populate the Category table +INSERT INTO `Category` (`CategoryID`, `Name`, `Description`) VALUES +(1, 'Smartphones', 'Mobile phones with advanced features and functionalities.'), +(2, 'Laptops', 'Portable personal computers suitable for mobile use.'); + +-- Populate the Order table +INSERT INTO `Order` (`OrderID`, `UserID`, `OrderDate`, `TotalAmount`, `OrderStatusID`, `PaymentConfirmedDate`) VALUES +(1, 1, '2023-10-01', 1299.99, 1, '2023-10-01'), +(2, 2, '2023-10-02', 349.99, 2, '2023-10-02'); + +-- Populate the OrderItem table +INSERT INTO `OrderItem` (`OrderID`, `ProductID`, `Quantity`, `Subtotal`) VALUES +(1, 1, 1, 1299.99), +(2, 2, 1, 899.99); + +-- Populate the OrderStatus table +INSERT INTO `OrderStatus` (`OrderStatusID`, `StatusName`, `Description`, `CreatedAt`, `UpdatedAt`) VALUES +(1, 'Placed', 'Order has been placed and is awaiting processing.', '2024-04-14 13:00:03', '2024-04-14 13:00:03'), +(2, 'Shipped', 'Order has been shipped to the customer.', '2024-04-14 13:00:03', '2024-04-14 13:00:03'), +(3, 'Delivered', 'Order has been delivered.', '2024-04-14 13:00:03', '2024-04-14 13:00:03'); + +-- Populate the Payment table +INSERT INTO `Payment` (`PaymentID`, `OrderID`, `PaymentMethod`, `Amount`, `PaymentDate`, `PaymentStatusID`, `TransactionID`) VALUES +(1, 1, 'Credit Card', 1299.99, '2023-10-01', 1, 'TX100001'), +(2, 2, 'PayPal', 349.99, '2023-10-02', 1, 'TX100002'); + +-- Populate the PaymentStatus table +INSERT INTO `PaymentStatus` (`PaymentStatusID`, `StatusName`) VALUES +(1, 'Completed'), +(2, 'Pending'), +(3, 'Refunded'); + +-- Populate the ShippingDetail table +INSERT INTO `ShippingDetail` (`ShippingID`, `OrderID`, `RecipientName`, `AddressID`, `ShippingMethod`, `ShippingCost`, `ExpectedDeliveryDate`, `TrackingNumber`, `IsDelivered`, `DeliveryDate`, `BaseCost`, `WeightSurcharge`) VALUES +(1, 1, 'Alice Blue', 1, 'FedEx', 10.00, '2023-10-05', 'TRACK1001', 0, NULL, 10.00, 2.00), +(2, 2, 'Bob Smith', 2, 'UPS', 5.00, '2023-10-04', 'TRACK1002', 1, '2023-10-04', 5.00, 0.50); + +-- Populate the Taxes table +INSERT INTO `Taxes` (`TaxID`, `Description`, `TaxPercent`, `ApplicableToCategoryID`) VALUES +(1, 'Standard Electronics Tax', 15.00, 1), +(2, 'Luxury Electronics Tax', 20.00, 2), +(3, 'Reduced Tax for Tablets', 5.00, 3), +(4, 'Camera Tax', 18.00, 4), +(5, 'Home Appliance Tax', 10.00, 5), +(6, 'Accessory Tax', 12.00, 6); + +-- Populate the Wishlist table +INSERT INTO `Wishlist` (`WishlistID`, `UserID`, `ProductID`, `AddedDate`, `Name`) VALUES +(1, 1, 1, '2023-10-05', 'Holiday Gifts'), +(1, 1, 2, '2023-10-05', 'Holiday Gifts'), +(2, 2, 3, '2023-10-05', 'Birthday Wishlist'); diff --git a/sqlScript/databaseSampleQueries.sql b/sqlScript/databaseSampleQueries.sql new file mode 100644 index 0000000000000000000000000000000000000000..8cab17b0ce65d9abe430a809a55500636e40a72f --- /dev/null +++ b/sqlScript/databaseSampleQueries.sql @@ -0,0 +1,132 @@ +-- SQL CRUD Operations for each entity in the database + +-- CRUD Operations for User Table +-- Select Users who logged in after January 1, 2024 +SELECT * FROM `User` WHERE `LastLogin` > '2024-01-01'; +-- Insert a new user into the User table +INSERT INTO `User` (`Username`, `Password`, `Email`, `FirstName`, `LastName`, `DateOfBirth`) VALUES ('newuser', 'password123', 'new.user@example.com', 'New', 'User', '1992-02-02'); +-- Update the email address of the user with UserID = 1 +UPDATE `User` SET `Email` = 'updated.email@example.com' WHERE `UserID` = 1; +-- Delete the user with UserID = 2 +DELETE FROM `User` WHERE `UserID` = 2; + +-- CRUD Operations for Address Table +-- Select all addresses in Norway +SELECT * FROM `Address` WHERE `Country` = 'Norway'; +-- Insert a new shipping address for the user with ID 3 +INSERT INTO `Address` (`UserID`, `Street`, `City`, `State`, `PostalCode`, `Country`, `IsDefault`, `AddressType`) VALUES (3, 'Bogstadveien 30', 'Oslo', 'Oslo', '0355', 'Norway', 1, 'Shipping'); +-- Change the default status of the address for UserID 1 +UPDATE `Address` SET `IsDefault` = 0 WHERE `AddressID` = 1 AND `UserID` = 1; +-- Delete the address with AddressID = 3 +DELETE FROM `Address` WHERE `AddressID` = 3; + +-- CRUD Operations for Product Table +-- Select all products associated with BrandID 2 (Apple) +SELECT * FROM `Product` WHERE `BrandID` = 2; +-- Insert a new product, Google Nest Hub +INSERT INTO `Product` (`Name`, `Description`, `Price`, `StockQuantity`, `BrandID`, `CategoryID`, `SKU`, `IsActive`) VALUES ('Google Nest Hub', 'Smart display with Google Assistant.', 89.99, 200, 1, 1, 'SKU9015', 1); +-- Update the price of the product with ProductID = 10 +UPDATE `Product` SET `Price` = 99.99 WHERE `ProductID` = 10; +-- Delete the product with ProductID = 5 +DELETE FROM `Product` WHERE `ProductID` = 5; + +-- CRUD Operations for Brand Table +-- Select all brands with IDs from 1 to 3 +SELECT * FROM `Brand` WHERE `BrandID` BETWEEN 1 AND 3; +-- Insert a new brand, Asus +INSERT INTO `Brand` (`Name`, `Description`) VALUES ('Asus', 'Taiwanese multinational computer and phone hardware and electronics company.'); +-- Update the description for the brand with BrandID = 7 +UPDATE `Brand` SET `Description` = 'Updated brand description here' WHERE `BrandID` = 7; +-- Delete the brand with BrandID = 6 +DELETE FROM `Brand` WHERE `BrandID` = 6; + +-- CRUD Operations for Category Table +-- Select all categories in the database +SELECT * FROM `Category`; +-- Insert a new category for printers +INSERT INTO `Category` (`Name`, `Description`) VALUES ('Printers', 'Devices that produce a hard copy by transferring ink onto paper.'); +-- Update the description of the category with CategoryID = 4 +UPDATE `Category` SET `Description` = 'Updated category description' WHERE `CategoryID` = 4; +-- Delete the category with CategoryID = 3 +DELETE FROM `Category` WHERE `CategoryID` = 3; + +-- CRUD Operations for Order Table +-- Select orders where the total amount is greater than $1000 +SELECT * FROM `Order` WHERE `TotalAmount` > 1000; +-- Insert a new order with details including userID, order date, total amount, and status ID +INSERT INTO `Order` (`UserID`, `OrderDate`, `TotalAmount`, `OrderStatusID`) VALUES (2, '2024-04-25', 1200.50, 3); +-- Change the order status of the order with OrderID = 1 to 'Shipped' +UPDATE `Order` SET `OrderStatusID` = 2 WHERE `OrderID` = 1; +-- Delete the order with OrderID = 3 +DELETE FROM `Order` WHERE `OrderID` = 3; + +-- CRUD Operations for OrderItem Table +-- Select all items associated with OrderID 1 +SELECT * FROM `OrderItem` WHERE `OrderID` = 1; +-- Insert two units of product ID 7 to order ID 1 with a subtotal +INSERT INTO `OrderItem` (`OrderID`, `ProductID`, `Quantity`, `Subtotal`) VALUES (1, 7, 2, 3999.98); +-- Update the quantity and subtotal for product ID 7 in order ID 1 +UPDATE `OrderItem` SET `Quantity` = 3, `Subtotal` = 5999.97 WHERE `OrderID` = 1 AND `ProductID` = 7; +-- Delete the order item entry for product ID 11 from order ID 2 +DELETE FROM `OrderItem` WHERE `OrderID` = 2 AND `ProductID` = 11; + +-- CRUD Operations for OrderStatus Table +-- Select details for the order status with ID 1 (typically "Placed") +SELECT * FROM `OrderStatus` WHERE `OrderStatusID` = 1; +-- Insert a new order status called "Processing" with a description +INSERT INTO `OrderStatus` (`StatusName`, `Description`) VALUES ('Processing', 'Order is being processed.'); +-- Update the description for the order status with ID 2 +UPDATE `OrderStatus` SET `Description` = 'Order has been shipped and is en route to the customer.' WHERE `OrderStatusID` = 2; +-- Delete the order status with ID 3 +DELETE FROM `OrderStatus` WHERE `OrderStatusID` = 3; + +-- CRUD Operations for Payment Table +-- Select all payments made using a Credit Card +SELECT * FROM `Payment` WHERE `PaymentMethod` = 'Credit Card'; +-- Insert a new payment record for order ID 2 using a Debit Card +INSERT INTO `Payment` (`OrderID`, `PaymentMethod`, `Amount`, `PaymentDate`, `PaymentStatusID`, `TransactionID`) VALUES (2, 'Debit Card', 120.50, '2024-04-15', 1, 'TX200003'); +-- Update the payment amount for the payment with PaymentID = 1 +UPDATE `Payment` SET `Amount` = 130.75 WHERE `PaymentID` = 1; +-- Delete the payment record with PaymentID = 2 +DELETE FROM `Payment` WHERE `PaymentID` = 2; + +-- CRUD Operations for PaymentStatus Table +-- Select details for the payment status with ID 1 (typically "Completed") +SELECT * FROM `PaymentStatus` WHERE `PaymentStatusID` = 1; +-- Insert a new payment status "Awaiting Confirmation" +INSERT INTO `PaymentStatus` (`StatusName`) VALUES ('Awaiting Confirmation'); +-- Change the status name of payment status ID 3 to "Failed" +UPDATE `PaymentStatus` SET `StatusName` = 'Failed' WHERE `PaymentStatusID` = 3; +-- Delete the payment status with ID 2 +DELETE FROM `PaymentStatus` WHERE `PaymentStatusID` = 2; + +-- CRUD Operations for ShippingDetail Table +-- Retrieve shipping details for order ID 1 +SELECT * FROM `ShippingDetail` WHERE `OrderID` = 1; +-- Add new shipping details for order ID 2 +INSERT INTO `ShippingDetail` (`OrderID`, `RecipientName`, `AddressID`, `ShippingMethod`, `ShippingCost`, `ExpectedDeliveryDate`, `TrackingNumber`) VALUES (2, 'Bob Brown', 2, 'DHL', 15.00, '2024-05-05', 'TRACK2002'); +-- Update the shipping record to mark it as delivered on April 25, 2024 +UPDATE `ShippingDetail` SET `IsDelivered` = 1, `DeliveryDate` = '2024-04-25' WHERE `ShippingID` = 1; +-- Delete the shipping detail record with ShippingID = 2 +DELETE FROM `ShippingDetail` WHERE `ShippingID` = 2; + +-- CRUD Operations for Taxes Table +-- Retrieve all tax entries where the tax percent is greater than 10% +SELECT * FROM `Taxes` WHERE `TaxPercent` > 10.00; +-- Add a new tax entry called "Environmental Tax" with a tax percentage of 8% +INSERT INTO `Taxes` (`Description`, `TaxPercent`, `ApplicableToCategoryID`) VALUES ('Environmental Tax', 8.00, 3); +-- Update the tax percentage to 19% for the tax entry with TaxID = 4 +UPDATE `Taxes` SET `TaxPercent` = 19.00 WHERE `TaxID` = 4; +-- Delete the tax entry with TaxID = 3 +DELETE FROM `Taxes` WHERE `TaxID` = 3; + +-- CRUD Operations for Wishlist Table +-- Retrieve all wishlist entries for userID 1 +SELECT * FROM `Wishlist` WHERE `UserID` = 1; +-- Add a new wishlist entry for userID 2 +INSERT INTO `Wishlist` (`UserID`, `ProductID`, `AddedDate`, `Name`) VALUES (2, 8, '2024-04-20', 'Tech Favorites'); +-- Update the name of the wishlist for userID 1 and wishlist ID 1 +UPDATE `Wishlist` SET `Name` = 'Updated Wishlist' WHERE `WishlistID` = 1 AND `UserID` = 1; +-- Delete the wishlist entry for userID 2 with wishlist ID 2 +DELETE FROM `Wishlist` WHERE `WishlistID` = 2 AND `UserID` = 2; +