Help me design a database for a demand side platform (DSP) in the ad space. Write sql…
- User
Help me design a database for a demand side platform (DSP) in the ad space. Write sql statements to create the essential tables in the database.
- Assistant
Help me design a database for a demand side platform (DSP) in the ad space. Write sql statements to create the essential tables in the database.
Certainly! Designing a database for a Demand Side Platform (DSP) in the advertising space involves modeling key entities such as advertisers, campaigns, creatives, bids, impressions, clicks, and conversions. Below, I will outline the essential tables along with SQL statements to create them. This design aims to capture the fundamental relationships and data required for a DSP to function effectively.
Entities and Relationships:
CREATE TABLE advertisers (
advertiser_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
contact_info VARCHAR(255),
account_balance DECIMAL(10, 2) DEFAULT 0.00,
status VARCHAR(20) NOT NULL CHECK (status IN ('active', 'inactive'))
);
Stores information about advertisers using the DSP.
CREATE TABLE campaigns (
campaign_id INT AUTO_INCREMENT PRIMARY KEY,
advertiser_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
budget DECIMAL(10, 2) DEFAULT 0.00,
start_date DATE,
end_date DATE,
status VARCHAR(20) NOT NULL CHECK (status IN ('active', 'inactive', 'paused')),
FOREIGN KEY (advertiser_id) REFERENCES advertisers(advertiser_id)
);
Contains campaigns created by advertisers, linked to the advertisers table.
CREATE TABLE creatives (
creative_id INT AUTO_INCREMENT PRIMARY KEY,
campaign_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
creative_type VARCHAR(20) NOT NULL CHECK (creative_type IN ('image', 'video', 'text')),
content_url VARCHAR(255) NOT NULL,
status VARCHAR(20) NOT NULL CHECK (status IN ('active', 'inactive')),
FOREIGN KEY (campaign_id) REFERENCES campaigns(campaign_id)
);
Holds ad content associated with campaigns.
CREATE TABLE ad_exchanges (
ad_exchange_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
contact_info VARCHAR(255),
status VARCHAR(20) NOT NULL CHECK (status IN ('active', 'inactive'))
);
Stores information about ad exchanges connected to the DSP.
CREATE TABLE targeting_options (
targeting_option_id INT AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(50) NOT NULL,
value VARCHAR(255) NOT NULL
);
Defines various targeting criteria (e.g., location, device type).
CREATE TABLE campaign_targeting_options (
campaign_id INT NOT NULL,
targeting_option_id INT NOT NULL,
PRIMARY KEY (campaign_id, targeting_option_id),
FOREIGN KEY (campaign_id) REFERENCES campaigns(campaign_id),
FOREIGN KEY (targeting_option_id) REFERENCES targeting_options(targeting_option_id)
);
Associates campaigns with targeting options.
CREATE TABLE bids (
bid_id INT AUTO_INCREMENT PRIMARY KEY,
campaign_id INT NOT NULL,
creative_id INT NOT NULL,
ad_exchange_id INT NOT NULL,
bid_amount DECIMAL(10, 4) NOT NULL,
bid_time DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (campaign_id) REFERENCES campaigns(campaign_id),
FOREIGN KEY (creative_id) REFERENCES creatives(creative_id),
FOREIGN KEY (ad_exchange_id) REFERENCES ad_exchanges(ad_exchange_id)
);
Records bids placed by the DSP on ad impressions.
CREATE TABLE impressions (
impression_id BIGINT AUTO_INCREMENT PRIMARY KEY,
bid_id INT NOT NULL,
ad_exchange_id INT NOT NULL,
impression_time DATETIME DEFAULT CURRENT_TIMESTAMP,
user_id VARCHAR(64),
location VARCHAR(255),
device VARCHAR(255),
FOREIGN KEY (bid_id) REFERENCES bids(bid_id),
FOREIGN KEY (ad_exchange_id) REFERENCES ad_exchanges(ad_exchange_id)
);
Logs when an ad is displayed to a user.
CREATE TABLE clicks (
click_id BIGINT AUTO_INCREMENT PRIMARY KEY,
impression_id BIGINT NOT NULL,
click_time DATETIME DEFAULT CURRENT_TIMESTAMP,
user_id VARCHAR(64),
FOREIGN KEY (impression_id) REFERENCES impressions(impression_id)
);
Tracks user clicks on ads.
CREATE TABLE conversions (
conversion_id BIGINT AUTO_INCREMENT PRIMARY KEY,
click_id BIGINT NOT NULL,
conversion_time DATETIME DEFAULT CURRENT_TIMESTAMP,
conversion_value DECIMAL(10, 2) DEFAULT 0.00,
FOREIGN KEY (click_id) REFERENCES clicks(click_id)
);
Logs conversions resulting from ad clicks (e.g., purchases).
DECIMAL for monetary values).PRIMARY KEY: Uniquely identifies each record.FOREIGN KEY: Maintains referential integrity between tables.NOT NULL: Ensures required fields are populated.CHECK: Enforces valid values for certain fields (may require enforcement via triggers or application logic in some SQL dialects).user_id fields can be populated with anonymized identifiers to track user interactions while respecting privacy.By creating these tables, you establish a foundational database structure for a DSP that can manage advertisers, campaigns, ad creatives, bidding processes, and track the performance of ads through impressions, clicks, and conversions. This structure supports essential DSP functionalities such as campaign management, ad targeting, real-time bidding, and reporting.
Feel free to adjust field types, constraints, or add additional tables and columns to suit specific requirements or to accommodate more advanced features such as real-time analytics, fraud detection, or integration with data management platforms.
Not yet included in a published release.