CREATE DATABASE "..\Programs\DB_Interbase_6\Demo.gdb" 
USER "sysdba" PASSWORD "masterkey";

CREATE DOMAIN GUID AS CHAR(38);

CREATE TABLE EDI_ELEMENT_PROFILE
(
                       SEGMENTID              VARCHAR(     3) CHARACTER SET ASCII NOT NULL,
                       ELEMENTID              VARCHAR(     4) CHARACTER SET ASCII NOT NULL,
                    ELEMENTCOUNT              INTEGER         DEFAULT 0 NOT NULL,
                     ELEMENTTYPE              VARCHAR(    12) CHARACTER SET ASCII DEFAULT 'AN' NOT NULL,
                   MAXIMUMLENGTH              INTEGER         DEFAULT 1 NOT NULL,
 CONSTRAINT PK_EDI_ELEMENT_PROFILE PRIMARY KEY (SEGMENTID, ELEMENTID)
);

CREATE TABLE EDI_LOOP_PROFILE
(
                     OWNERLOOPID              VARCHAR(    12) CHARACTER SET ASCII NOT NULL,
                    PARENTLOOPID              VARCHAR(    12) CHARACTER SET ASCII NOT NULL,
 CONSTRAINT PK_EDI_LOOP_PROFILE PRIMARY KEY (OWNERLOOPID, PARENTLOOPID)
);

CREATE TABLE EDI_SEGMENT_PROFILE
(
                       SEGMENTID              VARCHAR(     3) CHARACTER SET ASCII NOT NULL,
                     OWNERLOOPID              VARCHAR(    12) CHARACTER SET ASCII DEFAULT 'N/A' NOT NULL,
                    PARENTLOOPID              VARCHAR(    12) CHARACTER SET ASCII DEFAULT 'N/A' NOT NULL,
 CONSTRAINT PK_EDI_SEGMENT_PROFILE PRIMARY KEY (SEGMENTID)
);

GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON EDI_ELEMENT_PROFILE TO USER SYSDBA;
GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON EDI_LOOP_PROFILE TO USER SYSDBA;
GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON EDI_SEGMENT_PROFILE TO USER SYSDBA;
