0% found this document useful (0 votes)
6 views

Store Project.sql

Sql

Uploaded by

Jordan Samuelson
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Store Project.sql

Sql

Uploaded by

Jordan Samuelson
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

mysql> -- Create the database

Query OK, 0 rows affected (0.00 sec)

mysql> CREATE DATABASE ShopDB;Creates a database named 'ShopDB' for


storing tables.
Query OK, 1 row affected (0.03 sec)

mysql> USE ShopDB;-- Switches to the 'ShopDB' database.


Database changed
mysql>
mysql> -- Products Table
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE Products ( Defines a table to store product details such
as name, price, and stock.
-> product_id INT PRIMARY KEY AUTO_INCREMENT,
-> product_name VARCHAR(100) NOT NULL,
-> description TEXT,
-> price DECIMAL(10,2) NOT NULL,
-> stock_quantity INT NOT NULL
-> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> -- Customers Table
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE Customers ( Defines a table to store customer details


like name, email, and address
-> customer_id INT PRIMARY KEY AUTO_INCREMENT,
-> first_name VARCHAR(50) NOT NULL,
-> last_name VARCHAR(50) NOT NULL,
-> email VARCHAR(100) NOT NULL UNIQUE,
-> phone VARCHAR(20),
-> address VARCHAR(255)
-> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> -- Orders Table
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE Orders ( Defines a table to store customer orders with
total amount and order date.
-> order_id INT PRIMARY KEY AUTO_INCREMENT,
-> customer_id INT NOT NULL,
-> order_date DATE NOT NULL,
-> total_amount DECIMAL(10,2) NOT NULL,
-> FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)
-> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> -- OrderItems Table
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE OrderItems ( Defines a table to store individual items


within each order. order_item_id INT PRIMARY KEY AUTO_INCREMENT,
-> order_item_id INT PRIMARY KEY AUTO_INCREMENT,
-> order_id INT NOT NULL,
-> product_id INT NOT NULL,
-> quantity INT NOT NULL,
-> unit_price DECIMAL(10,2) NOT NULL,
-> FOREIGN KEY (order_id) REFERENCES Orders(order_id),
-> FOREIGN KEY (product_id) REFERENCES Products(product_id)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO Products (product_name, description, price, stock_quantity)


VALUES Adds test products to the 'Products' table.
-> ('Laptop', 'High-performance laptop', 1200.00, 15),
-> ('Smartphone', 'Latest smartphone model', 800.00, 30),
-> ('Headphones', 'Noise-cancelling headphones', 150.00, 50),
-> ('Monitor', '4K Ultra HD monitor', 400.00, 20),
-> ('Keyboard', 'Mechanical keyboard', 100.00, 40);
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> INSERT INTO Customers (first_name, last_name, email, phone, address)


VALUES Adds test customers to the 'Customers' table.
-> ('John', 'Doe', '[email protected]', '123-456-7890', '123 Main St'),
-> ('Jane', 'Smith', '[email protected]', '987-654-3210', '456 Elm St'),
-> ('Alice', 'Johnson', '[email protected]', '555-123-4567', '789 Oak
St');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> INSERT INTO Orders (customer_id, order_date, total_amount) VALUES Adds


test orders linked to customers in the 'Orders' table.
-> (1, '2024-12-01', 1550.00),
-> (1, '2024-12-02', 850.00),
-> (2, '2024-12-03', 1600.00),
-> (2, '2024-12-04', 1000.00),
-> (3, '2024-12-05', 1200.00),
-> (3, '2024-12-06', 750.00);
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> INSERT INTO OrderItems (order_id, product_id, quantity, unit_price) VALUES


Adds test items linked to orders in the 'OrderItems' table.
-> (1, 1, 1, 1200.00), -- Order 1: Laptop
-> (1, 3, 1, 150.00), -- Order 1: Headphones
-> (2, 2, 1, 800.00), -- Order 2: Smartphone
-> (3, 1, 1, 1200.00), -- Order 3: Laptop
-> (3, 4, 1, 400.00), -- Order 3: Monitor
-> (4, 5, 1, 100.00), -- Order 4: Keyboard
-> (5, 2, 1, 800.00), -- Order 5: Smartphone
-> (6, 3, 1, 150.00); -- Order 6: Headphones
Query OK, 8 rows affected (0.00 sec)
Records: 8 Duplicates: 0 Warnings: 0

You might also like