CREATE TABLE doc_fej
(
  kod serial NOT NULL,
  azonosito character(3),
  nev character varying(120),
  leiras character varying(200),
  hasznalatban smallint DEFAULT 0,
  alapertelmezett smallint DEFAULT 0,
  fejlec smallint DEFAULT 0,
  fejlec_kapcsolodik smallint DEFAULT 0,
  a5_meretu smallint DEFAULT 0,
  CONSTRAINT doc_fej_pkey PRIMARY KEY (kod)
)
WITHOUT OIDS;


CREATE TABLE doc
(
  kod serial NOT NULL,
  lap smallint,
  rtf bytea,
  fej_kod integer,
  megjegyzes character varying(40),
  CONSTRAINT doc_pkey PRIMARY KEY (kod),
  CONSTRAINT doc_fk1 FOREIGN KEY (fej_kod)
      REFERENCES doc_fej (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE,
  CONSTRAINT doc_ch1 CHECK (lap >= 1 AND lap <= 10)
)
WITHOUT OIDS;

CREATE TABLE doc_var
(
  kod serial NOT NULL,
  fej_kod integer,
  var_id smallint,
  var_nev character varying(120),
  var_type character(10),
  var_len integer,
  var_variablename character varying(120),
  var_default character varying(200),
  var_combo text,
  CONSTRAINT doc_var_pkey PRIMARY KEY (kod),
  CONSTRAINT doc_var_fk1 FOREIGN KEY (fej_kod)
      REFERENCES doc_fej (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE
)
WITHOUT OIDS;