Create Trigger / Stored Procedure Mysql to change characteristics of a column

2

I'm trying to create a Trigger / Stored Function for when the user changes the value of a column from 0 to 1 it changes the characteristic of another column

CREATE TABLE 'aluno' (
  'CPF_ALU' varchar(11) NOT NULL,
  'PRIORIDADE' tinyint(1) NOT NULL,
  'CURSO' int(4) NOT NULL,
  'ANO_ENTRADA' int(4) NOT NULL,
  'SEMESTRE_ENTRADA' int(1) NOT NULL,
  'TURNO' varchar(7) NOT NULL,
  'MONITOR' tinyint(1) NOT NULL,
  'VOLUNTARIO' tinyint(1) NOT NULL,
  'BOLSISTA' tinyint(1) NOT NULL,
  'DESISTIU' tinyint(1) NOT NULL,
  'MEDIA_GERAL' float DEFAULT NULL,
  'PROJETO_C_BOLSA' int(4) DEFAULT NULL,
  'VALOR_BOLSA' float DEFAULT NULL,
  'ORIENTADOR_TCC' varchar(11) DEFAULT NULL,
  PRIMARY KEY ('CPF_ALU'),
  KEY 'fk_curso_aluno_idx' ('CURSO'),
  KEY 'fk_orientador_tcc_idx' ('ORIENTADOR_TCC'),
  KEY 'fk_projeto_c_bolsa_idx' ('PROJETO_C_BOLSA'),
  CONSTRAINT 'fk_cpf_aluno' FOREIGN KEY ('CPF_ALU') REFERENCES 'pessoa' ('CPF_P') ON DELETE NO ACTION ON UPDATE CASCADE,
  CONSTRAINT 'fk_curso_aluno' FOREIGN KEY ('CURSO') REFERENCES 'curso' ('ID') ON DELETE NO ACTION ON UPDATE CASCADE,
  CONSTRAINT 'fk_orientador_tcc' FOREIGN KEY ('ORIENTADOR_TCC') REFERENCES 'professor' ('CPF_PROF') ON DELETE NO ACTION ON UPDATE CASCADE,
  CONSTRAINT 'fk_projeto_c_bolsa' FOREIGN KEY ('PROJETO_C_BOLSA') REFERENCES 'projeto' ('CODIGO') ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

This script in the student table, in the case when the user sets the stock column value to 1 (true) it would change the PROJETO_C_BOLSA and VALOR_BOLSA to NOT NULL .

DELIMITER $$
CREATE PROCEDURE alterarAluno ()
BEGIN
    START transaction;
        ALTER TABLE deinfo.aluno 
        CHANGE COLUMN PROJETO_C_BOLSA PROJETO_C_BOLSA INT(4) NOT NULL ,
        CHANGE COLUMN VALOR_BOLSA VALOR_BOLSA FLOAT NOT NULL ;
    COMMIT;
END $$
DELIMITER ;


DELIMITER $$
CREATE trigger configurarAlunoBolsistaInsert
before insert on deinfo.aluno for each row
begin
    if (new.bolsista = 1) then
        CALL deinfo.alterarAluno();
    end if;

end $$

DELIMITER ;

DELIMITER $$
CREATE trigger configurarAlunoBolsistaUpdate
before update on aluno for each row
begin
    if (new.bolsista = 1) then
        CALL deinfo.alterarAluno();
    end if;

end $$

DELIMITER ;

I created these Triggers / Procedure to make it work however when I try to update a row of the student table it returns me this error:

UPDATE 'aluno' SET 'BOLSISTA'='1', 'PROJETO_C_BOLSA'='1', 'VALOR_BOLSA'='400' WHERE 'CPF_ALU'='14114631887' 1422: Explicit or implicit commit is not allowed in stored function or trigger. 

Someone could give me some help.

I'm using MySQL57, I've read the documentation but found nothing that could help me in this regard.

    
asked by anonymous 17.06.2016 / 04:42

0 answers