Objective
Create a promotional banner management system for marketing campaigns. This enables coordinated marketing efforts across channels with scheduled banner rotations.
Step 1: Create Campaigns Table
Define marketing campaigns.
CREATE TABLE marketing_campaigns (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
campaign_type VARCHAR(50),
start_date DATE NOT NULL,
end_date DATE NOT NULL,
budget DECIMAL(10, 2),
status VARCHAR(20) DEFAULT 'draft',
target_audience VARCHAR(255),
created_by VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create Banner Placements Table
Define where banners can appear.
CREATE TABLE banner_placements (
id INTEGER PRIMARY KEY,
name VARCHAR(100) NOT NULL,
location VARCHAR(100) NOT NULL,
width INTEGER NOT NULL,
height INTEGER NOT NULL,
description TEXT,
is_active BOOLEAN DEFAULT TRUE
);
Step 3: Create Promotional Banners Table
Store banner images and metadata.
CREATE TABLE promotional_banners (
id INTEGER PRIMARY KEY,
campaign_id INTEGER NOT NULL,
placement_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
banner_image IMAGE(JPEG),
banner_mobile IMAGE(JPEG),
alt_text VARCHAR(255),
click_url VARCHAR(500),
priority INTEGER DEFAULT 0,
impressions INTEGER DEFAULT 0,
clicks INTEGER DEFAULT 0,
is_active BOOLEAN DEFAULT TRUE,
start_datetime TIMESTAMP,
end_datetime TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (campaign_id) REFERENCES marketing_campaigns(id),
FOREIGN KEY (placement_id) REFERENCES banner_placements(id)
);
Step 4: Create Banner Performance Table
Track banner analytics.
CREATE TABLE banner_performance (
id INTEGER PRIMARY KEY,
banner_id INTEGER NOT NULL,
record_date DATE NOT NULL,
impressions INTEGER DEFAULT 0,
clicks INTEGER DEFAULT 0,
conversions INTEGER DEFAULT 0,
revenue DECIMAL(10, 2) DEFAULT 0,
FOREIGN KEY (banner_id) REFERENCES promotional_banners(id)
);
Step 5: Insert Banner Placements
Define available positions.
INSERT INTO banner_placements (id, name, location, width, height, description) VALUES
(1, 'Homepage Hero', 'homepage', 1920, 600, 'Main hero banner on homepage'),
(2, 'Homepage Secondary', 'homepage', 600, 400, 'Secondary promotional area'),
(3, 'Category Header', 'category_page', 1200, 300, 'Top of category pages'),
(4, 'Sidebar Banner', 'sidebar', 300, 600, 'Right sidebar promotional'),
(5, 'Product Page Banner', 'product_page', 800, 200, 'Above product details'),
(6, 'Cart Page Banner', 'cart', 1000, 150, 'Shopping cart promotions'),
(7, 'Email Header', 'email', 600, 200, 'Email marketing header'),
(8, 'Mobile App Banner', 'mobile_app', 375, 200, 'Mobile app home screen');
Step 6: Insert Marketing Campaigns
Add sample campaigns.
INSERT INTO marketing_campaigns (id, name, campaign_type, start_date, end_date, budget, status, target_audience, created_by) VALUES
(1, 'Summer Sale 2024', 'seasonal', '2024-06-01', '2024-08-31', 50000.00, 'active', 'all_customers', 'marketing_team'),
(2, 'Back to School', 'seasonal', '2024-08-15', '2024-09-15', 25000.00, 'active', 'families', 'marketing_team'),
(3, 'New Product Launch', 'product', '2024-07-01', '2024-07-31', 15000.00, 'active', 'tech_enthusiasts', 'product_team'),
(4, 'Flash Sale Weekend', 'flash', '2024-07-20', '2024-07-21', 5000.00, 'completed', 'newsletter_subscribers', 'marketing_team'),
(5, 'Holiday Preview', 'seasonal', '2024-11-01', '2024-12-31', 75000.00, 'draft', 'all_customers', 'marketing_team');
Step 7: Insert Promotional Banners
Add campaign banners.
INSERT INTO promotional_banners (id, campaign_id, placement_id, name, alt_text, click_url, priority, impressions, clicks, is_active, start_datetime, end_datetime) VALUES
-- Summer Sale banners
(1, 1, 1, 'Summer Sale Hero', 'Up to 50% off summer essentials', '/summer-sale', 10, 150000, 4500, TRUE, '2024-06-01 00:00:00', '2024-08-31 23:59:59'),
(2, 1, 2, 'Summer Sale Secondary', 'Shop summer deals', '/summer-sale', 5, 120000, 2400, TRUE, '2024-06-01 00:00:00', '2024-08-31 23:59:59'),
(3, 1, 3, 'Summer Category Header', 'Summer collection now available', '/category/summer', 5, 80000, 1600, TRUE, '2024-06-01 00:00:00', '2024-08-31 23:59:59'),
(4, 1, 7, 'Summer Email Banner', 'Exclusive summer savings inside', '/summer-sale?src=email', 10, 50000, 2500, TRUE, '2024-06-01 00:00:00', '2024-08-31 23:59:59'),
-- Back to School banners
(5, 2, 1, 'Back to School Hero', 'Get ready for school - Save 30%', '/back-to-school', 10, 45000, 1350, TRUE, '2024-08-15 00:00:00', '2024-09-15 23:59:59'),
(6, 2, 4, 'Back to School Sidebar', 'School supplies on sale', '/back-to-school/supplies', 5, 35000, 700, TRUE, '2024-08-15 00:00:00', '2024-09-15 23:59:59'),
-- New Product Launch
(7, 3, 1, 'New Product Hero', 'Introducing the all-new ProMax', '/products/promax', 15, 75000, 3750, TRUE, '2024-07-01 00:00:00', '2024-07-31 23:59:59'),
(8, 3, 5, 'Product Page Cross-sell', 'Pair with ProMax accessories', '/products/promax-accessories', 5, 25000, 1250, TRUE, '2024-07-01 00:00:00', '2024-07-31 23:59:59'),
-- Flash Sale
(9, 4, 1, 'Flash Sale Hero', '48 Hours Only - Extra 20% Off', '/flash-sale', 20, 30000, 1800, FALSE, '2024-07-20 00:00:00', '2024-07-21 23:59:59'),
(10, 4, 6, 'Flash Sale Cart', 'Flash sale ends soon - Complete your order', '/flash-sale', 15, 8000, 640, FALSE, '2024-07-20 00:00:00', '2024-07-21 23:59:59');