--
-- ER/Studio Data Architect 11.0 SQL Code Generation
-- Company :      Berkeley Seismological Laboratory
-- Project :      CISN/ANSS Parametric Information
-- Author :       Stephane Zuzlewski
--
-- Date Created : Thursday, June 18, 2015 14:44:53
-- Target DBMS : Oracle 11g
--

DROP TABLE amp CASCADE CONSTRAINTS
;
DROP TABLE ampset CASCADE CONSTRAINTS
;
DROP TABLE ampsettypes CASCADE CONSTRAINTS
;
DROP TABLE arrival CASCADE CONSTRAINTS
;
DROP TABLE assocamm CASCADE CONSTRAINTS
;
DROP TABLE assocamo CASCADE CONSTRAINTS
;
DROP TABLE assocaro CASCADE CONSTRAINTS
;
DROP TABLE assoccom CASCADE CONSTRAINTS
;
DROP TABLE assoccoo CASCADE CONSTRAINTS
;
DROP TABLE assocevampset CASCADE CONSTRAINTS
;
DROP TABLE assoctypecat CASCADE CONSTRAINTS
;
DROP TABLE coda CASCADE CONSTRAINTS
;
DROP TABLE event CASCADE CONSTRAINTS
;
DROP TABLE eventcategory CASCADE CONSTRAINTS
;
DROP TABLE eventprefmag CASCADE CONSTRAINTS
;
DROP TABLE eventprefmec CASCADE CONSTRAINTS
;
DROP TABLE eventprefor CASCADE CONSTRAINTS
;
DROP TABLE eventtype CASCADE CONSTRAINTS
;
DROP TABLE mec CASCADE CONSTRAINTS
;
DROP TABLE mecchannel CASCADE CONSTRAINTS
;
DROP TABLE mecdata CASCADE CONSTRAINTS
;
DROP TABLE mecfreq CASCADE CONSTRAINTS
;
DROP TABLE mecfreqdata CASCADE CONSTRAINTS
;
DROP TABLE mecobject CASCADE CONSTRAINTS
;
DROP TABLE netmag CASCADE CONSTRAINTS
;
DROP TABLE origin CASCADE CONSTRAINTS
;
DROP TABLE origin_error CASCADE CONSTRAINTS
;
DROP TABLE remark CASCADE CONSTRAINTS
;
DROP TABLE "remark origin" CASCADE CONSTRAINTS
;
DROP SEQUENCE AMPSEQ
;
DROP SEQUENCE ARSEQ
;
DROP SEQUENCE COMMSEQ
;
DROP SEQUENCE COSEQ
;
DROP SEQUENCE EVSEQ
;
DROP SEQUENCE MAGSEQ
;
DROP SEQUENCE MECDATASEQ
;
DROP SEQUENCE MECFREQSEQ
;
DROP SEQUENCE MECSEQ
;
DROP SEQUENCE ORSEQ
;
-- 
-- SEQUENCE: AMPSEQ 
--

CREATE SEQUENCE AMPSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- SEQUENCE: ARSEQ 
--

CREATE SEQUENCE ARSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- SEQUENCE: COMMSEQ 
--

CREATE SEQUENCE COMMSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- SEQUENCE: COSEQ 
--

CREATE SEQUENCE COSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- SEQUENCE: EVSEQ 
--

CREATE SEQUENCE EVSEQ
    START WITH 60000000
    INCREMENT BY 1
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- SEQUENCE: MAGSEQ 
--

CREATE SEQUENCE MAGSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- SEQUENCE: MECDATASEQ 
--

CREATE SEQUENCE MECDATASEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    NOORDER
;


-- 
-- SEQUENCE: MECFREQSEQ 
--

CREATE SEQUENCE MECFREQSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    NOORDER
;


-- 
-- SEQUENCE: MECSEQ 
--

CREATE SEQUENCE MECSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- SEQUENCE: ORSEQ 
--

CREATE SEQUENCE ORSEQ
    START WITH 2
    INCREMENT BY 5
    NOMINVALUE
    NOMAXVALUE
    CACHE 20
    ORDER
;


-- 
-- TABLE: amp 
--

