/*	PRAK		*/

CREATE TABLE PRAK
(
IDPRAK	   INTEGER NOT NULL,
IDKSIAZKI  INTEGER NOT NULL,
IDAUTORA   INTEGER NOT NULL,
CONSTRAINT PRAK_PK PRIMARY KEY(IDPRAK)
);

ALTER TABLE PRAK add constraint PRAK_FK_IDKSIAZKI FOREIGN KEY(IDKSIAZKI) references KSIAZKI(idksiazki)
ON DELETE NO ACTION;

ALTER TABLE PRAK add constraint PRAK_FK_IDAUTORA FOREIGN KEY(IDAUTORA) references AUTORZY(idautora)
ON DELETE NO ACTION;

CREATE GENERATOR G_PRAK;
SET GENERATOR G_PRAK TO -1;

SET TERM ^ ;

CREATE TRIGGER T_PRAK FOR PRAK
ACTIVE BEFORE INSERT
POSITION 0
AS  
BEGIN
   NEW.IDPRAK = GEN_ID(G_PRAK, 1);
END
^

SET TERM ; ^

select * from PRAK;
