All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Ans. Table: Coupon coupon_id (primary key) coupon_code discount_rule (e.g., percentage or fixed amount) discount_percentage (e.g., 10% off) start_date end_date Table: OrderShipment shipment_id (primary key) order_id (foreign key to Order table) shipment_date shipment_status shipment_location carrier Table: Invoice invoice_id…
Adith Krishnan R
updated on 26 Feb 2023
Ans.
Table: Coupon
Table: OrderShipment
Table: Invoice
Table: Wishlist
Table: Replacement
Table: Review
Table: Product
Table: ProductSize
Table: ProductQuantity
Table: ProductCategory
Table: ProductBrand
Table: ProductTag
Table: ProductImage
Table: ProductQuestion
Table: ProductAnswer
Table: Customer
Table: CustomerAddress
Table: CustomerContact
Table: Order
Table: OrderItem
Table: Seller
SQL Queries :
CREATE TABLE Customer (
customer_id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
phone_number VARCHAR(20) NOT NULL,
gender CHAR(1),
dob DATE,
city VARCHAR(50),
password VARCHAR(100) NOT NULL,
member_type ENUM('normal', 'premium') NOT NULL DEFAULT 'normal'
);
CREATE TABLE CustomerAddress (
address_id PRIMARY KEY INT AUTO-INCREMENT,
FOREIGN KEY (customer_ID) REFERENCES Customer(Customer_iID),
FOREIGN KEY (area) REFERENCES CustomerAreaInfo(area)
);
CREATE TABLE CustomerAreaInfo (
area PRIMARY KEY INT AUTO-INCREMENT,
isDefault BOOLEAN,
door_no VARCHAR(4) NOT NULL,
street VARCHAR(100) NOT NULL,
city VARCHAR(100) NOT NULL,
country VARCHAR(100) NOT NULL
);
CREATE TABLE CustomerContact(
contact_ID PRIMARY KEY INT AUTO_INCREMENT,
FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID),
phone_number INT(11),
email VARCHAR(255)
)
CREATE TABLE Admin(
admin_ID PRIMARY KEY INT AUTO_INCREMENT,
name VARCHAR(255),
password VARCHAR(255)
)
CREATE TABLE AdminContact(
contact_ID PRIMARY KEY INT AUTO_INCREMENT,
FOREIGN KEY (admin_ID) REFERENCES Admin(admin_ID),
email VARCHAR(255) NOT NULL,
phone_number INT(11) NOT NULL
)
CREATE TABLE Seller (
seller_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
);
CREATE TABLE Seller (
FOREIGN KEY (seller_id) REFERENCES Seller(Seller_ID),
contact_ID PRIMARY KEY INT NOT NULL,
email VARCHAR(255) NOT NULL,
phone_number INT(11) NOT NULL
);
CREATE TABLE SellerLocation (
FOREIGN KEY (seller_id) REFERENCES Seller(Seller_ID) ,
location VARCHAR(255) NOT NULL,
);
CREATE TABLE Product (
product_id INT PRIMARY KEY,
name VARCHAR(255),
color VARCHAR(255),
cost DECIMAL(10,2),
current_discount DECIMAL(4,2),
product_origin VARCHAR(255),
is_featured BOOLEAN,
popularity_index INT,
avg_ratings DECIMAL(3,2),
total_ratings INT,
description VARCHAR(255),
is_on_sale BOOLEAN,
category_id INT,
brand_id INT,
FOREIGN KEY (seller_id) REFERENCES Sellers (seller_id),
FOREIGN KEY (category_id) REFERENCES Category (category_id),
FOREIGN KEY (brand_id) REFERENCES Brand (brand_id)
);
CREATE TABLE Category (
category_id INT PRIMARY KEY AUTO_INCREMENT,
category_name VARCHAR(50) NOT NULL,
parent_id INT,
FOREIGN KEY (parent_id) REFERENCES Category(category_id)
);
CREATE TABLE ProductCategory (
product_id INT NOT NULL,
category_id INT NOT NULL,
PRIMARY KEY (product_id, category_id),
FOREIGN KEY (product_id) REFERENCES Product(product_id),
FOREIGN KEY (category_id) REFERENCES Category(category_id)
);
CREATE TABLE Brand (
brand_id INT PRIMARY KEY AUTO_INCREMENT,
brand_name VARCHAR(50) NOT NULL
);
CREATE TABLE ProductBrand (
product_id INT NOT NULL,
brand_id INT NOT NULL,
PRIMARY KEY (product_id, brand_id),
FOREIGN KEY (product_id) REFERENCES Product(product_id),
FOREIGN KEY (brand_id) REFERENCES Brand(brand_id)
);
CREATE TABLE Tag (
tag_id INT PRIMARY KEY AUTO_INCREMENT,
tag_name VARCHAR(50) NOT NULL
);
CREATE TABLE ProductTag (
product_id INT NOT NULL,
tag_id INT NOT NULL,
PRIMARY KEY (product_id, tag_id),
FOREIGN KEY (product_id) REFERENCES Product(product_id),
FOREIGN KEY (tag_id) REFERENCES Tag(tag_id)
);
CREATE TABLE Order (
order_id INT PRIMARY KEY AUTO_INCREMENT,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
total_price DECIMAL(10, 2) NOT NULL,
payment_status ENUM('pending', 'paid', 'cancelled') NOT NULL DEFAULT 'pending',
shipping_status ENUM('ordered', 'packed', 'shipped', 'delivered', 'cancelled') NOT NULL DEFAULT 'ordered',
CREATE TABLE OrderItems(
FOREIGN KEY (order_ID) REFERENCES Order(order_ID)
FOREIGN KEY (PRODUCT_ID) REFERENCES Product(Product_ID),
item_cost INT (6),
item_quantity iNT (6),
item_availability BOOLEAN
)
CREATE TABLE Wishlist (
wishlist_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255),
description VARCHAR (255),
added_date DATE
);
CREATE TABLE WishlistItems (
FOREIGN KEY (wishlist_ID) REFERENCES Wishlist(wishlist_ID),
FOREIGN KEY (customer_ID) REFERENCES Customers(customer_ID),
FOREIGN KEY (product_ID) REFERENCES Products(product_ID)
)
CREATE TABLE Product_Replacements (
replacement_id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT NOT NULL,
product_id INT NOT NULL,
status VARCHAR(20) NOT NULL,
FOREIGN KEY (order_id) REFERENCES Orders(order_id),
FOREIGN KEY (product_id) REFERENCES Products(product_id)
);
CREATE TABLE Product_Reviews (
review_id INT PRIMARY KEY AUTO_INCREMENT,
product_id INT NOT NULL,
customer_id INT NOT NULL,
rating INT NOT NULL,
review_text VARCHAR(500) NOT NULL,
review_date DATE NOT NULL,
FOREIGN KEY (product_id) REFERENCES Products(product_id),
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)
);
CREATE TABLE Coupon(
coupon_ID PRIMARY KEY INT NOT NULL,
discount_rule VARCHAR(255),
discount_percentage INT(3),
start_date DATE,
end_date DATE
)
CREATE TABLE OrderShipment (
shipment_id INT PRIMARY KEY,
order_id INT,
shipment_date DATE,
shipment_method VARCHAR(255),
shipment_tracking_no VARCHAR(255),
shipment_status VARCHAR(255),
FOREIGN KEY (order_id) REFERENCES Orders (order_id)
);
CREATE TABLE Payment (
payment_ID PRIMARY KEY NOT NULL INT,
status VARCHAR(255),
)
CREATE TABLE PaymentMethod (
FOREIGN KEY (payment_ID) REFERENCES Payment(payment_ID),
payment_mode VARCHAR(255),
)
CREATE TABLE Invoice (
invoice_id INT PRIMARY KEY,
order_id INT,
invoice_date DATE,
total_amount DECIMAL(10,2),
payment_method VARCHAR(255),
FOREIGN KEY (order_id) REFERENCES Orders (order_id)
);
CREATE TABLE Replacement (
replacement_id INT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
reason VARCHAR(255),
status VARCHAR(255),
FOREIGN KEY (order_id) REFERENCES Orders (order_id),
FOREIGN KEY (product_id) REFERENCES Products (product_id)
);
CREATE TABLE Review (
review_id INT PRIMARY KEY,
customer_id INT,
product_id INT,
rating INT,
review_text VARCHAR(255),
review_date DATE,
FOREIGN KEY (customer_id) REFERENCES Customers (customer_id),
FOREIGN KEY (product_id) REFERENCES Products (product_id)
);
CREATE TABLE ProductSize (
product_id INT,
size VARCHAR(10),
PRIMARY KEY (product_id, size),
FOREIGN KEY (product_id) REFERENCES Product (product_id)
);
CREATE TABLE ProductQuantity (
product_id INT,
size VARCHAR(10),
quantity INT,
PRIMARY KEY (product_id, size),
FOREIGN KEY (product_id, size) REFERENCES ProductSize (product_id, size)
);
CREATE TABLE ProductImage (
image_url VARCHAR(255),
PRIMARY KEY (product_id, image_url),
FOREIGN KEY (product_id) REFERENCES Product (product_id)
);
CREATE TABLE ProductQuestion (
question_id INT PRIMARY KEY,
question_text VARCHAR(255),
FOREIGN KEY (product_id) REFERENCES Product (product_id)
);
CREATE TABLE ProductAnswer (
answer_id INT PRIMARY KEY,
answer_text VARCHAR(255),
FOREIGN KEY (question_id) REFERENCES ProductQuestion (question_id)
);
CREATE TABLE Cart (
cart_ID PRIMARY KEY NOT NULL INT,
total_cost INT (6),
total_discount INT (3),
taxes INT (3)
)
CREATE TABLE CartItems (
FOREIGN KEY (cart_ID) REFERENCES Cart(cart_ID),
item_ID PRIMARY KEY NOT NULL INT,
item_cost INT (6),
item_quantity INT (6),
item_availability BOOLEAN
)
To optimize the database for efficient searching on name, categories, date of product, latest and brand name, we can create appropriate indexes on the relevant columns of the tables.
For example, we can create the following indexes:
CREATE INDEX idx_product_name ON Product (name);
CREATE INDEX idx_product_date_added ON Product (date_added);
CREATE INDEX idx_product_is_featured ON Product (is_featured);
CREATE INDEX idx_product_category_category_id ON ProductCategory (category_id);
CREATE INDEX idx_product_category_product_id ON ProductCategory (product_id);
CREATE INDEX idx_product_brand_brand_id ON ProductBrand (brand_id);
CREATE INDEX idx_product_brand_product_id ON ProductBrand (product_id);
By creating these indexes, the database engine can use them to quickly locate the relevant rows for a given search query, thereby improving the performance of the search.
For example, if we want to search for products with a particular name or brand, we can use the following SQL query:
SELECT * FROM Product WHERE name LIKE '%keyword%' OR brand LIKE '%keyword%';
The database engine can use the 'idx_product_name' and 'idx_product_brand' indexes to quickly locate the relevant rows for the search, rather than having to scan the entire table.
Similarly, if we want to search for products based on their category or date added, we can use the following SQL queries:
SELECT p.* FROM Product p JOIN ProductCategory pc ON p.id = pc.product_id WHERE pc.category_id = category_id;
SELECT * FROM Product WHERE date_added >= 'start_date' AND date_added <= 'end_date';
In both cases, the database engine can use the appropriate indexes to quickly locate the relevant rows for the search, rather than having to scan the entire table.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 1
Ans. Table: Coupon coupon_id (primary key) coupon_code discount_rule (e.g., percentage or fixed amount) discount_percentage (e.g., 10% off) start_date end_date Table: OrderShipment shipment_id (primary key) order_id (foreign key to Order table) shipment_date shipment_status shipment_location carrier Table: Invoice invoice_id…
26 Feb 2023 02:21 PM IST
Hackathon 2k21
Won first place in a Hackathon conducted by Skill-Lync. The challenge was to build a user-profile / portfolio website using front-end technologies HTML5, CSS3, Javascript, Bootstrap, jQuery. Additionally I used animate.css library for some smooth css animations. Live Project : https://adithkrishnan98.github.io/Hackathon2021/Hackathon/…
11 Nov 2021 11:36 AM IST
Task Manager Application
A fully responsive CRUD application built using React JS, Redux and Redux-Toolkit for state management, Framer Motion for animations, Axios for making fetch and post requests to a fake server. Project hosted on Heroku. Features : Viewing all tasks. Adding new tasks. Viewing pending and completed tasks separately. Searching…
30 Oct 2021 03:09 AM IST
Swag Of India E-commerce website - Front End
Click below to check out the website I've created as part of Front-End Dev Project https://swagofindia.netlify.app
26 Sep 2021 05:40 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.