CREATE TABLE amp(
    ampid         NUMBER(15, 0)     NOT NULL,
    commid        NUMBER(15, 0),
    datetime      NUMBER(25, 10),
    sta           VARCHAR2(6)       NOT NULL,
    net           VARCHAR2(8),
    auth          VARCHAR2(15)      NOT NULL,
    subsource     VARCHAR2(8),
    channel       VARCHAR2(8),
    channelsrc    VARCHAR2(8),
    seedchan      VARCHAR2(3),
    location      VARCHAR2(2),
    iphase        VARCHAR2(8),
    amplitude     BINARY_DOUBLE     NOT NULL,
    amptype       VARCHAR2(8),
    units         VARCHAR2(4)       NOT NULL,
    ampmeas       VARCHAR2(1),
    eramp         NUMBER(5, 3),
    flagamp       VARCHAR2(4),
    per           NUMBER(10, 4),
    snr           BINARY_DOUBLE,
    tau           NUMBER(9, 4),
    quality       NUMBER(2, 1),
    rflag         VARCHAR2(2),
    cflag         VARCHAR2(2),
    wstart        BINARY_DOUBLE     NOT NULL,
    duration      BINARY_DOUBLE,
    lddate        DATE              DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT ampkey01 PRIMARY KEY (ampid)
)
TABLESPACE PI000
;



-- 
-- TABLE: ampset 
--

CREATE TABLE ampset(
    ampsetid    NUMBER           NOT NULL,
    ampid       NUMBER(15, 0)    NOT NULL,
    CONSTRAINT ampsetkey01 PRIMARY KEY (ampsetid, ampid)
)
;



-- 
-- TABLE: ampsettypes 
--

CREATE TABLE ampsettypes(
    ampsettype     VARCHAR2(20)    NOT NULL,
    description    VARCHAR2(80),
    CONSTRAINT ampsettypeskey01 PRIMARY KEY (ampsettype)
)
;



-- 
-- TABLE: arrival 
--

CREATE TABLE arrival(
    arid          NUMBER(15, 0)     NOT NULL,
    commid        NUMBER(15, 0),
    datetime      NUMBER(25, 10)    NOT NULL,
    sta           VARCHAR2(6)       NOT NULL,
    net           VARCHAR2(8),
    auth          VARCHAR2(15)      NOT NULL,
    subsource     VARCHAR2(8),
    channel       VARCHAR2(8),
    channelsrc    VARCHAR2(8),
    seedchan      VARCHAR2(3),
    location      VARCHAR2(2),
    iphase        VARCHAR2(8),
    qual          VARCHAR2(1),
    clockqual     VARCHAR2(1),
    clockcorr     NUMBER(15, 0),
    ccset         VARCHAR2(1),
    fm            VARCHAR2(2),
    ema           NUMBER(5, 2),
    azimuth       NUMBER(4, 1),
    slow          NUMBER(8, 4),
    deltim        NUMBER(5, 2),
    delinc        NUMBER(4, 2),
    delaz         NUMBER(5, 2),
    delslo        NUMBER(8, 4),
    quality       NUMBER(3, 2),
    snr           BINARY_DOUBLE,
    rflag         VARCHAR2(2),
    lddate        DATE              DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT arkey01 PRIMARY KEY (arid)
)
TABLESPACE PI000
;



-- 
-- TABLE: assocamm 
--

CREATE TABLE assocamm(
    magid         NUMBER(15, 0)    NOT NULL,
    ampid         NUMBER(15, 0)    NOT NULL,
    commid        NUMBER(15, 0),
    auth          VARCHAR2(15)     NOT NULL,
    subsource     VARCHAR2(8),
    weight        NUMBER(4, 3),
    in_wgt        NUMBER(4, 3),
    mag           NUMBER(5, 2),
    magres        NUMBER(5, 2),
    magcorr       NUMBER(5, 2),
    importance    NUMBER(4, 3),
    rflag         VARCHAR2(2),
    lddate        DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT assocammkey01 PRIMARY KEY (magid, ampid)
)
TABLESPACE PI000
;



-- 
-- TABLE: assocamo 
--

CREATE TABLE assocamo(
    orid         NUMBER(15, 0)    NOT NULL,
    ampid        NUMBER(15, 0)    NOT NULL,
    commid       NUMBER(15, 0),
    auth         VARCHAR2(15)     NOT NULL,
    subsource    VARCHAR2(8),
    delta        NUMBER(9, 4),
    seaz         NUMBER(4, 1),
    rflag        VARCHAR2(2),
    lddate       DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT assocamokey01 PRIMARY KEY (orid, ampid)
)
TABLESPACE PI000
;



-- 
-- TABLE: assocaro 
--

CREATE TABLE assocaro(
    orid          NUMBER(15, 0)    NOT NULL,
    arid          NUMBER(15, 0)    NOT NULL,
    commid        NUMBER(15, 0),
    auth          VARCHAR2(15)     NOT NULL,
    subsource     VARCHAR2(8),
    iphase        VARCHAR2(8),
    importance    NUMBER(4, 3),
    delta         NUMBER(9, 4),
    seaz          NUMBER(4, 1),
    in_wgt        NUMBER(4, 3),
    wgt           NUMBER(4, 3),
    timeres       NUMBER(5, 2),
    ema           NUMBER(5, 2),
    slow          NUMBER(8, 4),
    vmodelid      NUMBER(3, 0),
    scorr         NUMBER(6, 4),
    sdelay        NUMBER(7, 4),
    rflag         VARCHAR2(2),
    ccset         VARCHAR2(1),
    lddate        DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT assocarokey01 PRIMARY KEY (orid, arid)
)
TABLESPACE PI000
;



-- 
-- TABLE: assoccom 
--

CREATE TABLE assoccom(
    magid        NUMBER(15, 0)    NOT NULL,
    coid         NUMBER(15, 0)    NOT NULL,
    commid       NUMBER(15, 0),
    auth         VARCHAR2(15)     NOT NULL,
    subsource    VARCHAR2(8),
    weight       NUMBER(4, 3),
    in_wgt       NUMBER(4, 3),
    mag          NUMBER(7, 4),
    magres       NUMBER(7, 4),
    magcorr      NUMBER(7, 4),
    rflag        VARCHAR2(2),
    lddate       DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT assoccomkey01 PRIMARY KEY (magid, coid)
)
TABLESPACE PI000
;



-- 
-- TABLE: assoccoo 
--

CREATE TABLE assoccoo(
    orid         NUMBER(15, 0)    NOT NULL,
    coid         NUMBER(15, 0)    NOT NULL,
    commid       NUMBER(15, 0),
    auth         VARCHAR2(15)     NOT NULL,
    subsource    VARCHAR2(8),
    delta        NUMBER(9, 4),
    seaz         NUMBER(7, 4),
    rflag        VARCHAR2(2),
    lddate       DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT assoccookey01 PRIMARY KEY (orid, coid)
)
TABLESPACE PI000
;



-- 
-- TABLE: assocevampset 
--

CREATE TABLE assocevampset(
    ampsetid      NUMBER           NOT NULL,
    ampsettype    VARCHAR2(20)     NOT NULL,
    evid          NUMBER(15, 0)    NOT NULL,
    subsource     VARCHAR2(8)      NOT NULL,
    isvalid       NUMBER           NOT NULL,
    lddate        DATE             DEFAULT (cast(sys_extract_utc(systimestamp)asdate)),
    CONSTRAINT assocevampsetkey01 PRIMARY KEY (ampsetid, ampsettype)
)
;



-- 
-- TABLE: assoctypecat 
--

CREATE TABLE assoctypecat(
    etype    VARCHAR2(2)    NOT NULL,
    catid    NUMBER         NOT NULL,
    CONSTRAINT AssocTypeCatKey01 PRIMARY KEY (etype, catid)
)
;



-- 
-- TABLE: coda 
--

