From 973ba836853701984a6140a9746f963cadc9d206 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:13:12 +0000 Subject: [PATCH 1/2] Setting up GitHub Classroom Feedback From ba897b548802b0aa303f37a5637a77cc0b0084d8 Mon Sep 17 00:00:00 2001 From: sadman-nasif <127980450+sadman-nasif@users.noreply.github.com> Date: Thu, 6 Jul 2023 00:20:30 +0600 Subject: [PATCH 2/2] Add files via upload Sorry for the delay sir. I was sick during the time of the instruction of uploading the files. Later on, I did not even know you asked us to upload, until right now. Upon knowing this, I uploaded right away. Pardon the delay sir. --- 1907120/DDL.sql | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1907120/DML.sql | 54 +++++++++++++++++++++++++++++++++++++ 1907120/PL_SQL.sql | 33 +++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 1907120/DDL.sql create mode 100644 1907120/DML.sql create mode 100644 1907120/PL_SQL.sql diff --git a/1907120/DDL.sql b/1907120/DDL.sql new file mode 100644 index 0000000..5c80181 --- /dev/null +++ b/1907120/DDL.sql @@ -0,0 +1,67 @@ +drop TABLE OrderDetails; +drop table Orders; + +drop TABLE Inventory; +drop table Customers; +drop table Products; + + +-- Create the Products table +CREATE TABLE Products ( + ProductID INT PRIMARY KEY, + ProductName VARCHAR(25), + ProductDescription VARCHAR(25), + ProductCategory VARCHAR(25), + ProductPrice DECIMAL(10, 2), + ProductImage VARCHAR(25), + QuantityInStock INT, + ReorderThreshold INT +); + +-- Create the Customers table +CREATE TABLE Customers ( + CustomerID INT PRIMARY KEY, + FirstName VARCHAR(25), + LastName VARCHAR(25), + EmailAddress VARCHAR(25), + PhoneNumber VARCHAR(20), + ShippingAddress VARCHAR(25), + BillingAddress VARCHAR(25) +); + +-- Create the Orders table +CREATE TABLE Orders ( + OrderID INT PRIMARY KEY, + CustomerID INT, + OrderDate DATE, + OrderTotal DECIMAL(10, 2), + FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID) +); + +-- Create the OrderDetails table +CREATE TABLE OrderDetails ( + OrderDetailID INT PRIMARY KEY, + OrderID INT, + ProductID INT, + Quantity INT, + Price DECIMAL(10, 2), + FOREIGN KEY (OrderID) REFERENCES Orders(OrderID), + FOREIGN KEY (ProductID) REFERENCES Products(ProductID) +); + +-- Create the Inventory table +CREATE TABLE Inventory ( + ProductID INT, + WarehouseID INT, + QuantityInStock INT, + PRIMARY KEY (ProductID, WarehouseID), + FOREIGN KEY (ProductID) REFERENCES Products(ProductID) +); + + +select * from OrderDetails; +select * from Inventory; + +alter table Inventory add location char(20); +alter table Inventory modify location varchar(23); +alter table Inventory rename column location to location2; \ No newline at end of file diff --git a/1907120/DML.sql b/1907120/DML.sql new file mode 100644 index 0000000..ae74382 --- /dev/null +++ b/1907120/DML.sql @@ -0,0 +1,54 @@ +-- Insert data into the Products table +INSERT INTO Products VALUES (1, 'Product A', 'Description A', 'Category A', 9.99, 'image_a.jpg', 10, 5); +INSERT INTO Products VALUES (2, 'Product B', 'Description B', 'Category B', 19.99, 'image_b.jpg', 15, 8); +INSERT INTO Products VALUES (3, 'Product C', 'Description C', 'Category A', 14.99, 'image_c.jpg', 5, 2); +INSERT INTO Products VALUES (4, 'Product D', 'Description D', 'Category C', 24.99, 'image_d.jpg', 20, 10); +INSERT INTO Products VALUES (5, 'Product E', 'Description E', 'Category B', 12.99, 'image_e.jpg', 12, 6); + +-- Insert data into the Customers table +INSERT INTO Customers VALUES (1, 'John', 'Doe', 'john@example.com', '1234567890', '123 Shipping St', '123 Billing St'); +INSERT INTO Customers VALUES (2, 'Jane', 'Smith', 'jane@example.com', '9876543210', '456 Shipping St', '456 Billing St'); + INSERT INTO Customers VALUES (3, 'Michael', 'Johnson', 'michael@example.com', '5555555555', '789 Shipping St', '789 Billing St'); +INSERT INTO Customers VALUES (4, 'Emily', 'Brown', 'emily@example.com', '1111111111', '987 Shipping St', '987 Billing St'); + INSERT INTO Customers VALUES (5, 'David', 'Davis', 'david@example.com', '2222222222', '654 Shipping St', '654 Billing St'); + +-- Insert data into the Orders table +INSERT INTO Orders VALUES (1, 1,TO_DATE('2023-03-10', 'YYYY-MM-DD'), 29.99); +INSERT INTO Orders VALUES (2, 2,TO_DATE('2023-01-02', 'YYYY-MM-DD'), 45.99); + INSERT INTO Orders VALUES (3, 3,TO_DATE('2023-04-20', 'YYYY-MM-DD'), 19.99); + INSERT INTO Orders VALUES (4, 4, TO_DATE('2023-03-13', 'YYYY-MM-DD'), 32.99); + INSERT INTO Orders VALUES (5, 5, TO_DATE('2023-03-10', 'YYYY-MM-DD'), 27.99); + +-- Insert data into the OrderDetails table +INSERT INTO OrderDetails VALUES (1, 1, 1, 2, 9.99); +INSERT INTO OrderDetails VALUES (2, 1, 3, 1, 14.99); +INSERT INTO OrderDetails VALUES (3, 2, 2, 3, 19.99); + INSERT INTO OrderDetails VALUES (4, 3, 5, 1, 12.99); + INSERT INTO OrderDetails VALUES (5, 4, 4, 2, 24.99); + +-- Insert data into the Inventory table +INSERT INTO Inventory VALUES (1, 1, 8, 'Dhaka'); + +INSERT INTO Inventory VALUES (2, 1, 12, 'Chittagong'); + + INSERT INTO Inventory VALUES (3, 1, 5, 'rajshahi'); + + INSERT INTO Inventory VALUES (4, 1, 18, 'Khulna'); + + INSERT INTO Inventory VALUES (5, 1, 10, 'Barisal'); + + +--join +SELECT i.ProductID, p.ProductName, i.QuantityInStock +FROM Inventory i +JOIN Products p ON i.ProductID = p.ProductID; + +--aggregation +SELECT ProductID, SUM(QuantityInStock) AS TotalQuantity +FROM Inventory +GROUP BY ProductID; + +--retrieve the total quantity of a product in stock: +SELECT ProductID, SUM(QuantityInStock) AS TotalQuantity +FROM Inventory +GROUP BY ProductID; diff --git a/1907120/PL_SQL.sql b/1907120/PL_SQL.sql new file mode 100644 index 0000000..a7f8c62 --- /dev/null +++ b/1907120/PL_SQL.sql @@ -0,0 +1,33 @@ +-- Create a PL/SQL block +set serveroutput on +DECLARE + -- Declare a cursor + CURSOR product_cursor IS + SELECT ProductID, ProductName, ProductPrice + FROM Products; + + -- Declare variables to store cursor data + product_id Products.ProductID%TYPE; + product_name Products.ProductName%TYPE; + product_price Products.ProductPrice%TYPE; +BEGIN + -- Open the cursor + OPEN product_cursor; + + -- Fetch data from the cursor + LOOP + FETCH product_cursor INTO product_id, product_name, product_price; + EXIT WHEN product_cursor%NOTFOUND; + + -- Perform some operations with the fetched data + -- For example, print the product details + DBMS_OUTPUT.PUT_LINE('Product ID: ' || product_id); + DBMS_OUTPUT.PUT_LINE('Product Name: ' || product_name); + DBMS_OUTPUT.PUT_LINE('Product Price: ' || product_price); + DBMS_OUTPUT.PUT_LINE('-------------------'); + END LOOP; + + -- Close the cursor + CLOSE product_cursor; +END; +/