错误1064-触发器创建期间“附近”的语法错误

时间:2020-07-13 01:03:13

标签: mysql sql

我收到此错误: 错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第7行的“''附近使用

关于以下查询:

DELIMITER //
create trigger UpdateTrigger 
    after update
        on reserva for each row
begin
IF NEW.reserva_valida = 0 THEN
    DELETE FROM companhia_aerea.venda 
    where companhia_aerea.venda = NEW.reserva_id;
END IF;
end;
DELIMITER ;

这就是我创建涉及的两个表的方式:

预订:

CREATE TABLE IF NOT EXISTS `companhia_aerea`.`reserva` (
  `reserva_id` INT NOT NULL AUTO_INCREMENT,
  `reserva_data_validade` DATE NOT NULL,
  `reserva_valida` TINYINT NOT NULL,
  `reserva_voo_id` INT NOT NULL,
  `reserva_venda_id` INT NOT NULL,
  PRIMARY KEY (`reserva_id`),
  INDEX `fk_reserva_voo1_idx` (`reserva_voo_id` ASC) VISIBLE,
  INDEX `fk_reserva_venda1_idx` (`reserva_venda_id` ASC) VISIBLE,
  CONSTRAINT `fk_reserva_voo1`
    FOREIGN KEY (`reserva_voo_id`)
    REFERENCES `companhia_aerea`.`voo` (`voo_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_reserva_venda1`
    FOREIGN KEY (`reserva_venda_id`)
    REFERENCES `companhia_aerea`.`venda` (`venda_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

VENDA:

DROP TABLE IF EXISTS companhia_aerea.venda;
CREATE TABLE IF NOT EXISTS `companhia_aerea`.`venda` (
  `venda_id` INT NOT NULL AUTO_INCREMENT,
  `reserva_id` INT NOT NULL,
  `venda_parcelas` INT NOT NULL,
  PRIMARY KEY (`venda_id`))
ENGINE = InnoDB;

1 个答案:

答案 0 :(得分:0)

您需要引用where的{​​{1}}子句中的列,而不是表。表别名将帮助:

delete