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

Message

The document contains SQL code to create tables for a database including customers, admins, products, inventory, categories, and suppliers. Data is inserted into these tables including customer information, admin logins, product listings with details, inventory levels by location, category types, and supplier contacts mapped to products. The tables are related through foreign keys and some updates are made to add additional fields. The database schema establishes the structure and initial data for an online storefront.

Uploaded by

Min Khant Kyaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Message

The document contains SQL code to create tables for a database including customers, admins, products, inventory, categories, and suppliers. Data is inserted into these tables including customer information, admin logins, product listings with details, inventory levels by location, category types, and supplier contacts mapped to products. The tables are related through foreign keys and some updates are made to add additional fields. The database schema establishes the structure and initial data for an online storefront.

Uploaded by

Min Khant Kyaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

CREATE TABLE customer (

customer_id INT NOT NULL,


name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
PRIMARY KEY (customer_id)
);

--data for customer table


INSERT INTO customer (customer_id, name, email, address, password)
VALUES (1, 'Alice Johnson', '[email protected]', '123 Main St, Anytown, USA',
'password123');

INSERT INTO customer (customer_id, name, email, address, password)


VALUES (2, 'Bob Smith', '[email protected]', '456 Oak Ave, Another town, USA',
'password456');

INSERT INTO customer (customer_id, name, email, address, password)


VALUES (3, 'Charlie Brown', '[email protected]', '789 Elm St, Somewhere, USA',
'password789');

CREATE TABLE admin (


admin_id INT NOT NULL ,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
PRIMARY KEY (admin_id)
);
--data for admin table
INSERT INTO admin (admin_id, name, email, password)
VALUES (1, 'John Smith', '[email protected]', 'password123');

INSERT INTO admin (admin_id, name, email, password)


VALUES (2, 'Jane Doe', '[email protected]', 'password456');

INSERT INTO admin (admin_id, name, email, password)


VALUES (3, 'Bob Johnson', '[email protected]', 'password789');

