DROP TABLE EMPLOYEE_PROJECT;
DROP TABLE PROJECT;
DROP TABLE EMPLOYEE;
DROP TABLE DEPARTMENT;

CREATE TABLE DEPARTMENT (ID INTEGER NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID));
CREATE TABLE PROJECT (ID INTEGER NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID));
CREATE TABLE EMPLOYEE (ID INTEGER NOT NULL, NAME VARCHAR(255), STARTDATE DATE, SALARY BIGINT, 
                       DEPARTMENT_ID INTEGER, MANAGER_ID INTEGER, PRIMARY KEY (ID),
                       CONSTRAINT DEPARTMENT_FK FOREIGN KEY (DEPARTMENT_ID) REFERENCES DEPARTMENT (ID),
                       CONSTRAINT MANAGER_FK FOREIGN KEY (MANAGER_ID) REFERENCES EMPLOYEE (ID));
CREATE TABLE EMPLOYEE_PROJECT (PROJECTS_ID INTEGER NOT NULL, EMPLOYEES_ID INTEGER NOT NULL,
                               CONSTRAINT PROJECTS_FK FOREIGN KEY (PROJECTS_ID) REFERENCES PROJECT (ID),
                               CONSTRAINT EMPLOYEES_FK FOREIGN KEY (EMPLOYEES_ID) REFERENCES EMPLOYEE (ID),
                               PRIMARY KEY (PROJECTS_ID, EMPLOYEES_ID));


INSERT INTO DEPARTMENT (ID, NAME) VALUES (1, 'Engineering');
INSERT INTO DEPARTMENT (ID, NAME) VALUES (2, 'CA13');
INSERT INTO DEPARTMENT (ID, NAME) VALUES (3, 'CA19');

INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (1, 'Joan', 59000, {d '2003-04-16'},  1, NULL);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (2, 'Sarah', 52000, {d '2002-04-26'}, 2, 1);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (3, 'John', 55000, {d '2001-01-01'}, 2, 1);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (4, 'Roberts', 53000, {d '2001-05-23'}, 2, 1);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (5, 'Peter', 50000, {d '2002-08-06'}, 2, 1);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (6, 'Frank', 51000, {d '2003-02-17'}, 1, 2);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (7, 'Scott', 60000, {d '2004-11-14'}, 1, 2);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (8, 'Sue', 62000, {d '2005-08-18'}, 1, 2);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (9, 'Stephanie', 54000, {d '2006-06-07'}, 1, 2);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (10, 'Jennifer', 55000, {d '1999-08-11'}, 1, NULL);
INSERT INTO EMPLOYEE (ID, NAME, SALARY, STARTDATE, DEPARTMENT_ID, MANAGER_ID) VALUES (11, 'Marcus', 35000, {d '1995-07-22'}, NULL, NULL);

INSERT INTO PROJECT (ID, NAME) VALUES (1, 'Design Release2');
INSERT INTO PROJECT (ID, NAME) VALUES (2, 'Implement Release2');
INSERT INTO PROJECT (ID, NAME) VALUES (3, 'Test Release2');
INSERT INTO PROJECT (ID, NAME) VALUES (4, 'Release3');

INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (1, 1);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (2, 2);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (2, 3);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (3, 1);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (3, 2);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (3, 3);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (4, 1);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (5, 2);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (5, 3);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (6, 1);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (6, 2);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (7, 3);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (8, 1);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (8, 2);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (9, 3);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (9, 1);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (10, 1);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (10, 2);
INSERT INTO EMPLOYEE_PROJECT (EMPLOYEES_ID, PROJECTS_ID) VALUES (10, 3);