-- Generated by Oracle SQL Developer Data Modeler 3.1.4.710
--   at:        2015-03-15 23:10:32 CET
--   site:      Oracle Database 11g
--   type:      Oracle Database 11g



CREATE TABLESPACE STUDENTS2014 
    LOGGING 
    ONLINE 
    PERMANENT 
    EXTENT MANAGEMENT LOCAL AUTOALLOCATE 
    FLASHBACK ON 
;

CREATE USER NEUMANN 
    IDENTIFIED BY  
    ACCOUNT UNLOCK 
;

CREATE TABLE NEUMANN.ATTACK 
    ( 
     ID_ATTACK INTEGER  NOT NULL , 
     STATUS INTEGER  NOT NULL , 
     ATTACK_DATE TIMESTAMP  NOT NULL , 
     PEOPLE_KILLED INTEGER , 
     PEOPLE_INJURED INTEGER , 
     ID_TARGET INTEGER  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.ATTACK 
    ADD CONSTRAINT ATTACK_PK PRIMARY KEY ( ID_ATTACK ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.ATTACK_HAS_GROUP 
    ( 
     ID_ATTACK INTEGER  NOT NULL , 
     ID_GROUP INTEGER  NOT NULL 
    ) 
    LOGGING 
;




CREATE TABLE NEUMANN.ATTACK_HAS_PEOPLE 
    ( 
     ID_ATTACK INTEGER  NOT NULL , 
     ID_PEOPLE INTEGER  NOT NULL 
    ) 
    LOGGING 
;




CREATE TABLE NEUMANN.ATTACK_HAS_WEAPON 
    ( 
     ID_ATTACK INTEGER  NOT NULL , 
     ID_WEAPON NUMBER (10)  NOT NULL 
    ) 
    LOGGING 
;




CREATE TABLE NEUMANN.ATTACK_STATUS 
    ( 
     ID_ATTACK_STATUS INTEGER  NOT NULL , 
     NAME VARCHAR2 (45 BYTE) , 
     ATTACK_ID_ATTACK INTEGER  NOT NULL , 
     ATTACK_ID_ATTACK1 INTEGER  NOT NULL 
    ) 
    LOGGING 
;



ALTER TABLE NEUMANN.ATTACK_STATUS 
    ADD CONSTRAINT ATTACK_STATUS_PK PRIMARY KEY ( ID_ATTACK_STATUS ) ;



CREATE TABLE NEUMANN.COUNTRY 
    ( 
     ID_GROUP NUMBER (10)  NOT NULL , 
     NAME VARCHAR2 (45 BYTE) , 
     ISO VARCHAR2 (45 BYTE) , 
     PHONE_PREFIX VARCHAR2 (45 BYTE) , 
     ID_COUNTRY INTEGER  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.COUNTRY 
    ADD CONSTRAINT COUNTRY_PK PRIMARY KEY ( ID_COUNTRY ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.EMAIL 
    ( 
     ID_IDENTITY INTEGER  NOT NULL , 
     EMAIL VARCHAR2 (45 BYTE) 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;




CREATE TABLE NEUMANN.GROUP_HAS_ENEMY 
    ( 
     ID_GROUP INTEGER  NOT NULL , 
     ID_COUNTRY INTEGER  NOT NULL 
    ) 
    LOGGING 
;




CREATE TABLE NEUMANN.GROUP_HAS_WEAPON 
    ( 
     ID_GROUP INTEGER  NOT NULL , 
     ID_WEAPON NUMBER (10)  NOT NULL , 
     EXPECTED_QUANTITY UNKNOWN 
--  ERROR: Datatype UNKNOWN is not allowed 
                    
    ) 
    LOGGING 
;




CREATE TABLE NEUMANN.IDENTITY 
    ( 
     ID_IDENTITY INTEGER  NOT NULL , 
     NAME VARCHAR2 (45 BYTE) , 
     SURNAME VARCHAR2 (45 BYTE) , 
     DESCRIPTION VARCHAR2 (45 BYTE) , 
     MAIN NUMBER (3) , 
     ID_PEOPLE INTEGER  NOT NULL , 
     ID_COUNTRY INTEGER  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.IDENTITY 
    ADD CONSTRAINT IDENTITY_PK PRIMARY KEY ( ID_IDENTITY ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.PEOPLE 
    ( 
     ID_PEOPLE INTEGER  NOT NULL , 
     HIGH VARCHAR2 (45 BYTE) , 
     EYES_COLOR VARCHAR2 (45 BYTE) 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.PEOPLE 
    ADD CONSTRAINT PEOPLE_PK PRIMARY KEY ( ID_PEOPLE ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.PEOPLE_HAS_CELL 
    ( 
     ID_CELL INTEGER  NOT NULL , 
     ID_PEOPLE INTEGER  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;




CREATE TABLE NEUMANN.PHONE 
    ( 
     ID_IDENTITY INTEGER  NOT NULL , 
     PHONE_NUMBER INTEGER , 
     ID_COUNTRY NUMBER (10)  NOT NULL , 
     COUNTRY_ID_COUNTRY INTEGER  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;




CREATE TABLE NEUMANN.RELIGION 
    ( 
     ID_RELIGION INTEGER  NOT NULL , 
     NAME VARCHAR2 (45 BYTE) , 
     ID_RELIGION_GROUP NUMBER (10)  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.RELIGION 
    ADD CONSTRAINT RELIGION_PK PRIMARY KEY ( ID_RELIGION ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.RELIGION_GROUP 
    ( 
     ID_RELIGION_GROUP NUMBER (10)  NOT NULL , 
     NAME VARCHAR2 (45 BYTE) 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.RELIGION_GROUP 
    ADD CONSTRAINT RELIGION_GROUP_PK PRIMARY KEY ( ID_RELIGION_GROUP ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.TARGET 
    ( 
     ID_TARGET INTEGER  NOT NULL , 
     NAME VARCHAR2 (45 BYTE) , 
     GPS_X BINARY_DOUBLE , 
     GPS_Y BINARY_DOUBLE , 
     EXISTING NUMBER (3) , 
     STATIC CHAR (1) , 
     CIVILIAN CHAR (1) , 
     ID_TOWN NUMBER  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.TARGET 
    ADD CONSTRAINT TARGET_PK PRIMARY KEY ( ID_TARGET ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.TER_CELL 
    ( 
     ID_CELL INTEGER  NOT NULL , 
     NAME VARCHAR2 (45 BYTE) , 
     ID_TOWN NUMBER  NOT NULL , 
     ID_GROUP INTEGER  NOT NULL , 
     ID_LEADER INTEGER  NOT NULL 
    ) 
    LOGGING 
;



ALTER TABLE NEUMANN.TER_CELL 
    ADD CONSTRAINT TER_CELL_PK PRIMARY KEY ( ID_CELL ) ;



CREATE TABLE NEUMANN.TER_GROUP 
    ( 
     ID_GROUP INTEGER  NOT NULL , 
     NAME VARCHAR2 (45 BYTE)  NOT NULL , 
     ABBR VARCHAR2 (15 BYTE) , 
     DANGEROUS VARCHAR2 (45 BYTE) , 
     STATUS VARCHAR2 (45 BYTE) , 
     ID_RELIGION INTEGER  NOT NULL , 
     ID_COUNTRY INTEGER  NOT NULL , 
     ID_LEADER INTEGER  NOT NULL 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.TER_GROUP 
    ADD CONSTRAINT TER_GROUP_PK PRIMARY KEY ( ID_GROUP ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;



CREATE TABLE NEUMANN.TOWN 
    ( 
     ID_TOWN NUMBER  NOT NULL , 
     ORIG_NAME VARCHAR2 , 
     ENG_NAME VARCHAR2 , 
     CAPITAL CHAR (1) , 
     ID_COUNTRY INTEGER  NOT NULL 
    ) 
    LOGGING 
;



ALTER TABLE NEUMANN.TOWN 
    ADD CONSTRAINT TOWN_PK PRIMARY KEY ( ID_TOWN ) ;



CREATE TABLE NEUMANN.WEAPON 
    ( 
     ID_WEAPON NUMBER (10)  NOT NULL , 
     NAME VARCHAR2 (45 BYTE)  NOT NULL , 
     POWER NUMBER (10) , 
     RANGE NUMBER (10) , 
     ACCURACY NUMBER (10) 
    ) 
        PCTFREE 10 
        PCTUSED 40 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) 
;



ALTER TABLE NEUMANN.WEAPON 
    ADD CONSTRAINT WEAPON_PK PRIMARY KEY ( ID_WEAPON ) 
    USING INDEX 
        PCTFREE 10 
        INITRANS 2 
        MAXTRANS 255 
        TABLESPACE STUDENTS2014 
        LOGGING 
        STORAGE ( 
        PCTINCREASE 0 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        FREELISTS 1 
        FREELIST GROUPS 1 
        BUFFER_POOL DEFAULT 
    ) ;




ALTER TABLE NEUMANN.ATTACK_HAS_GROUP 
    ADD CONSTRAINT ATACK_HAS_GROUP_ATTACK_FK FOREIGN KEY 
    ( 
     ID_ATTACK
    ) 
    REFERENCES NEUMANN.ATTACK 
    ( 
     ID_ATTACK
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.ATTACK_HAS_GROUP 
    ADD CONSTRAINT ATACK_HAS_GROUP_GROUP_FK FOREIGN KEY 
    ( 
     ID_GROUP
    ) 
    REFERENCES NEUMANN.TER_GROUP 
    ( 
     ID_GROUP
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.ATTACK_HAS_PEOPLE 
    ADD CONSTRAINT ATACK_HAS_PEOPLE_ATTACK_FK FOREIGN KEY 
    ( 
     ID_ATTACK
    ) 
    REFERENCES NEUMANN.ATTACK 
    ( 
     ID_ATTACK
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.ATTACK_HAS_PEOPLE 
    ADD CONSTRAINT ATACK_HAS_PEOPLE_PEOPLE_FK FOREIGN KEY 
    ( 
     ID_PEOPLE
    ) 
    REFERENCES NEUMANN.PEOPLE 
    ( 
     ID_PEOPLE
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.ATTACK_HAS_WEAPON 
    ADD CONSTRAINT ATTACK_HAS_WEAPON_ATTACK_FK FOREIGN KEY 
    ( 
     ID_ATTACK
    ) 
    REFERENCES NEUMANN.ATTACK 
    ( 
     ID_ATTACK
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.ATTACK_HAS_WEAPON 
    ADD CONSTRAINT ATTACK_HAS_WEAPON_WEAPON_FK FOREIGN KEY 
    ( 
     ID_WEAPON
    ) 
    REFERENCES NEUMANN.WEAPON 
    ( 
     ID_WEAPON
    ) 
    NOT DEFERRABLE 
;


-- Error - Foreign Key ATTACK_STATUS_ATTACK_FK has no columns

ALTER TABLE NEUMANN.ATTACK_STATUS 
    ADD CONSTRAINT ATTACK_STATUS_ATTACK_FK FOREIGN KEY 
    ( 
     ATTACK_ID_ATTACK1
    ) 
    REFERENCES NEUMANN.ATTACK 
    ( 
     ID_ATTACK
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.ATTACK 
    ADD CONSTRAINT ATTACK_TARGET_FK FOREIGN KEY 
    ( 
     ID_TARGET
    ) 
    REFERENCES NEUMANN.TARGET 
    ( 
     ID_TARGET
    ) 
    NOT DEFERRABLE 
;


-- Error - Foreign Key COUNTRY_TER_GROUP_FK has no columns

ALTER TABLE NEUMANN.EMAIL 
    ADD CONSTRAINT EMAIL_IDENTITY_FK FOREIGN KEY 
    ( 
     ID_IDENTITY
    ) 
    REFERENCES NEUMANN.IDENTITY 
    ( 
     ID_IDENTITY
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.GROUP_HAS_ENEMY 
    ADD CONSTRAINT GROUP_HAS_ENEMY_COUNTRY_FK FOREIGN KEY 
    ( 
     ID_COUNTRY
    ) 
    REFERENCES NEUMANN.COUNTRY 
    ( 
     ID_COUNTRY
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.GROUP_HAS_ENEMY 
    ADD CONSTRAINT GROUP_HAS_ENEMY_GROUP_FK FOREIGN KEY 
    ( 
     ID_GROUP
    ) 
    REFERENCES NEUMANN.TER_GROUP 
    ( 
     ID_GROUP
    ) 
    NOT DEFERRABLE 
;



--  ERROR: FK name length exceeds maximum allowed length(30) 
ALTER TABLE NEUMANN.GROUP_HAS_WEAPON 
    ADD CONSTRAINT GROUP_HAS_WEAPONv1_TER_GROUP_FK FOREIGN KEY 
    ( 
     ID_GROUP
    ) 
    REFERENCES NEUMANN.TER_GROUP 
    ( 
     ID_GROUP
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.GROUP_HAS_WEAPON 
    ADD CONSTRAINT GROUP_HAS_WEAPONv1_WEAPON_FK FOREIGN KEY 
    ( 
     ID_WEAPON
    ) 
    REFERENCES NEUMANN.WEAPON 
    ( 
     ID_WEAPON
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.IDENTITY 
    ADD CONSTRAINT IDENTITY_COUNTRY_FK FOREIGN KEY 
    ( 
     ID_COUNTRY
    ) 
    REFERENCES NEUMANN.COUNTRY 
    ( 
     ID_COUNTRY
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.IDENTITY 
    ADD CONSTRAINT IDENTITY_PEOPLE_FK FOREIGN KEY 
    ( 
     ID_PEOPLE
    ) 
    REFERENCES NEUMANN.PEOPLE 
    ( 
     ID_PEOPLE
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.PEOPLE_HAS_CELL 
    ADD CONSTRAINT PEOPLE_HAS_CELL_PEOPLE_FK FOREIGN KEY 
    ( 
     ID_PEOPLE
    ) 
    REFERENCES NEUMANN.PEOPLE 
    ( 
     ID_PEOPLE
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.PEOPLE_HAS_CELL 
    ADD CONSTRAINT PEOPLE_HAS_CELL_TER_CELL_FK FOREIGN KEY 
    ( 
     ID_CELL
    ) 
    REFERENCES NEUMANN.TER_CELL 
    ( 
     ID_CELL
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.PHONE 
    ADD CONSTRAINT PHONE_COUNTRY_FK FOREIGN KEY 
    ( 
     COUNTRY_ID_COUNTRY
    ) 
    REFERENCES NEUMANN.COUNTRY 
    ( 
     ID_COUNTRY
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.PHONE 
    ADD CONSTRAINT PHONE_IDENTITY_FK FOREIGN KEY 
    ( 
     ID_IDENTITY
    ) 
    REFERENCES NEUMANN.IDENTITY 
    ( 
     ID_IDENTITY
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.RELIGION 
    ADD CONSTRAINT RELIGION_RELIGION_GROUP_FK FOREIGN KEY 
    ( 
     ID_RELIGION_GROUP
    ) 
    REFERENCES NEUMANN.RELIGION_GROUP 
    ( 
     ID_RELIGION_GROUP
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TARGET 
    ADD CONSTRAINT TARGET_town_FK FOREIGN KEY 
    ( 
     ID_TOWN
    ) 
    REFERENCES NEUMANN.TOWN 
    ( 
     ID_TOWN
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TER_CELL 
    ADD CONSTRAINT TER_CELL_PEOPLE_FK FOREIGN KEY 
    ( 
     ID_LEADER
    ) 
    REFERENCES NEUMANN.PEOPLE 
    ( 
     ID_PEOPLE
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TER_CELL 
    ADD CONSTRAINT TER_CELL_TER_GROUP_FK FOREIGN KEY 
    ( 
     ID_GROUP
    ) 
    REFERENCES NEUMANN.TER_GROUP 
    ( 
     ID_GROUP
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TER_GROUP 
    ADD CONSTRAINT TER_GROUP_COUNTRY_FK FOREIGN KEY 
    ( 
     ID_COUNTRY
    ) 
    REFERENCES NEUMANN.COUNTRY 
    ( 
     ID_COUNTRY
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TER_GROUP 
    ADD CONSTRAINT TER_GROUP_PEOPLE_FK FOREIGN KEY 
    ( 
     ID_LEADER
    ) 
    REFERENCES NEUMANN.PEOPLE 
    ( 
     ID_PEOPLE
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TER_GROUP 
    ADD CONSTRAINT TER_GROUP_RELIGION_FK FOREIGN KEY 
    ( 
     ID_RELIGION
    ) 
    REFERENCES NEUMANN.RELIGION 
    ( 
     ID_RELIGION
    ) 
    ON DELETE CASCADE 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TER_CELL 
    ADD CONSTRAINT TOWN_FK FOREIGN KEY 
    ( 
     ID_TOWN
    ) 
    REFERENCES NEUMANN.TOWN 
    ( 
     ID_TOWN
    ) 
    NOT DEFERRABLE 
;


ALTER TABLE NEUMANN.TOWN 
    ADD CONSTRAINT town_COUNTRY_FK FOREIGN KEY 
    ( 
     ID_COUNTRY
    ) 
    REFERENCES NEUMANN.COUNTRY 
    ( 
     ID_COUNTRY
    ) 
    NOT DEFERRABLE 
;

CREATE SEQUENCE NEUMANN.ATTACK_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.COUNTRY_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.GROUP_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.IDENTITY_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.PEOPLE_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.RELIGION_GROUP_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.RELIGION_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.TARGET_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE SEQUENCE NEUMANN.WEAPON_SEQ 
    INCREMENT BY 1 
    MAXVALUE 9999999999999999999999999999 
    MINVALUE 1 
    CACHE 20 
;

CREATE OR REPLACE TRIGGER NEUMANN.ATTACK_SEQ_TR 
    BEFORE INSERT ON NEUMANN.ATTACK 
    FOR EACH ROW 
    WHEN ( NEW.id_attack IS NULL ) 
BEGIN
 SELECT attack_seq.NEXTVAL INTO :NEW.id_attack FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.COUNTRY_SEQ_TR 
    BEFORE INSERT ON NEUMANN.COUNTRY 
    FOR EACH ROW 
    WHEN ( NEW.id_country IS NULL ) 
BEGIN
 SELECT country_seq.NEXTVAL INTO :NEW.id_country FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.GROUP_SEQ_TR 
    BEFORE INSERT ON NEUMANN.TER_GROUP 
    FOR EACH ROW 
    WHEN ( NEW.id_group IS NULL ) 
BEGIN
 SELECT group_seq.NEXTVAL INTO :NEW.id_group FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.IDENTITY_SEQ_TR 
    BEFORE INSERT ON NEUMANN.IDENTITY 
    FOR EACH ROW 
    WHEN ( NEW.id_identity IS NULL ) 
BEGIN
 SELECT identity_seq.NEXTVAL INTO :NEW.id_identity FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.PEOPLE_SEQ_TR 
    BEFORE INSERT ON NEUMANN.PEOPLE 
    FOR EACH ROW 
    WHEN ( NEW.id_people IS NULL ) 
BEGIN
 SELECT people_seq.NEXTVAL INTO :NEW.id_people FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.RELIGION_GROUP_SEQ_TR 
    BEFORE INSERT ON NEUMANN.RELIGION_GROUP 
    FOR EACH ROW 
    WHEN ( NEW.id_religion_group IS NULL ) 
BEGIN
 SELECT religion_group_seq.NEXTVAL INTO :NEW.id_religion_group FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.RELIGION_SEQ_TR 
    BEFORE INSERT ON NEUMANN.RELIGION 
    FOR EACH ROW 
    WHEN ( NEW.id_religion IS NULL ) 
BEGIN
 SELECT religion_seq.NEXTVAL INTO :NEW.id_religion FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.TARGET_SEQ_TR 
    BEFORE INSERT ON NEUMANN.TARGET 
    FOR EACH ROW 
    WHEN ( NEW.id_target IS NULL ) 
BEGIN
 SELECT target_seq.NEXTVAL INTO :NEW.id_target FROM DUAL;
END; 
/


CREATE OR REPLACE TRIGGER NEUMANN.WEAPON_SEQ_TR 
    BEFORE INSERT ON NEUMANN.WEAPON 
    FOR EACH ROW 
    WHEN ( NEW.id_weapon IS NULL ) 
BEGIN
 SELECT weapon_seq.NEXTVAL INTO :NEW.id_weapon FROM DUAL;
END; 
/




-- Oracle SQL Developer Data Modeler Summary Report: 
-- 
-- CREATE TABLE                            20
-- CREATE INDEX                             0
-- ALTER TABLE                             40
-- CREATE VIEW                              0
-- CREATE PACKAGE                           0
-- CREATE PACKAGE BODY                      0
-- CREATE PROCEDURE                         0
-- CREATE FUNCTION                          0
-- CREATE TRIGGER                           9
-- ALTER TRIGGER                            0
-- CREATE STRUCTURED TYPE                   0
-- CREATE COLLECTION TYPE                   0
-- CREATE CLUSTER                           0
-- CREATE CONTEXT                           0
-- CREATE DATABASE                          0
-- CREATE DIMENSION                         0
-- CREATE DIRECTORY                         0
-- CREATE DISK GROUP                        0
-- CREATE ROLE                              0
-- CREATE ROLLBACK SEGMENT                  0
-- CREATE SEQUENCE                          9
-- CREATE MATERIALIZED VIEW                 0
-- CREATE SYNONYM                           0
-- CREATE TABLESPACE                        1
-- CREATE USER                              1
-- 
-- DROP TABLESPACE                          0
-- DROP DATABASE                            0
-- 
-- ERRORS                                   4
-- WARNINGS                                 0
