Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions 1907120/DDL.sql
Original file line number Diff line number Diff line change
@@ -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;
54 changes: 54 additions & 0 deletions 1907120/DML.sql
Original file line number Diff line number Diff line change
@@ -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;
33 changes: 33 additions & 0 deletions 1907120/PL_SQL.sql
Original file line number Diff line number Diff line change
@@ -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;
/