CREATE TABLE customer (
    c_customer_sk INT PRIMARY KEY,
    c_current_addr_sk INT,
    c_current_cdemo_sk INT
);
INSERT INTO customer 
SELECT generate_series(1, 100000), 
       (random() * 50000)::INT + 1, 
       (random() * 1920800)::INT + 1;

CREATE TABLE customer_address (
    ca_address_sk INT PRIMARY KEY,
    ca_county VARCHAR(50)
);
INSERT INTO customer_address 
SELECT generate_series(1, 50000), 
       CASE (random() * 5)::INT + 1 
           WHEN 1 THEN 'Rush County'
           WHEN 2 THEN 'Toole County'
           WHEN 3 THEN 'Jefferson County'
           WHEN 4 THEN 'Dona Ana County'
           WHEN 5 THEN 'La Porte County'
       END;

CREATE TABLE customer_demographics (
    cd_demo_sk INT PRIMARY KEY,
    cd_gender VARCHAR(10),
    cd_marital_status VARCHAR(15),
    cd_education_status VARCHAR(20),
    cd_income_band INT,
    cd_credit_rating VARCHAR(10),
    cd_dep_count INT
);
INSERT INTO customer_demographics 
SELECT generate_series(1, 1920800), 
       CASE (random() * 2)::INT + 1 
           WHEN 1 THEN 'Male'
           WHEN 2 THEN 'Female'
       END,
       CASE (random() * 3)::INT + 1 
           WHEN 1 THEN 'Single'
           WHEN 2 THEN 'Married'
           WHEN 3 THEN 'Divorced'
       END,
       CASE (random() * 3)::INT + 1 
           WHEN 1 THEN 'Bachelor'
           WHEN 2 THEN 'Master'
           WHEN 3 THEN 'PhD'
       END,
       (random() * 100000)::INT + 1,
       CASE (random() * 3)::INT + 1 
           WHEN 1 THEN 'Good'
           WHEN 2 THEN 'Average'
           WHEN 3 THEN 'Poor'
       END,
       (random() * 5)::INT + 1;

CREATE TABLE store_sales (
    ss_customer_sk INT,
    ss_sold_date_sk INT
);
INSERT INTO store_sales 
SELECT (random() * 100000)::INT + 1, 
       (random() * 73049)::INT + 1
FROM generate_series(1, 2880404);

CREATE TABLE web_sales (
    ws_bill_customer_sk INT,
    ws_sold_date_sk INT
);
INSERT INTO web_sales 
SELECT (random() * 100000)::INT + 1, 
       (random() * 73049)::INT + 1
FROM generate_series(1, 719384);

CREATE TABLE catalog_sales (
    cs_ship_customer_sk INT,
    cs_sold_date_sk INT
);
INSERT INTO catalog_sales 
SELECT (random() * 100000)::INT + 1, 
       (random() * 73049)::INT + 1
FROM generate_series(1, 1441548);

CREATE TABLE date_dim (
    d_date_sk INT PRIMARY KEY,
    d_year INT,
    d_moy INT
);
INSERT INTO date_dim 
SELECT generate_series(1, 73049), 
       2000 + (random() * 25)::INT, 
       (random() * 12)::INT + 1;
ANALYZE;


