Inserted suitable foreign keys in a sqlite compatible way

This commit is contained in:
Imbus 2024-03-23 19:47:14 +01:00
parent c54ecdab71
commit be904a7ab3

View file

@ -14,8 +14,8 @@ CREATE TABLE IF NOT EXISTS Recipes (
RecipeYear Year,
ingrediences int,
ProductID int,
PRIMARY KEY (RecipeName, RecipeYear)
FOREIGN KEY (ingrediences) REFERENCES ingredience(IngredienceID)
PRIMARY KEY (RecipeName, RecipeYear),
FOREIGN KEY (ingrediences) REFERENCES ingredience(IngredienceID),
FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);
@ -36,13 +36,16 @@ CREATE TABLE IF NOT EXISTS RawMaterials (
CREATE TABLE IF NOT EXISTS PalletsProduced (
PalletID int PRIMARY KEY,
ProductID int,
ProductionDateTime datetime
ProductionDateTime datetime,
FOREIGN KEY (ProductID) REFERENCES Products (ProductID)
);
CREATE TABLE IF NOT EXISTS PalletsDelivered (
DeliveredID int PRIMARY KEY,
PalletID int,
DeliveryDateTime datetime
DeliveryDateTime datetime,
FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID),
FOREIGN KEY (DeliveredID) REFERENCES Truck (Pallet)
);
CREATE TABLE IF NOT EXISTS Truck (
@ -55,7 +58,8 @@ CREATE TABLE IF NOT EXISTS loadingBill (
LoadingbillID int PRIMARY KEY,
adress varchar(100),
customer varchar(100),
truckID int
truckID int,
FOREIGN KEY (truckID) REFERENCES Truck (truckId)
);
CREATE TABLE IF NOT EXISTS Orders (
@ -63,28 +67,22 @@ CREATE TABLE IF NOT EXISTS Orders (
CustomerID int,
ProductID int,
Quantity int,
OrderDateTime datetime
OrderDateTime datetime,
FOREIGN KEY (CustomerID) REFERENCES Customers (CustomerID),
FOREIGN KEY (ProductID) REFERENCES Products (ProductID)
);
CREATE TABLE IF NOT EXISTS BlockedProducts (
BlockedProductID int PRIMARY KEY,
ProductID int,
BlockedDateTime datetime
BlockedDateTime datetime,
FOREIGN KEY (ProductID) REFERENCES Products (ProductID)
);
CREATE TABLE IF NOT EXISTS PalletTraceability (
TraceID int PRIMARY KEY,
location varchar(100),
locationdate datetime,
PalletID int
PalletID int,
FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID)
);
-- ALTER TABLE PalletsProduced ADD FOREIGN KEY (ProductID) REFERENCES Products (ProductID);
-- ALTER TABLE PalletsDelivered ADD FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID);
-- ALTER TABLE PalletsDelivered ADD FOREIGN KEY (DeliveredID) REFERENCES Truck (Pallet);
-- ALTER TABLE loadingBill ADD FOREIGN KEY (truckID) REFERENCES Truck (truckId);
-- ALTER TABLE Orders ADD FOREIGN KEY (CustomerID) REFERENCES Customers (CustomerID);
-- ALTER TABLE Orders ADD FOREIGN KEY (ProductID) REFERENCES Products (ProductID);
-- ALTER TABLE BlockedProducts ADD FOREIGN KEY (ProductID) REFERENCES Products (ProductID);
-- ALTER TABLE PalletTraceability ADD FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID);