DDL informix

DDL informix

CREATE TABLE galmacen (
    almid serial not null,
    codigo char(6) not null,
    nomalm varchar(40) not null,
    tercer char(12) not null,
    tipdir char(6) default '0' not null,
    empcode char(4) not null,
    agrupa char(4) not null,
    recint char(6) not null,
    delega char(6),
    depart char(6),
    codpre char(10),
    stkneg smallint default 0 not null,
    stkrup char(1) default 'N' not null,
    tipval char(1) not null,
    cosuni char(1) default 'N' not null,
    costol smallint default 0 not null,
    fecval date not null,
    aplven smallint default 0 not null,
    indlot smallint default 1 not null,
    disdel smallint default 0 not null,
    reflec int,
    capdes decimal(11,3) default 0.000 not null,
    horini smallint default 0 not null,
    horfin smallint default 0 not null,
    tippro char(4),
    impre1 char(10),
    impre2 char(10),
    tipast char(4),
    fecalt date default today not null,
    fecbaj date,
    fecult date not null,
    feccon date,
    inipot smallint,
    estado char(1) not null,
    errnum smallint default 0 not null,
    wkfnum smallint,
    auxchr1 char(1),
    auxchr2 char(1),
    auxchr3 char(1),
    auxchr4 char(1),
    auxchr5 char(1),
    auxfec1 date,
    auxfec2 date,
    auxnum1 smallint,
    auxnum2 smallint,
    auxnum3 smallint,
    user_created char(20) default user not null,
    date_created datetime year to second default current year to second not null,
    user_updated char(20) default user not null,
    date_updated datetime year to second default current year to second not null
      ,CHECK (
    (tipval IN ('F', 'L', 'M', 'N'))
 )
     CONSTRAINT c_galmacen1
      ,CHECK (
    (cosuni IN ('S', 'N'))
 )
     CONSTRAINT c_galmacen2
      ,CHECK (
    (feccon IS NULL OR feccon <= fecval)
 )
     CONSTRAINT c_galmacen3
      ,CHECK (
    (feccon IS NULL OR
    (feccon IS NOT NULL AND tipast IS NOT NULL))
 )
     CONSTRAINT c_galmacen4
      ,CHECK (
    (fecbaj IS NULL OR fecalt <= fecbaj)
 )
     CONSTRAINT c_galmacen5
      ,CHECK (
    (horini <= horfin)
 )
     CONSTRAINT c_galmacen6
      ,CHECK (
    ((horini BETWEEN 0 AND 23) AND (horfin BETWEEN 0 AND 23))
 )
     CONSTRAINT c_galmacen7
      ,CHECK (
    (costol = 0 OR (costol > 0 AND tipval = 'M'))
 )
     CONSTRAINT c_galmacen8
      ,CHECK (
    errnum = 0 OR (errnum != 0 AND estado = 'B')
 )
     CONSTRAINT c_galmacen9
      ,CHECK (
    wkfnum IS NULL OR (wkfnum IS NOT NULL AND errnum != 0)
 )
     CONSTRAINT c_galmacen10
      ,CHECK (
      stkrup IN ('N', 'G', 'Z')
 )
     CONSTRAINT c_galmacen11
);
ALTER TABLE galmacen LOCK MODE (ROW);

CREATE UNIQUE INDEX u_galmacen1 ON galmacen(almid);
ALTER TABLE galmacen
 ADD CONSTRAINT  UNIQUE (almid)
 CONSTRAINT u_galmacen1;

-- Index to avoid automatic named by database (named with pk name).
CREATE UNIQUE INDEX p_galmacen ON galmacen(codigo);
ALTER TABLE galmacen
 ADD CONSTRAINT
 PRIMARY KEY (codigo)
 CONSTRAINT p_galmacen;

CREATE  INDEX f_galmacen1 ON galmacen(tercer);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (tercer)
 REFERENCES ctercero(codigo)
 CONSTRAINT f_galmacen1;

CREATE  INDEX f_galmacen2 ON galmacen(tipast);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (tipast)
 REFERENCES gconasih(codigo)
 CONSTRAINT f_galmacen2;

CREATE  INDEX f_galmacen3 ON galmacen(agrupa);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (agrupa)
 REFERENCES gagrupac(codigo)
 CONSTRAINT f_galmacen3;

CREATE  INDEX f_galmacen4 ON galmacen(delega,depart);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (delega,depart)
 REFERENCES gdeparta(delega,depart)
 CONSTRAINT f_galmacen4;

CREATE  UNIQUE  INDEX f_galmacen5 ON galmacen(tercer,tipdir);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (tercer,tipdir)
 REFERENCES cterdire(codigo,tipdir)
 CONSTRAINT f_galmacen5;

CREATE  INDEX f_galmacen6 ON galmacen(recint);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (recint)
 REFERENCES galmreci(codigo)
 CONSTRAINT f_galmacen6;

CREATE  INDEX f_galmacen7 ON galmacen(empcode);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (empcode)
 REFERENCES cempresa(empcode)
 CONSTRAINT f_galmacen7;

CREATE  INDEX f_galmacen8 ON galmacen(tippro);
ALTER TABLE galmacen
 ADD CONSTRAINT  FOREIGN KEY (tippro)
 REFERENCES gmovprod(codigo)
 CONSTRAINT f_galmacen8;