DirektiveDesDons/BancaDati.sql

102 lines
4.7 KiB
MySQL
Raw Normal View History

2023-01-11 10:33:20 +01:00
SET
SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET
time_zone = "+00:00";
2023-01-23 05:33:21 +01:00
CREATE TABLE `folla`
( /*Menge*/
`id` int auto_increment NOT NULL PRIMARY KEY,
`unita` varchar(200) UNIQUE NOT NULL, /*Einheit*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2023-01-11 10:33:20 +01:00
CREATE TABLE `ingredienti`
( /*Zutaten*/
2023-01-23 05:33:21 +01:00
`id` int auto_increment NOT NULL PRIMARY KEY,
`cognome` varchar(200) NOT NULL, /*Name*/
`calorie` integer(5) NOT NULL, /*Kalorien*/
`quantita` integer(5) NOT NULL, /*Anzahl*/
2023-01-25 08:02:59 +01:00
`prezzo` decimal(8, 2) NOT NULL, /*Preis*/
2023-01-23 05:33:21 +01:00
`follaID` int NOT NULL, /*MengeID*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
2022-12-15 15:11:16 +01:00
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2023-01-11 10:33:20 +01:00
CREATE TABLE `elenco`
( /*Liste*/
2023-01-23 05:33:21 +01:00
`id` int auto_increment NOT NULL PRIMARY KEY,
`utenteID` int NOT NULL, /*ErstellerID*/
`cognome` varchar(200) NOT NULL, /*Name*/
`coloreDiSfondo` varchar(200), /*Hintergrundfarbe*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
2022-12-15 15:11:16 +01:00
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2023-01-11 10:33:20 +01:00
CREATE TABLE `utente`
( /*Benutzer*/
2023-01-23 05:33:21 +01:00
`id` int auto_increment NOT NULL PRIMARY KEY,
`email` varchar(200) NOT NULL, /*Email*/
`parolaDordine` varchar(255) NOT NULL, /*Passwort*/
`nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/
`gettone` varchar(255), /*Token für Session*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
2022-12-15 15:11:16 +01:00
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2023-01-11 10:33:20 +01:00
CREATE TABLE `elencoIngredienti`
( /*Liste_Zutaten*/
2023-01-23 05:33:21 +01:00
`id` int auto_increment NOT NULL PRIMARY KEY,
`ingredientiID` int NOT NULL, /*ZutatenID*/
`elencoID` int NOT NULL, /*ListeID*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
2022-12-15 15:11:16 +01:00
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2023-01-11 10:33:20 +01:00
CREATE TABLE `utenteElenco`
( /*Benutzer_Liste*/
2023-01-23 05:33:21 +01:00
`id` int auto_increment NOT NULL PRIMARY KEY,
`elencoID` int NOT NULL, /*ListeID*/
`utenteID` int NOT NULL, /*BenutzerID*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
2022-12-15 15:11:16 +01:00
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2023-01-11 14:36:18 +01:00
ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/
2022-12-15 15:11:16 +01:00
ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/
2023-01-23 05:33:21 +01:00
ADD CONSTRAINT `FK_ElencoIngredienti_Elenco` FOREIGN KEY (`elencoID`) REFERENCES `elenco`(`id`); /*Liste_Zutaten hat Foreignkey von Liste(id)*/
2022-12-15 15:11:16 +01:00
2023-01-11 14:36:18 +01:00
ALTER TABLE `utenteElenco` /*Benutzer_Liste*/
2022-12-15 15:11:16 +01:00
ADD CONSTRAINT `FK_UtenteElenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`), /*Benutzer_Liste hat Foreignkey von Benutzer(id)*/
2022-12-21 10:27:40 +01:00
ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`); /*Benutzer_Liste hat Foreignkey von Liste(id)*/
2023-01-23 05:33:21 +01:00
ALTER TABLE `ingredienti`
ADD CONSTRAINT `FK_Ingredienti_Folla` FOREIGN KEY (`follaID`) REFERENCES `folla`(`id`); /*Zutaten hat Foreignkey von Menge(id)*/
ALTER TABLE `elenco`
ADD CONSTRAINT `FK_Elenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`); /*Liste hat Foreignkey von Benutzer(id)*/
/*Test Data*/
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test@test.com', 'password', "testuser");
2023-01-25 08:02:59 +01:00
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test1@test.com', 'hunter2', "testuser1");
2023-01-23 05:33:21 +01:00
INSERT INTO `folla` (unita) VALUES ('st');
INSERT INTO `folla` (unita) VALUES ('g');
INSERT INTO `folla` (unita) VALUES ('kg');
INSERT INTO `folla` (unita) VALUES ('mg');
INSERT INTO `folla` (unita) VALUES ('l');
INSERT INTO `folla` (unita) VALUES ('ml');
INSERT INTO `folla` (unita) VALUES ('TL');
INSERT INTO `folla` (unita) VALUES ('EL');
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Raffinierter Zucker', 3870, 1000, 5, 2);
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Die Chips von der Tanke', 843, 375, 4.30, 2);
2023-01-25 08:02:59 +01:00
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Reines Copium', 420, 1337, 6.9, 4);
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Maggi', 420, 1337, 6.9, 4);
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Eine große Pommes Frites mit Pommes Frites', 4200, 1, 6.9, 3);
2023-01-23 05:33:21 +01:00
2023-01-25 08:02:59 +01:00
INSERT INTO `elenco` (utenteID, cognome) VALUES (1, 'Liste für den Einkauf bei Netto');
2023-01-23 05:33:21 +01:00
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (1, 1);
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (2, 1);