CREATE TABLE coda(
    coid          NUMBER(15, 0)     NOT NULL,
    commid        NUMBER(15, 0),
    sta           VARCHAR2(6)       NOT NULL,
    net           VARCHAR2(8),
    auth          VARCHAR2(15)      NOT NULL,
    subsource     VARCHAR2(8),
    channel       VARCHAR2(8),
    channelsrc    VARCHAR2(8),
    seedchan      VARCHAR2(3),
    location      VARCHAR2(2),
    codatype      VARCHAR2(3),
    afix          NUMBER(7, 4),
    afree         NUMBER(7, 4),
    qfix          NUMBER(7, 4),
    qfree         NUMBER(7, 4),
    tau           NUMBER(7, 4),
    nsample       NUMBER(6, 0),
    rms           NUMBER(5, 3),
    durtype       VARCHAR2(3),
    iphase        VARCHAR2(8),
    eramp         NUMBER(5, 3),
    units         VARCHAR2(4)       NOT NULL,
    time1         NUMBER(10, 0),
    amp1          NUMBER(10, 0),
    time2         NUMBER(10, 0),
    amp2          NUMBER(10, 0),
    time3         NUMBER(10, 0),
    amp3          NUMBER(10, 0),
    time4         NUMBER(10, 0),
    amp4          NUMBER(10, 0),
    time5         NUMBER(10, 0),
    amp5          NUMBER(10, 0),
    time6         NUMBER(10, 0),
    amp6          NUMBER(10, 0),
    quality       NUMBER(3, 2),
    datetime      NUMBER(25, 10)    NOT NULL,
    algorithm     VARCHAR2(15),
    winsize       NUMBER(7, 4),
    rflag         VARCHAR2(2),
    lddate        DATE              DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT codakey01 PRIMARY KEY (coid)
)
TABLESPACE PI000
;



-- 
-- TABLE: event 
--

CREATE TABLE event(
    evid          NUMBER(15, 0)    NOT NULL,
    prefor        NUMBER(15, 0),
    prefmag       NUMBER(15, 0),
    prefmec       NUMBER(15, 0),
    commid        NUMBER(15, 0),
    auth          VARCHAR2(15)     NOT NULL,
    subsource     VARCHAR2(8),
    etype         VARCHAR2(2)      NOT NULL,
    selectflag    NUMBER(1, 0),
    lddate        DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    version       NUMBER(3, 0)     DEFAULT (0) NOT NULL,
    CONSTRAINT evkey01 PRIMARY KEY (evid)
)
TABLESPACE PI000
;



-- 
-- TABLE: eventcategory 
--

CREATE TABLE eventcategory(
    catid          NUMBER          NOT NULL,
    category       VARCHAR2(25)    NOT NULL,
    description    VARCHAR2(80),
    CONSTRAINT EvCatKey01 PRIMARY KEY (catid)
)
;



-- 
-- TABLE: eventprefmag 
--

CREATE TABLE eventprefmag(
    magtype    VARCHAR2(6)      NOT NULL,
    evid       NUMBER(15, 0)    NOT NULL,
    magid      NUMBER(15, 0)    NOT NULL,
    lddate     DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT EventPrefMag_PK PRIMARY KEY (magtype, evid)
)
;



-- 
-- TABLE: eventprefmec 
--

CREATE TABLE eventprefmec(
    mechtype    VARCHAR2(2)      NOT NULL,
    evid        NUMBER(15, 0)    NOT NULL,
    mecid       NUMBER(15, 0),
    lddate      DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT EventPrefMec_PK PRIMARY KEY (mechtype, evid)
)
;



-- 
-- TABLE: eventprefor 
--

CREATE TABLE eventprefor(
    type      VARCHAR2(2)      NOT NULL,
    evid      NUMBER(15, 0)    NOT NULL,
    orid      NUMBER(15, 0)    NOT NULL,
    lddate    DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT EventPrefOr_PK PRIMARY KEY (type, evid)
)
;



-- 
-- TABLE: eventtype 
--

CREATE TABLE eventtype(
    etype          VARCHAR2(2)     NOT NULL,
    name           VARCHAR2(16)    NOT NULL,
    description    VARCHAR2(80),
    CONSTRAINT EVENTTYPEKEY01 PRIMARY KEY (etype)
)
;



-- 
-- TABLE: mec 
--

