Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump parcelavendas #7

Closed
thiagogomesverissimo opened this issue Oct 23, 2020 · 0 comments
Closed

dump parcelavendas #7

thiagogomesverissimo opened this issue Oct 23, 2020 · 0 comments
Assignees

Comments

@thiagogomesverissimo
Copy link
Member

CREATE TABLE PARCELASVENDAS (
  ID DMID NOT NULL,
  IDVENDA DMID NOT NULL,
  NUMERO INTEGER,
  DATAVENCTO DMDATA,
  VALOR DMNUMERICO,
  STATUS VARCHAR(10) CHARACTER SET ISO8859_1 COLLATE ISO8859_1,
  USUARIO DMUSUARIO,
  DHINCLUSAO DMDHINCLUSAO,
  DHMODIFICACAO DMDHMODIFICACAO,
  "CHECK" DMBOLEANO);


ALTER TABLE PARCELASVENDAS ADD CONSTRAINT PK_PARCELASVENDAS PRIMARY KEY (ID);

ALTER TABLE PARCELASVENDAS ADD CONSTRAINT FK_PARCELASVENDASVENDAS FOREIGN KEY (IDVENDA) REFERENCES VENDAS(ID) ON DELETE CASCADE ON UPDATE CASCADE;


SET TERM ^ ;

CREATE TRIGGER PARCELASVENDAS_BI FOR PARCELASVENDAS
ACTIVE BEFORE INSERT
POSITION 1
AS
BEGIN
  IF (NOT EXISTS(SELECT ID FROM PARCELASVENDAS WHERE ID = NEW.ID
  AND IDVENDA = NEW.IDVENDA AND "CHECK" = 'N')) THEN
  BEGIN
    IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(PARCELASVENDAS_ID_GEN, 1);
    NEW.DHINCLUSAO = 'NOW';
    NEW.DHMODIFICACAO = 'NOW';
    NEW."CHECK" = 'N';
  END
  ELSE
    EXCEPTION REGISTROJAEXISTE;
END^

CREATE TRIGGER PARCELASVENDAS_BU FOR PARCELASVENDAS
ACTIVE BEFORE UPDATE
POSITION 1
AS
BEGIN
  NEW.DHMODIFICACAO = 'NOW';
END^
SET TERM ; ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant