CREATE TABLE CODIGOS (
    NRO_CODIGO   INTEGER NOT NULL,
    NOMBRE       VARCHAR(100)  NOT NULL,
    IMPORTE      NUMERIC(15,2)  NOT NULL,
    INACTIVO       BOOLEAN  NOT NULL,
    NRO_CARRERA  INTEGER  NOT NULL,
    DESCUENTO    NUMERIC(15,2)  NOT NULL,
    CONTADO      BOOLEAN  NOT NULL,
    CONSTANCIA   BOOLEAN NOT NULL
);
-----
ALTER TABLE CODIGOS ADD CONSTRAINT PK_CODIGOS PRIMARY KEY (NRO_CODIGO);
-----
ALTER TABLE CODIGOS ADD CONSTRAINT FK_CODIGOS_CARRERAS FOREIGN KEY (NRO_CARRERA) REFERENCES CARRERAS (NRO_CARRERA);
-----
CREATE OR ALTER TRIGGER CODIGOS_BI FOR CODIGOS
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.NRO_CODIGO IS NULL) THEN BEGIN
    NEW.NRO_CODIGO = GEN_ID(ORDEN_GEN, 1);
  END
  NEW.INACTIVO = FALSE;
END
