done #3
100
BancaDati.sql
100
BancaDati.sql
@ -3,64 +3,96 @@ SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
|||||||
SET
|
SET
|
||||||
time_zone = "+00:00";
|
time_zone = "+00: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;
|
||||||
|
|
||||||
CREATE TABLE `ingredienti`
|
CREATE TABLE `ingredienti`
|
||||||
( /*Zutaten*/
|
( /*Zutaten*/
|
||||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||||
`cognome` varchar(200) NOT NULL, /*Name*/
|
`cognome` varchar(200) NOT NULL, /*Name*/
|
||||||
`caloriePerCento` integer(5) NOT NULL, /*Kalorien pro Gramm*/
|
`calorie` integer(5) NOT NULL, /*Kalorien*/
|
||||||
`ilPeso` integer(5) NULL, /*Gewicht*/
|
`quantita` integer(5) NOT NULL, /*Anzahl*/
|
||||||
`prezzo` decimal(4, 2) NOT NULL, /*Preis*/
|
`prezzo` decimal(4, 2) NOT NULL, /*Preis*/
|
||||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
`follaID` int NOT NULL, /*MengeID*/
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
|
||||||
CREATE TABLE `folla`
|
|
||||||
( /*Menge*/
|
|
||||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
|
||||||
`unita` varchar(200) NOT NULL, /*Einheit*/
|
|
||||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `elenco`
|
CREATE TABLE `elenco`
|
||||||
( /*Liste*/
|
( /*Liste*/
|
||||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||||
`creatore` varchar(200) NOT NULL, /*Ersteller*/
|
`utenteID` int NOT NULL, /*ErstellerID*/
|
||||||
`coloreDiSfondo` integer(10) NOT NULL, /*Hintergrundfarbe*/
|
`cognome` varchar(200) NOT NULL, /*Name*/
|
||||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
`coloreDiSfondo` varchar(200), /*Hintergrundfarbe*/
|
||||||
|
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `utente`
|
CREATE TABLE `utente`
|
||||||
( /*Benutzer*/
|
( /*Benutzer*/
|
||||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||||
`email` varchar(200) NOT NULL, /*Email*/
|
`email` varchar(200) NOT NULL, /*Email*/
|
||||||
`parolaDordine` varchar(255) NOT NULL, /*Passwort*/
|
`parolaDordine` varchar(255) NOT NULL, /*Passwort*/
|
||||||
`nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/
|
`nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/
|
||||||
`gettone` varchar(255), /*Token für Session*/
|
`gettone` varchar(255), /*Token für Session*/
|
||||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `elencoIngredienti`
|
CREATE TABLE `elencoIngredienti`
|
||||||
( /*Liste_Zutaten*/
|
( /*Liste_Zutaten*/
|
||||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||||
`ingredientiID` int NOT NULL, /*ZutatenID*/
|
`ingredientiID` int NOT NULL, /*ZutatenID*/
|
||||||
`elencoID` int NOT NULL, /*ListeID*/
|
`elencoID` int NOT NULL, /*ListeID*/
|
||||||
`follaID` int NOT NULL, /*MengeID*/
|
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `utenteElenco`
|
CREATE TABLE `utenteElenco`
|
||||||
( /*Benutzer_Liste*/
|
( /*Benutzer_Liste*/
|
||||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||||
`elencoID` int NOT NULL, /*ListeID*/
|
`elencoID` int NOT NULL, /*ListeID*/
|
||||||
`utenteID` int NOT NULL, /*BenutzerID*/
|
`utenteID` int NOT NULL, /*BenutzerID*/
|
||||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/
|
ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/
|
||||||
ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/
|
ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/
|
||||||
ADD CONSTRAINT `FK_ElencoIngredienti_Elenco` FOREIGN KEY (`elencoID`) REFERENCES `elenco`(`id`), /*Liste_Zutaten hat Foreignkey von Liste(id)*/
|
ADD CONSTRAINT `FK_ElencoIngredienti_Elenco` FOREIGN KEY (`elencoID`) REFERENCES `elenco`(`id`); /*Liste_Zutaten hat Foreignkey von Liste(id)*/
|
||||||
ADD CONSTRAINT `FK_ElencoIngredienti_Folla` FOREIGN KEY (`follaID`) REFERENCES `folla`(`id`); /*Liste_Zutaten hat Foreignkey von Menge(id)*/
|
|
||||||
|
|
||||||
ALTER TABLE `utenteElenco` /*Benutzer_Liste*/
|
ALTER TABLE `utenteElenco` /*Benutzer_Liste*/
|
||||||
ADD CONSTRAINT `FK_UtenteElenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`), /*Benutzer_Liste hat Foreignkey von Benutzer(id)*/
|
ADD CONSTRAINT `FK_UtenteElenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`), /*Benutzer_Liste hat Foreignkey von Benutzer(id)*/
|
||||||
ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`); /*Benutzer_Liste hat Foreignkey von Liste(id)*/
|
ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`); /*Benutzer_Liste hat Foreignkey von Liste(id)*/
|
||||||
|
|
||||||
|
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");
|
||||||
|
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test1@test.com', 'password1', "testuser1");
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
INSERT INTO `elenco` (utenteID, cognome) VALUES (1, 'Liste den Einkauf bei Netto');
|
||||||
|
|
||||||
|
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (1, 1);
|
||||||
|
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (2, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user