BEGIN;
CREATE TABLE IF NOT EXISTS users (
user_id SERIAL PRIMARY KEY,
user_name VARCHAR(50) NOT NULL
);
CREATE TABLE IF NOT EXISTS products (
product_id SERIAL PRIMARY KEY,
product_name VARCHAR(50) NOT NULL
);
CREATE TABLE IF NOT EXISTS user_products (
user_product_id SERIAL PRIMARY KEY,
user_id INTEGER,
product_id INTEGER,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)
);
COMMIT;
BEGIN;
INSERT INTO users(user_name) SELECT format('ユーザーNo.%s', i) FROM generate_series(1, 10000) as i;
INSERT INTO products(product_name) SELECT format('プロダクトNo.%s', i) FROM generate_series(1, 10000) as i;
INSERT INTO user_products(user_id, product_id) SELECT i, i FROM generate_series(1, 10000) as i;
COMMIT;