Jump to content
Sign in to follow this  
alphasil

Erro num Trigger

Recommended Posts

alphasil

Olá;

Estou com problema na criação de um trigger da minha base de dados, dá erro

tenho esta tabela

CREATE TABLE `reserva` (
 `id_reserva` int(11) NOT NULL AUTO_INCREMENT,
 `id_sala` int(11) NOT NULL,
 `id_utilizador` int(11) NOT NULL,
 `id_material` int(11) NOT NULL,
 `inicio` datetime NOT NULL,
 `fim` datetime NOT NULL,
 `data_reserva` datetime NOT NULL,
 `id_funcionario` int(11) DEFAULT NULL,
 `data_entrega` datetime DEFAULT NULL,
 PRIMARY KEY (`id_reserva`),
 KEY `fk_reserva_sala` (`id_sala`),
 KEY `fk_reserva_docente1` (`id_utilizador`),
 KEY `FK_reserva_material` (`id_material`),
 KEY `FK_reserva_func` (`id_funcionario`),
 CONSTRAINT `FK_reserva` FOREIGN KEY (`id_sala`) REFERENCES `sala` (`id_sala`),
 CONSTRAINT `FK_reserva_func` FOREIGN KEY (`id_funcionario`) REFERENCES `funcionario` (`id_funcionario`),
 CONSTRAINT `FK_reserva_material` FOREIGN KEY (`id_material`) REFERENCES `material` (`id_material`),
 CONSTRAINT `FK_reserva_utili` FOREIGN KEY (`id_utilizador`) REFERENCES `utilizador` (`id_utilizador`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;

E quero usar este trigger de datas

CREATE TRIGGER t1
BEFORE INSERT ON reserva
FOR EACH ROW
BEGIN
 IF (NEW.inicio > NEW.fim)
 set msg = 'DIE: data de início não pode ser maior que a data de fim';
 SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'exemplo';
 END IF
END;

Error Code : 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON `reserva_salas`.`reserva`

FOR EACH ROW BEGIN

if(New.inicio > NEW.fim)' at line 4

Execution Time : 00:00:00:000

Transfer Time : 00:00:00:000

Total Time : 00:00:00:000

Alguma dica se faz favor?

Obrigado

Edited by alphasil

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.