drop database if exists emaille;
create database emaille;
\connect emaille

CREATE  TABLE person (
   nname text,
   vname text,
   id integer,
   PRIMARY KEY (id)
);

CREATE TABLE emaille (
   email text,
   person integer,
   FOREIGN KEY (person) REFERENCES person (id)
                        ON UPDATE CASCADE
			ON DELETE CASCADE
);

INSERT INTO person VALUES ('neumann', 'alfred e.', 42);
INSERT INTO emaille VALUES ('alfred@mad.org', 42);

--DELETE FROM person WHERE nname LIKE 'neu%';
--UPDATE person set id=420 WHERE id=42;
UPDATE emaille set person=4200 where person=42;

INSERT INTO person (nname, id) VALUES ('dienert', 100);
INSERT INTO person (id, vname) VALUES (200, 'hans');
INSERT INTO person (nname, id) VALUES ('nobody', 44);
INSERT INTO person VALUES ('neumann', 'johann von', 45);

SELECT * from person;
SELECT * from emaille;
