
--- CREATE SCHEMA "20181126utenze";

--- SET search_path to "20181126utenze";


CREATE TABLE Persone (  CF  text NOT NULL PRIMARY KEY,
                        cognome text,
                        nome text );




CREATE TABLE Ordini (   codice integer NOT NULL PRIMARY KEY,
                        cliente text NOT NULL REFERENCES persone,
                        descrizione text NOT NULL);


CREATE TABLE RateEmesse ( numero integer NOT NULL PRIMARY KEY,
                        ordine integer NOT NULL REFERENCES ordini ,
                        data date NOT NULL,
                        importo integer NOT NULL,
                        datapagamento date );


---INSERT INTO persone(CF,cognome,nome) VALUES ('','','');
INSERT INTO persone(CF,cognome,nome) VALUES ('RSSMRA','Rossi','Mario');
INSERT INTO persone(CF,cognome,nome) VALUES ('BNCLGU','Bianco','Luigi');
INSERT INTO persone(CF,cognome,nome) VALUES ('VRDLCU','Verdi','Luca');
INSERT INTO persone(CF,cognome,nome) VALUES ('MROMRA','Mori','Mario');

---INSERT INTO ordini(codice,cliente,descrizione) 
---   VALUES ('','...','...');
--- DELETE FROM utenze;
INSERT INTO ordini(codice,cliente,descrizione)
   VALUES (101,'RSSMRA',' ...');
INSERT INTO ordini(codice,cliente,descrizione)
   VALUES (102,'RSSMRA',' ...');
INSERT INTO ordini(codice,cliente,descrizione)
   VALUES (103,'BNCLGU',' ...');


---INSERT INTO RateEmesse(numero,ordine,data,importo,datapagamento) 
---   VALUES (,,'',,'');
--- DELETE FROM bollette;
INSERT INTO RateEmesse(numero,ordine,data,importo,datapagamento) 
   VALUES (20010,101,'2018-01-15',250,'2018-02-10');
INSERT INTO RateEmesse(numero,ordine,data,importo,datapagamento) 
   VALUES (20011,101,'2018-04-15',100,'2018-05-20');
INSERT INTO RateEmesse(numero,ordine,data,importo,datapagamento) 
   VALUES (20012,101,'2018-07-15',120,null);
INSERT INTO RateEmesse(numero,ordine,data,importo,datapagamento) 
   VALUES (20021,102,'2018-04-15',130,'2018-05-02');
INSERT INTO RateEmesse(numero,ordine,data,importo,datapagamento) 
   VALUES (20022,102,'2018-07-15',120,'2018-08-03');



