2022-03-08 18:29:49 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS sales_people (
|
2022-03-09 16:00:36 +01:00
|
|
|
person_id SERIAL PRIMARY KEY,
|
|
|
|
name varchar(200) NOT NULL
|
2022-03-08 18:29:49 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS sales (
|
2022-03-09 16:00:36 +01:00
|
|
|
sale_id SERIAL PRIMARY KEY,
|
2022-03-08 18:29:49 +01:00
|
|
|
sale_name varchar(200) NOT NULL,
|
|
|
|
sold_by INT,
|
|
|
|
CONSTRAINT sold_by_fk
|
|
|
|
FOREIGN KEY(sold_by)
|
|
|
|
REFERENCES sales_people(person_id)
|
|
|
|
);
|
|
|
|
|
2022-03-09 16:00:36 +01:00
|
|
|
INSERT INTO sales_people (name)
|
|
|
|
select 'Salesperson ' || id
|
2022-03-08 18:29:49 +01:00
|
|
|
FROM GENERATE_SERIES(1, 50) as id;
|
|
|
|
|
2022-03-09 16:00:36 +01:00
|
|
|
INSERT INTO sales (sale_name, sold_by)
|
|
|
|
select 'Sale ' || id, floor(random() * 50 + 1)::int
|
|
|
|
FROM GENERATE_SERIES(1, 200) as id;
|