CREATE TABLE mec(
    mecid          NUMBER(15, 0)     NOT NULL,
    oridin         NUMBER(15, 0),
    oridout        NUMBER(15, 0),
    magid          NUMBER(15, 0),
    commid         NUMBER(15, 0),
    mechtype       VARCHAR2(2),
    mecalgo        VARCHAR2(15),
    scalar         BINARY_DOUBLE,
    erscalar       BINARY_DOUBLE,
    tft            VARCHAR2(8),
    tfd            BINARY_DOUBLE,
    mxx            BINARY_DOUBLE,
    myy            BINARY_DOUBLE,
    mzz            BINARY_DOUBLE,
    mxy            BINARY_DOUBLE,
    mxz            BINARY_DOUBLE,
    myz            BINARY_DOUBLE,
    smxx           BINARY_DOUBLE,
    smyy           BINARY_DOUBLE,
    smzz           BINARY_DOUBLE,
    smxy           BINARY_DOUBLE,
    smxz           BINARY_DOUBLE,
    smyz           BINARY_DOUBLE,
    srcduration    NUMBER(6, 3),
    auth           VARCHAR2(15)      NOT NULL,
    subsource      VARCHAR2(8),
    strike1        NUMBER(3, 0),
    dip1           NUMBER(3, 0),
    rake1          NUMBER(4, 0),
    strike2        NUMBER(3, 0),
    dip2           NUMBER(2, 0),
    rake2          NUMBER(4, 0),
    unstrike1      NUMBER(6, 3),
    undip1         NUMBER(5, 3),
    unrake1        NUMBER(6, 3),
    unstrike2      NUMBER(6, 3),
    undip2         NUMBER(5, 3),
    unrake2        NUMBER(6, 3),
    eigenp         BINARY_DOUBLE,
    plungep        NUMBER(2, 0),
    strikep        NUMBER(3, 0),
    eigenn         BINARY_DOUBLE,
    plungen        NUMBER(2, 0),
    striken        NUMBER(3, 0),
    eigent         BINARY_DOUBLE,
    plunget        NUMBER(2, 0),
    striket        NUMBER(3, 0),
    nsta           NUMBER(5, 0),
    pvr            NUMBER(5, 0),
    quality        NUMBER(2, 1),
    pdc            NUMBER(3, 0),
    pclvd          NUMBER(3, 0),
    piso           NUMBER(3, 0),
    datetime       NUMBER(25, 10)    NOT NULL,
    rflag          VARCHAR2(2),
    lddate         DATE              DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT meckey01 PRIMARY KEY (mecid)
)
TABLESPACE PI000
;



-- 
-- TABLE: mecchannel 
--

CREATE TABLE mecchannel(
    mecdataid    NUMBER(15, 0)    NOT NULL,
    net          VARCHAR2(8)      NOT NULL,
    sta          VARCHAR2(6)      NOT NULL,
    seedchan     VARCHAR2(3)      NOT NULL,
    location     VARCHAR2(2)      NOT NULL,
    CONSTRAINT MecChannel_PK PRIMARY KEY (mecdataid, net, sta, seedchan, location)
)
;



-- 
-- TABLE: mecdata 
--

CREATE TABLE mecdata(
    mecdataid      NUMBER(15, 0)     NOT NULL,
    mecid          NUMBER(15, 0),
    mecfreqid      NUMBER(15, 0),
    polarity       VARCHAR2(2),
    discrepancy    VARCHAR2(1),
    orientation    VARCHAR2(1),
    quality        NUMBER(3, 2),
    amplitude      FLOAT(126),
    phase          FLOAT(126),
    time1          NUMBER(25, 10),
    time2          NUMBER(25, 10),
    model          VARCHAR2(10),
    zcor           NUMBER(5, 0),
    corlen         NUMBER(5, 0),
    dt             NUMBER(11, 5),
    varred         NUMBER(4, 1),
    lddate         DATE              DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT MecData_PK PRIMARY KEY (mecdataid)
)
;



-- 
-- TABLE: mecfreq 
--

CREATE TABLE mecfreq(
    mecfreqid    NUMBER(15, 0)    NOT NULL,
    mecalgo      VARCHAR2(15),
    lddate       DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT MecFreq_PK PRIMARY KEY (mecfreqid)
)
;



-- 
-- TABLE: mecfreqdata 
--

CREATE TABLE mecfreqdata(
    mecfreqid    NUMBER(15, 0)    NOT NULL,
    type         VARCHAR2(15)     NOT NULL,
    freq         NUMBER(15, 6)    NOT NULL,
    CONSTRAINT MecFreqData_PK PRIMARY KEY (mecfreqid, type)
)
;



-- 
-- TABLE: mecobject 
--

CREATE TABLE mecobject(
    dataid      NUMBER(15, 0)    NOT NULL,
    mecid       NUMBER(15, 0)    NOT NULL,
    mimetype    VARCHAR2(20),
    data        BLOB,
    meta        VARCHAR2(128),
    CONSTRAINT MecObject_PK PRIMARY KEY (dataid, mecid)
)
;



-- 
-- TABLE: netmag 
--

CREATE TABLE netmag(
    magid          NUMBER(15, 0)    NOT NULL,
    orid           NUMBER(15, 0)    NOT NULL,
    commid         NUMBER(15, 0),
    magnitude      NUMBER(5, 2)     NOT NULL,
    magtype        VARCHAR2(6)      NOT NULL,
    auth           VARCHAR2(15)     NOT NULL,
    subsource      VARCHAR2(8),
    magalgo        VARCHAR2(15),
    nsta           NUMBER(5, 0),
    nobs           NUMBER(5, 0),
    uncertainty    NUMBER(5, 3),
    gap            NUMBER(4, 1),
    distance       NUMBER(7, 3),
    quality        NUMBER(2, 1),
    rflag          VARCHAR2(2),
    lddate         DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT magkey01 PRIMARY KEY (magid)
)
TABLESPACE PI000
;



-- 
-- TABLE: origin 
--

CREATE TABLE origin(
    orid           NUMBER(15, 0)     NOT NULL,
    evid           NUMBER(15, 0)     NOT NULL,
    prefmag        NUMBER(15, 0),
    prefmec        NUMBER(15, 0),
    commid         NUMBER(15, 0),
    bogusflag      NUMBER(1, 0)      DEFAULT (0) NOT NULL,
    datetime       NUMBER(25, 10)    NOT NULL,
    lat            NUMBER(9, 7)      NOT NULL,
    lon            NUMBER(10, 7)     NOT NULL,
    depth          NUMBER(7, 3),
    mdepth         NUMBER(7, 3),
    type           VARCHAR2(2),
    algorithm      VARCHAR2(15),
    algo_assoc     VARCHAR2(80),
    auth           VARCHAR2(15)      NOT NULL,
    subsource      VARCHAR2(8),
    datumhor       VARCHAR2(8),
    datumver       VARCHAR2(8),
    gap            NUMBER(4, 1),
    distance       NUMBER(7, 3),
    wrms           NUMBER(5, 3),
    stime          NUMBER(6, 3),
    erhor          NUMBER(7, 3),
    sdep           NUMBER(7, 3),
    erlat          NUMBER(7, 3),
    erlon          NUMBER(7, 3),
    totalarr       NUMBER(5, 0),
    totalamp       NUMBER(6, 0),
    ndef           NUMBER(5, 0),
    nbs            NUMBER(4, 0),
    nbfm           NUMBER(4, 0),
    locevid        VARCHAR2(12),
    quality        NUMBER(2, 1),
    fdepth         VARCHAR2(1),
    fepi           VARCHAR2(1),
    ftime          VARCHAR2(1),
    vmodelid       VARCHAR2(2),
    cmodelid       VARCHAR2(2),
    rflag          VARCHAR2(2),
    crust_type     VARCHAR2(1),
    crust_model    VARCHAR2(3),
    gtype          VARCHAR2(1),
    lddate         DATE              DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT orkey01 PRIMARY KEY (orid)
)
TABLESPACE PI000
;



-- 
-- TABLE: origin_error 
--

CREATE TABLE origin_error(
    orid        NUMBER(15, 0)    NOT NULL,
    sxx         NUMBER(7, 3),
    syy         NUMBER(7, 3),
    szz         NUMBER(7, 3),
    stt         NUMBER(7, 3),
    sxy         NUMBER(7, 3),
    sxz         NUMBER(7, 3),
    syz         NUMBER(7, 3),
    stx         NUMBER(7, 3),
    sty         NUMBER(7, 3),
    stz         NUMBER(7, 3),
    azismall    NUMBER(5, 2),
    dipsmall    NUMBER(4, 2),
    magsmall    NUMBER(7, 5),
    aziinter    NUMBER(5, 2),
    dipinter    NUMBER(4, 2),
    maginter    NUMBER(7, 5),
    azilarge    NUMBER(5, 2),
    diplarge    NUMBER(4, 2),
    maglarge    NUMBER(7, 5),
    lddate      DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT orerrkey01 PRIMARY KEY (orid)
)
TABLESPACE PI000
;



-- 
-- TABLE: remark 
--

CREATE TABLE remark(
    commid    NUMBER(15, 0)    NOT NULL,
    lineno    NUMBER(15, 0)    NOT NULL,
    remark    VARCHAR2(80),
    lddate    DATE             DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
    CONSTRAINT remkey01 PRIMARY KEY (commid, lineno)
)
TABLESPACE PI000
;



-- 
-- TABLE: "remark origin" 
--

CREATE TABLE "remark origin"(
    lineno    NUMBER(15, 0)    NOT NULL,
    commid    NUMBER(15, 0)    NOT NULL,
    orid      NUMBER(15, 0)    NOT NULL,
    CONSTRAINT PK60 PRIMARY KEY (lineno, commid, orid)
)
;



-- 
-- INDEX: EvCat01 
--

DROP INDEX EvCat01
;

CREATE UNIQUE INDEX EvCat01 ON eventcategory(category)
;
-- 
-- INDEX: EVENTTYPE01 
--

DROP INDEX EVENTTYPE01
;

CREATE UNIQUE INDEX EVENTTYPE01 ON eventtype(name)
;
-- 
-- TABLE: ampset 
--

ALTER TABLE ampset ADD CONSTRAINT Refamp981 
    FOREIGN KEY (ampid)
    REFERENCES amp(ampid)
;


-- 
-- TABLE: assocamm 
--

ALTER TABLE assocamm ADD CONSTRAINT Aam_Amp 
    FOREIGN KEY (ampid)
    REFERENCES amp(ampid)
;

ALTER TABLE assocamm ADD CONSTRAINT Aam_Net 
    FOREIGN KEY (magid)
    REFERENCES netmag(magid)
;


-- 
-- TABLE: assocamo 
--

ALTER TABLE assocamo ADD CONSTRAINT Amo_Amp 
    FOREIGN KEY (ampid)
    REFERENCES amp(ampid)
;

ALTER TABLE assocamo ADD CONSTRAINT Amo_Ori 
    FOREIGN KEY (orid)
    REFERENCES origin(orid)
;


-- 
-- TABLE: assocaro 
--

ALTER TABLE assocaro ADD CONSTRAINT Aao_Arr 
    FOREIGN KEY (arid)
    REFERENCES arrival(arid)
;

ALTER TABLE assocaro ADD CONSTRAINT Aao_Ori 
    FOREIGN KEY (orid)
    REFERENCES origin(orid)
;


-- 
-- TABLE: assoccom 
--

ALTER TABLE assoccom ADD CONSTRAINT Aom_Cod 
    FOREIGN KEY (coid)
    REFERENCES coda(coid)
;

ALTER TABLE assoccom ADD CONSTRAINT Aom_Net 
    FOREIGN KEY (magid)
    REFERENCES netmag(magid)
;


-- 
-- TABLE: assoccoo 
--

ALTER TABLE assoccoo ADD CONSTRAINT Aco_Cod 
    FOREIGN KEY (coid)
    REFERENCES coda(coid)
;

ALTER TABLE assoccoo ADD CONSTRAINT Aco_Ori 
    FOREIGN KEY (orid)
    REFERENCES origin(orid)
;


-- 
-- TABLE: assocevampset 
--

ALTER TABLE assocevampset ADD CONSTRAINT Refevent1021 
    FOREIGN KEY (evid)
    REFERENCES event(evid)
;

ALTER TABLE assocevampset ADD CONSTRAINT assocevampsetkey02 
    FOREIGN KEY (ampsettype)
    REFERENCES ampsettypes(ampsettype)
;


-- 
-- TABLE: assoctypecat 
--

ALTER TABLE assoctypecat ADD CONSTRAINT Refeventcategory831 
    FOREIGN KEY (catid)
    REFERENCES eventcategory(catid)
;

ALTER TABLE assoctypecat ADD CONSTRAINT Refeventtype841 
    FOREIGN KEY (etype)
    REFERENCES eventtype(etype)
;


-- 
-- TABLE: event 
--

ALTER TABLE event ADD CONSTRAINT Refeventtype851 
    FOREIGN KEY (etype)
    REFERENCES eventtype(etype)
;

ALTER TABLE event ADD CONSTRAINT Eve_Mec 
    FOREIGN KEY (prefmec)
    REFERENCES mec(mecid)
;

ALTER TABLE event ADD CONSTRAINT Eve_Net 
    FOREIGN KEY (prefmag)
    REFERENCES netmag(magid)
;

ALTER TABLE event ADD CONSTRAINT Eve_Ori 
    FOREIGN KEY (prefor)
    REFERENCES origin(orid)
;


-- 
-- TABLE: eventprefmag 
--

ALTER TABLE eventprefmag ADD CONSTRAINT Epm_Eve 
    FOREIGN KEY (evid)
    REFERENCES event(evid)
;

ALTER TABLE eventprefmag ADD CONSTRAINT Epm_Net 
    FOREIGN KEY (magid)
    REFERENCES netmag(magid)
;


-- 
-- TABLE: eventprefmec 
--

ALTER TABLE eventprefmec ADD CONSTRAINT Refevent701 
    FOREIGN KEY (evid)
    REFERENCES event(evid)
;

ALTER TABLE eventprefmec ADD CONSTRAINT Refmec711 
    FOREIGN KEY (mecid)
    REFERENCES mec(mecid)
;


-- 
-- TABLE: eventprefor 
--

ALTER TABLE eventprefor ADD CONSTRAINT Refevent1081 
    FOREIGN KEY (evid)
    REFERENCES event(evid)
;

ALTER TABLE eventprefor ADD CONSTRAINT Reforigin1091 
    FOREIGN KEY (orid)
    REFERENCES origin(orid)
;


-- 
-- TABLE: mec 
--

ALTER TABLE mec ADD CONSTRAINT Mec_Net 
    FOREIGN KEY (magid)
    REFERENCES netmag(magid)
;

ALTER TABLE mec ADD CONSTRAINT Mec_Ori 
    FOREIGN KEY (oridin)
    REFERENCES origin(orid)
;

ALTER TABLE mec ADD CONSTRAINT Mec_Ori2 
    FOREIGN KEY (oridout)
    REFERENCES origin(orid)
;


-- 
-- TABLE: mecchannel 
--

ALTER TABLE mecchannel ADD CONSTRAINT MecChannel_FK01 
    FOREIGN KEY (mecdataid)
    REFERENCES mecdata(mecdataid)
;


-- 
-- TABLE: mecdata 
--

ALTER TABLE mecdata ADD CONSTRAINT Refmec731 
    FOREIGN KEY (mecid)
    REFERENCES mec(mecid)
;

ALTER TABLE mecdata ADD CONSTRAINT MecData_FK02 
    FOREIGN KEY (mecfreqid)
    REFERENCES mecfreq(mecfreqid)
;


-- 
-- TABLE: mecfreqdata 
--

ALTER TABLE mecfreqdata ADD CONSTRAINT MecFreqData_FK01 
    FOREIGN KEY (mecfreqid)
    REFERENCES mecfreq(mecfreqid)
;


-- 
-- TABLE: mecobject 
--

ALTER TABLE mecobject ADD CONSTRAINT Refmec761 
    FOREIGN KEY (mecid)
    REFERENCES mec(mecid)
;


-- 
-- TABLE: netmag 
--

ALTER TABLE netmag ADD CONSTRAINT Net_Ori 
    FOREIGN KEY (orid)
    REFERENCES origin(orid)
;


-- 
-- TABLE: origin 
--

ALTER TABLE origin ADD CONSTRAINT Ori_Eve 
    FOREIGN KEY (evid)
    REFERENCES event(evid)
;

ALTER TABLE origin ADD CONSTRAINT Ori_Mec 
    FOREIGN KEY (prefmec)
    REFERENCES mec(mecid)
;

ALTER TABLE origin ADD CONSTRAINT Ori_Net 
    FOREIGN KEY (prefmag)
    REFERENCES netmag(magid)
;


-- 
-- TABLE: origin_error 
--

ALTER TABLE origin_error ADD CONSTRAINT Ori__Err_Ori 
    FOREIGN KEY (orid)
    REFERENCES origin(orid)
;


-- 
-- TABLE: "remark origin" 
--

ALTER TABLE "remark origin" ADD CONSTRAINT Refremark1111 
    FOREIGN KEY (commid, lineno)
    REFERENCES remark(commid, lineno)
;

ALTER TABLE "remark origin" ADD CONSTRAINT Reforigin1121 
    FOREIGN KEY (orid)
    REFERENCES origin(orid)
;


