为什么它没有显示这样的专栏

发布于 2025-02-11 11:51:03 字数 961 浏览 0 评论 0原文

/* Triggers*/
create table acustomer( id integer primary key, desc text, last_order_id integer);
create table bcustomer ( id integer primary key, item_id int, customer_id int, quan int, price int);
insert into acustomer (desc) values ( 'rohan');
insert into acustomer (desc) values ('mohan');
insert into acustomer (desc) values ('sohan');
select * from acustomer;
create trigger ccustomer after insert on bcustomer
begin
    update acustomer set last_order_id = NEW.id where acustomer.id = NEW.customer_id;
end;
insert into bcustomer (item_id, customer_id, quan, price) values (1, 2, 3, 4);
insert into bcustomer (item_id, customer_id, quan, price) values (5, 6, 7, 8);
insert into bcustomer (item_id, customer_id, quan, price) values (8, 9, 10, 20);
insert into bcustomer (item_id, customer_id, quan, price) values (4, 12, 19, 13);

select * from acustomer;
select * from bcustomer;

#on在表Ccustomer中执行插入,它显示错误:无列:new.customer.id

/* Triggers*/
create table acustomer( id integer primary key, desc text, last_order_id integer);
create table bcustomer ( id integer primary key, item_id int, customer_id int, quan int, price int);
insert into acustomer (desc) values ( 'rohan');
insert into acustomer (desc) values ('mohan');
insert into acustomer (desc) values ('sohan');
select * from acustomer;
create trigger ccustomer after insert on bcustomer
begin
    update acustomer set last_order_id = NEW.id where acustomer.id = NEW.customer_id;
end;
insert into bcustomer (item_id, customer_id, quan, price) values (1, 2, 3, 4);
insert into bcustomer (item_id, customer_id, quan, price) values (5, 6, 7, 8);
insert into bcustomer (item_id, customer_id, quan, price) values (8, 9, 10, 20);
insert into bcustomer (item_id, customer_id, quan, price) values (4, 12, 19, 13);

select * from acustomer;
select * from bcustomer;

#On executing insertion in table ccustomer, it is showing error : no such column : NEW.customer.id

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画骨成沙 2025-02-18 11:51:03

您对 bcustomer 表的最后一个插入件是

insert into bcustomer (item_id, customer_id, quan, price) values (4, 12, 19, 13);

customer中没有任何匹配的 last_order_id

如果您将运行

insert into bcustomer (item_id, customer_id, quan, price) values (4, 1, 19, 13);

customer_id = 1 ,它将更新您的 customer 表,因为它具有匹配的ID,即 1

尝试此

Your last insert for bcustomer table is

insert into bcustomer (item_id, customer_id, quan, price) values (4, 12, 19, 13);

which doesn't have any matching last_order_id in acustomer.

If you will run

insert into bcustomer (item_id, customer_id, quan, price) values (4, 1, 19, 13);

customer_id = 1, it will update your acustomer table since it has a matching id, which is 1.

try this dbfiddle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文