CREATE TABLE products (


product_id INT NOT NULL,
category_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
description VARCHAR(255) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
image_url VARCHAR(255) NOT NULL,
PRIMARY KEY (product_id),
FOREIGN KEY (Category_id) REFERENCES categories(category_id)
);
--data for products
INSERT INTO products (product_id, category_id, product_name, product_brand, price,
image_url)
VALUES (1, 3, 'Razer DeathAdder Elite Gaming Mouse', 'Razer', 69.99,
'https://example.com/mouse.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES (2, 2, 'RK Royal Kludge RK61 Wireless Gaming Keyboard', 'The RK Royal Kludge
RK61 is a wireless mechanical keyboard designed for gaming', 59.99,
'https://example.com/keyboard.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES (3, 3, 'BenQ Zowie EC2-A Gaming Mouse', 'The BenQ Zowie EC2-A is a gaming
mouse designed for esports', 59.99, 'https://example.com/mouse.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES (4, 1, 'Samsung 27-inch Curved Monitor', 'Full HD monitor with a curved
design', 249.99, 'https://www.example.com/samsung-curved-monitor.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES (5, 1, 'AOC 24-inch LED Monitor', 'Full HD monitor with a slim profile',
149.99, 'https://www.example.com/aoc-led-monitor.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES (6, 1, 'Razer Raptor 27-inch Gaming Monitor', 'QHD gaming monitor with a
144Hz refresh rate', 799.99, 'https://www.example.com/razer-raptor-monitor.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES
(7, 4, 'Bose QuietComfort 35 II', 'Wireless noise-cancelling headphones with Alexa
voice control', 299.00, 'https://example.com/headphone1.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES
(8, 4, 'Sony WH-1000XM4', 'Wireless noise-cancelling headphones with 30 hours of
battery life', 348.00, 'https://example.com/headphone2.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES
(9, 4, 'Sennheiser HD 660 S', 'High-end open-back headphones with exceptional
clarity and detail', 499.95, 'https://example.com/headphone3.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES
(10, 5, 'Razer Blade 15', '15.6-inch gaming laptop with NVIDIA GeForce RTX 3070
graphics', 1799.99, 'https://example.com/laptop1.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES
(11, 5, 'ASUS ROG Zephyrus G14', '14-inch gaming laptop with AMD Ryzen 9 processor
and NVIDIA GeForce RTX 3060 graphics', 1449.99, 'https://example.com/laptop2.jpg');

INSERT INTO products (product_id, category_id, product_name, product_brand, price,


image_url)
VALUES
(12, 5, 'Dell XPS 13', '13.4-inch laptop with 11th Gen Intel Core processor and up
to 16GB RAM', 1199.99, 'https://example.com/laptop3.jpg');
--changes
ALTER TABLE products RENAME COLUMN PRODUCT_BRAND TO description;
commit;
rollback;

ALTER TABLE products


ADD brand VARCHAR(255);

UPDATE products
SET brand = 'Razer'
WHERE product_name LIKE '%Razer%';

UPDATE products
SET brand = 'RK Royal Kludge'
WHERE product_name LIKE '%RK Royal Kludge%';

UPDATE products
SET brand = 'BenQ Zowie'
WHERE product_name LIKE '%BenQ Zowie%';

UPDATE products
SET brand = 'Samsung'
WHERE product_name LIKE '%Samsung%';

UPDATE products
SET brand = 'AOC'
WHERE product_name LIKE '%AOC%';

UPDATE products
SET brand = 'Razer'
WHERE product_name LIKE '%Razer Raptor%';

UPDATE products
SET brand = 'Bose'
WHERE product_name LIKE '%Bose%';

UPDATE products
SET brand = 'Sony'
WHERE product_name LIKE '%Sony%';

UPDATE products
SET brand = 'Sennheiser'
WHERE product_name LIKE '%Sennheiser%';

UPDATE products
SET brand = 'Razer'
WHERE product_name LIKE '%Razer Blade%';

UPDATE products
SET brand = 'ASUS'
WHERE product_name LIKE '%ASUS ROG Zephyrus%';

UPDATE products
SET brand = 'Dell'
WHERE product_name LIKE '%Dell XPS%';

commit;
CREATE TABLE inventory (
inventory_id INT NOT NULL,
product_id INT NOT NULL,
location VARCHAR(255) NOT NULL,
units INT NOT NULL,
PRIMARY KEY (inventory_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)
);

--data for inventory


INSERT INTO inventory (inventory_id, product_id, location, Quantity)
VALUES (1, 1, 'Warehouse A', 100);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (2, 2, 'Warehouse B', 50);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (3, 3, 'Warehouse C', 75);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (4, 4, 'Warehouse A', 200);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (5, 5, 'Warehouse B', 150);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (6, 6, 'Warehouse C', 100);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (7, 7, 'Warehouse A', 25);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (8, 8, 'Warehouse B', 30);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (9, 9, 'Warehouse C', 40);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (10, 10, 'Warehouse A', 20);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (11, 11, 'Warehouse B', 15);

INSERT INTO inventory (inventory_id, product_id, location, Quantity)


VALUES (12, 12, 'Warehouse C', 10);

CREATE TABLE categories (


category_id INT NOT NULL ,
category_name VARCHAR(255) NOT NULL,
description VARCHAR(255) NOT NULL,
PRIMARY KEY (category_id)
);

-- data for categories


INSERT INTO categories (category_id, category_name)
VALUES (1, 'Monitor');
INSERT INTO categories (category_id, category_name)
VALUES (2, 'Keyboard');

INSERT INTO categories (category_id, category_name)


VALUES (3, 'Mouse');

INSERT INTO categories (category_id, category_name)


VALUES (4, 'Headphone');

INSERT INTO categories (category_id, category_name)


VALUES (5, 'Laptop');
commit;

CREATE TABLE suppliers (


supplier_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
contact_info VARCHAR(255) NOT NULL,
PRIMARY KEY (supplier_id)
);
--data for suppliers
INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)
VALUES (1, 'Supplier X', '123 Main St, Anytown USA', '555-1234', 1);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (2, 'Supplier Y', '456 Oak St, Anytown USA', '555-5678', 2);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (3, 'Supplier Z', '789 Elm St, Anytown USA', '555-9012', 3);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (4, 'Supplier X', '123 Main St, Anytown USA', '555-1234', 4);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (5, 'Supplier Y', '456 Oak St, Anytown USA', '555-5678', 5);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (6, 'Supplier Z', '789 Elm St, Anytown USA', '555-9012', 6);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (7, 'Supplier X', '123 Main St, Anytown USA', '555-1234', 7);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (8, 'Supplier Y', '456 Oak St, Anytown USA', '555-5678', 8);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (9, 'Supplier Z', '789 Elm St, Anytown USA', '555-9012', 9);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (10, 'Supplier X', '123 Main St, Anytown USA', '555-1234', 10);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (11, 'Supplier Y', '456 Oak St, Anytown USA', '555-5678', 2);

INSERT INTO suppliers (supplier_id, name, address, contact_info, product_id)


VALUES (12, 'Supplier Z', '789 Elm St, Anytown USA', '555-9012', 3);

CREATE TABLE review (


review_id INT NOT NULL,
customer_id INT NOT NULL,
product_id INT NOT NULL,
rating INT NOT NULL,
text VARCHAR(255) NOT NULL,
PRIMARY KEY (review_id),
FOREIGN KEY (customer_id) REFERENCES customer(customer_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)
);
--data for review table
INSERT INTO review (review_id, customer_id, product_id, rating, text)
VALUES (1, 1, 1, 4, 'Great product, I highly recommend it.');

INSERT INTO review (review_id, customer_id, product_id, rating, text)


VALUES (2, 2, 10, 9, 'Decent product, could be better.');

INSERT INTO review (review_id, customer_id, product_id, rating, text)


VALUES (3, 3, 4, 8, 'Amazing product, exceeded my expectations.');

CREATE TABLE payments (


payment_id INT NOT NULL,
customer_id INT NOT NULL,
order_id INT NOT NULL,
payment_amount DECIMAL(10, 2) NOT NULL,
payment_date DATE NOT NULL,
PRIMARY KEY (payment_id),
FOREIGN KEY (customer_id) REFERENCES customer(customer_id)
);

--data for payment


INSERT INTO sale (sale_id, customer_id, product_id, payment_amount,
payment_date,QUANTITY)
VALUES (1, 1, 1, 699.9, TO_DATE('2022-01-01', 'YYYY-MM-DD'),10);

INSERT INTO sale (sale_id, customer_id, product_id, payment_amount,


payment_date,QUANTITY)
VALUES (2, 2, 2, 119.98, TO_DATE('2022-01-02', 'YYYY-MM-DD'),2);

INSERT INTO sale (sale_id, customer_id, product_id, payment_amount,


payment_date,QUANTITY)
VALUES (3, 3, 5, 149.99, TO_DATE('2022-01-03', 'YYYY-MM-DD'),1);

INSERT INTO sale (sale_id, customer_id, product_id, payment_amount,


payment_date,QUANTITY)
VALUES (4, 3, 6, 799.99, TO_DATE('2022-01-06', 'YYYY-MM-DD'),1);

INSERT INTO sale (sale_id, customer_id, product_id, payment_amount,


payment_date,QUANTITY)
VALUES (5, 1, 8, 1044, TO_DATE('2022-01-10', 'YYYY-MM-DD'),3);

INSERT INTO sale (sale_id, customer_id, product_id, payment_amount,


payment_date,QUANTITY)
VALUES (6, 1, 10, 8999.95, TO_DATE('2022-01-11', 'YYYY-MM-DD'),5);

--Altering Table,
ALTER TABLE Suppliers ADD product_id INT NOT NULL;
ALTER TABLE Suppliers ADD FOREIGN KEY (product_id) REFERENCES products(product_id);

ALTER TABLE Payments ADD product_id INT NOT NULL;


ALTER TABLE Payments ADD FOREIGN KEY (product_id) REFERENCES products(product_id);
ALTER TABLE Payments DROP COLUMN order_id;
ALTER TABLE Payments DROP COLUMN payment_id;
ALTER TABLE Payments ADD Qauntity INT NOT NULL ;
ALTER TABLE sale RENAME COLUMN Qauntity to quantity;
ALTER TABLE payments RENAME TO Sale;
ALTER TABLE products RENAME COLUMN NAME to PRODUCT_NAME;
ALTER TABLE products RENAME COLUMN DESCRIPTION to PRODUCT_BRAND;
ALTER TABLE Categories DROP COLUMN DESCRIPTION;
ALTER TABLE Sale ADD Sale_id INT NOT NULL;
ALTER TABLE Sale ADD PRIMARY KEY (sale_id);
ALTER TABLE Inventory RENAME COLUMN Units TO Quantity;
COMMIT;

You might also like