简体   繁体   English

我应该如何处理 mysql 触发器中字段列表中的未知“Col_name”列?

[英]What should I do with the unknown 'Col_name' column in field list in mysql trigger?


CREATE TABLE Bookinglog #########ROOMSTATE LOG TABLE 
(
 `Bookinglog_ID` INT NOT NULL AUTO_INCREMENT , 
 `Booking_ID` INT NOT NULL , 
 `time_stamp` DATETIME(6) NOT NULL ,
 `Booking_CheckInDate` date NOT NULL , 
 `Booking_CheckOutDate` date NOT NULL COMMENT , 
 `Cust_ID` INT NOT NULL COMMENT , 
 `booking_totalamount` INT NULL COMMENT,
 `LOG` VARCHAR(1) NOT NULL,
 CONSTRAINT PRIMARY KEY (Bookinglog_ID)
);

Mysql couldn't create a trigger for insert or delete, so I created one for each. Mysql 无法为插入或删除创建触发器,因此我为每个触发器创建了一个。

This is my trigger code:这是我的触发代码:


select * from bookinglog;

drop table bookinglog;
drop trigger booking_trigger2;


############## Booking INSERT TRIGGER
delimiter $$ 
   create trigger Booking_trigger
    after insert on Booking
    for each row
    begin
      declare booking_id int;
      declare time_stamp timestamp;
      declare booking_checkindate date;
      declare booking_checkoutdate date;
      declare cust_id int;
      declare booking_totalamount int;
      declare log varchar(1);
      
      set booking_id = new.booking_id;
      set time_stamp = current_timestamp();
      set cust_id = new.cust_id;
      set booking_checkindate = new.booking_checkindate;
      set booking_checkoutdate = new.booking_checkoutdate;
      set booking_totalamount = new.booking_totalamount;
      set LOG = 'C';
      
      insert into roomstatelog(booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log) 
        value (booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log);
   end $$
delimiter ;

############## Booking DELETE TRIGGER
delimiter $$ 
   create trigger Booking_trigger2
    before delete on Booking
    for each row
    begin
      declare booking_id int;
      declare time_stamp timestamp;
      declare booking_checkindate date;
      declare booking_checkoutdate date;
      declare cust_id int;
      declare booking_totalamount int;
      declare log varchar(1);
      
      set booking_id = old.booking_id;
      set time_stamp = current_timestamp();
      set cust_id = old.cust_id;
      set booking_checkindate = old.booking_checkindate;
      set booking_checkoutdate = old.booking_checkoutdate;
      set booking_totalamount = old.booking_totalamount;
      set LOG = 'D';
      
      insert into roomstatelog(booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log) 
        value (booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log);
   end $$
delimiter ;

I want to log the data inserted or deleted from the reservation table in the bookinglog table.我想在 bookinglog 表中记录从预订表中插入或删除的数据。

When insert or delete is executed, these errors appear.执行插入或删除时,会出现这些错误。

Error Code: 1054. Unknown column 'booking_checkindate' in 'field list'

I think there is a problem with the syntax in the trigger code我认为触发代码中的语法有问题

It was a really simple matter.这是一件非常简单的事情。 I should write 'bookinglog' as the table name in insert into, but I wrote 'roomstate'.我应该在插入时写“bookinglog”作为表名,但我写了“roomstate”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM