Objective
Create a customer review system with photo uploads and ratings. This enables social proof, authentic product feedback, and improved purchasing decisions.
Step 1: Create Products Table
Create a table for reviewed products.
CREATE TABLE reviewed_products (
id INTEGER PRIMARY KEY,
sku VARCHAR(50) NOT NULL UNIQUE,
name VARCHAR(255) NOT NULL,
category VARCHAR(100),
avg_rating DECIMAL(3, 2) DEFAULT 0,
review_count INTEGER DEFAULT 0,
photo_review_count INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create Reviews Table
Create a table for customer reviews.
CREATE TABLE product_reviews (
id INTEGER PRIMARY KEY,
product_id INTEGER NOT NULL,
customer_id VARCHAR(100) NOT NULL,
customer_name VARCHAR(100),
rating INTEGER NOT NULL,
title VARCHAR(255),
review_text TEXT,
has_photos BOOLEAN DEFAULT FALSE,
photo_count INTEGER DEFAULT 0,
is_verified_purchase BOOLEAN DEFAULT FALSE,
helpful_count INTEGER DEFAULT 0,
is_approved BOOLEAN DEFAULT TRUE,
is_featured BOOLEAN DEFAULT FALSE,
review_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (product_id) REFERENCES reviewed_products(id)
);
Step 3: Create Review Photos Table
Store customer-uploaded photos.
CREATE TABLE review_photos (
id INTEGER PRIMARY KEY,
review_id INTEGER NOT NULL,
photo IMAGE(JPEG),
caption TEXT,
photo_order INTEGER DEFAULT 1,
width INTEGER,
height INTEGER,
file_size INTEGER,
is_approved BOOLEAN DEFAULT TRUE,
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (review_id) REFERENCES product_reviews(id)
);
Step 4: Insert Sample Products
Add products for reviews.
INSERT INTO reviewed_products (id, sku, name, category) VALUES
(1, 'SHOES-RUN-001', 'ProRunner Sports Shoes', 'Footwear'),
(2, 'BAG-BACK-001', 'TravelMax Backpack', 'Bags'),
(3, 'WATCH-FIT-001', 'FitTrack Smart Watch', 'Electronics'),
(4, 'JACKET-OUT-001', 'AllWeather Jacket', 'Clothing'),
(5, 'CAMERA-ACT-001', 'ActionCam Pro', 'Electronics');
Step 5: Insert Customer Reviews
Add sample reviews.
INSERT INTO product_reviews (id, product_id, customer_id, customer_name, rating, title, review_text, has_photos, photo_count, is_verified_purchase, helpful_count, is_featured, review_date) VALUES
-- Shoes reviews
(1, 1, 'cust_001', 'Mike R.', 5, 'Best running shoes ever!', 'These shoes are incredibly comfortable. Ive run 3 marathons in them with no issues. Great cushioning and support.', TRUE, 3, TRUE, 45, TRUE, '2024-01-10 14:30:00'),
(2, 1, 'cust_002', 'Sarah L.', 4, 'Great shoes, runs slightly small', 'Love the quality and comfort. Order half size up as they run a bit small. Highly recommend!', TRUE, 2, TRUE, 28, FALSE, '2024-01-12 09:15:00'),
(3, 1, 'cust_003', 'John D.', 3, 'Decent but expected more', 'Quality is okay but not exceptional. Comfortable for daily use but wouldnt recommend for serious running.', FALSE, 0, TRUE, 12, FALSE, '2024-01-15 16:45:00'),
-- Backpack reviews
(4, 2, 'cust_004', 'Emily K.', 5, 'Perfect travel companion', 'Used this for a 3-week Europe trip. Fits carry-on size, has tons of pockets, and is waterproof!', TRUE, 4, TRUE, 67, TRUE, '2024-01-08 11:20:00'),
(5, 2, 'cust_005', 'Chris M.', 5, 'Durable and spacious', 'Bought for hiking and its perfect. Great back support and laptop compartment is super useful.', TRUE, 2, TRUE, 34, FALSE, '2024-01-18 13:00:00'),
-- Watch reviews
(6, 3, 'cust_006', 'Amanda P.', 4, 'Great fitness features', 'Accurate heart rate monitoring and sleep tracking. Battery lasts about 5 days. App could be better.', TRUE, 1, TRUE, 23, FALSE, '2024-01-20 10:30:00'),
(7, 3, 'cust_007', 'Tom B.', 5, 'Exceeded expectations', 'Best smartwatch at this price point. All the features I need for workouts and daily use.', TRUE, 3, TRUE, 41, TRUE, '2024-01-22 15:45:00'),
-- Camera reviews
(8, 5, 'cust_008', 'Lisa J.', 5, 'Amazing video quality', 'The 4K footage is stunning. Waterproof and compact. Perfect for my scuba diving trips.', TRUE, 5, TRUE, 89, TRUE, '2024-01-05 08:00:00');