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

Posted

技术标签:

【中文标题】我应该如何处理 mysql 触发器中字段列表中未知的“Col_name”列?【英文标题】:What should I do with the unknown 'Col_name' column in field list in mysql trigger? 【发布时间】:2021-08-23 17:00:45 【问题描述】:

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 无法为插入或删除创建触发器,所以我为每个创建了一个。

这是我的触发代码:


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 ;

我想在 bookinglog 表中记录从预订表中插入或删除的数据。

执行插入或删除时,会出现这些错误。

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

我认为触发代码中的语法有问题

【问题讨论】:

检查是否区分大小写,插入列列表中的列名。尝试“Booking_CheckInDate”而不是“booking_checkindate” @Suchitra 我已经检查了一遍又一遍。但我找不到任何问题。 【参考方案1】:

这是一件非常简单的事情。我应该在 insert into 中写 'bookinglog' 作为表名,但我写的是 'roomstate'。

【讨论】:

以上是关于我应该如何处理 mysql 触发器中字段列表中未知的“Col_name”列?的主要内容,如果未能解决你的问题,请参考以下文章

C getline() - 如何处理缓冲区/如何将未知数量的值读入数组

如何处理未知的 UILabel 高度及其对 Interface Builder 中标签下方的影响?

如何处理语义分割中未知类的平均交集(mIOU)?

当朋友在 PHP/MySQL 应用程序中忽略某人时,我应该如何处理?

如何处理角度5递归未知确切数字路由器参数?

如何处理版本列表中包含的字符串导致的错误,按StrictVersion排序?