 COMMENT ON COLUMN MMP.CODES.VALUE
   IS 'The value for the code';
 
-ALTER TABLE MMP.CODES ADD CONSTRAINT FK_CODES_CODE_CATEGORY FOREIGN KEY (CATEGORY_ID) REFERENCES CODE_CATEGORIES(ID) ON DELETE CASCADE;
+ALTER TABLE MMP.CODES ADD CONSTRAINT FK_CODES_CODE_CATEGORY FOREIGN KEY (CATEGORY_ID) REFERENCES MMP.CODE_CATEGORIES(ID) ON DELETE CASCADE;
 
 
 

  FUNCTION_ID  INTEGER NOT NULL,

  PRIMARY KEY (GROUP_ID, FUNCTION_ID),
  CONSTRAINT EXTERNAL_FUNCTION_GROUP_MAP_GROUP_FK FOREIGN KEY (GROUP_ID) REFERENCES EXTERNAL_GROUPS(ID) ON DELETE CASCADE,
  CONSTRAINT EXTERNAL_FUNCTION_GROUP_MAP_FUNCTION_FK FOREIGN KEY (FUNCTION_ID) REFERENCES FUNCTIONS(ID) ON DELETE CASCADE
);

CREATE INDEX EXTERNAL_FUNCTION_GROUP_MAP_ID_IX

  ORGANISATION_ID  INTEGER NOT NULL,

  PRIMARY KEY (USER_ID, ORGANISATION_ID),
  CONSTRAINT USER_ORGANISATION_MAP_USER_FK FOREIGN KEY (USER_ID) REFERENCES MMP.USERS(ID) ON DELETE CASCADE,
  CONSTRAINT USER_ORGANISATION_MAP_ORGANISATION_FK FOREIGN KEY (ORGANISATION_ID) REFERENCES MMP.ORGANISATIONS(ID) ON DELETE CASCADE
);

CREATE INDEX USER_ORGANISATION_MAP_USER_ID_IX
