2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS customers (
|
|
|
|
customer_id int PRIMARY KEY,
|
|
|
|
name varchar(100),
|
|
|
|
address varchar(255)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS products (
|
|
|
|
product_id int PRIMARY KEY,
|
|
|
|
name varchar(100)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS recipes (
|
|
|
|
recipe_name varchar(100),
|
|
|
|
recipe_year year,
|
|
|
|
ingredients int,
|
|
|
|
product_id int,
|
|
|
|
PRIMARY KEY (recipe_name, recipe_year),
|
|
|
|
FOREIGN KEY (ingredients) REFERENCES ingredients(ingredient_id),
|
|
|
|
FOREIGN KEY (product_id) REFERENCES products(product_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS ingredients (
|
|
|
|
ingredient_id int PRIMARY KEY,
|
|
|
|
raw_material_name varchar(100),
|
2024-04-22 13:27:42 +02:00
|
|
|
amount int,
|
|
|
|
unit varchar(50),
|
2024-05-03 01:59:07 +02:00
|
|
|
FOREIGN KEY (raw_material_name) REFERENCES raw_materials(raw_material_name)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS raw_materials (
|
|
|
|
raw_material_name varchar(100) PRIMARY KEY,
|
|
|
|
quantity int,
|
|
|
|
last_delivery_date_time datetime
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS pallets_produced (
|
|
|
|
pallet_id int PRIMARY KEY,
|
|
|
|
product_id int,
|
|
|
|
production_date_time datetime,
|
|
|
|
FOREIGN KEY (product_id) REFERENCES products (product_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS pallets_delivered (
|
|
|
|
delivered_id int PRIMARY KEY,
|
|
|
|
pallet_id int,
|
|
|
|
delivery_date_time datetime,
|
|
|
|
FOREIGN KEY (pallet_id) REFERENCES pallets_produced (pallet_id),
|
|
|
|
FOREIGN KEY (delivered_id) REFERENCES truck (pallet)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS truck (
|
|
|
|
truck_id int PRIMARY KEY,
|
2024-04-22 13:27:42 +02:00
|
|
|
capacity int,
|
2024-05-03 01:59:07 +02:00
|
|
|
pallet int
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS loading_bill (
|
|
|
|
loadingbill_id int PRIMARY KEY,
|
|
|
|
address varchar(100),
|
2024-04-22 13:27:42 +02:00
|
|
|
customer varchar(100),
|
2024-05-03 01:59:07 +02:00
|
|
|
truck_id int,
|
|
|
|
FOREIGN KEY (truck_id) REFERENCES truck (truck_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS orders (
|
|
|
|
order_id int PRIMARY KEY,
|
|
|
|
customer_id int,
|
|
|
|
product_id int,
|
|
|
|
quantity int,
|
|
|
|
order_date_time datetime,
|
|
|
|
FOREIGN KEY (customer_id) REFERENCES customers (customer_id),
|
|
|
|
FOREIGN KEY (product_id) REFERENCES products (product_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS blocked_products (
|
|
|
|
blocked_product_id int PRIMARY KEY,
|
|
|
|
product_id int,
|
|
|
|
blocked_date_time datetime,
|
|
|
|
FOREIGN KEY (product_id) REFERENCES products (product_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 01:59:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS pallet_traceability (
|
|
|
|
trace_id int PRIMARY KEY,
|
2024-04-22 13:27:42 +02:00
|
|
|
location varchar(100),
|
2024-05-03 01:59:07 +02:00
|
|
|
location_date datetime,
|
|
|
|
pallet_id int,
|
|
|
|
FOREIGN KEY (pallet_id) REFERENCES pallets_produced (pallet_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|