mysql 中每行的命令
Command FOR EACH ROW in mysql
帮我 please.I 想在 mysql 服务器中创建触发器,但服务器写信给我
SQL 查询:文档
CREATE TRIGGER `dis_out_of_stock` AFTER UPDATE ON `ps_stock_available`
FOR EACH ROW
begin
UPDATE `ps_product_shop` SET active=0 WHERE id_product IN (SELECT
id_product FROM `ps_stock_available` WHERE quantity=0);
MySQL 说:文档
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 '' at line 4
这是我的代码:
在 ps_stock_available
更新后创建触发器 dis_out_of_stock
每行
开始
更新ps_product_shop
SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available
WHERE quantity=0);
更新ps_product_shop
SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available
WHERE quantity>0);
结束
谢谢,祝你有愉快的一天。
- 您需要将
DELIMITER
重新定义为 ;
以外的其他内容,例如:$$
- 此外,使用
DROP TRIGGER IF EXISTS
. 检查触发器是否已经存在
- 最后,将
DELIMITER
重新定义为;
尝试:
DELIMITER $$
DROP TRIGGER IF EXISTS dis_out_of_stock $$
CREATE TRIGGER dis_out_of_stock
AFTER UPDATE ON ps_stock_available
FOR EACH ROW begin
UPDATE ps_product_shop
SET active=0
WHERE id_product IN (SELECT id_product
FROM ps_stock_available
WHERE quantity = 0);
END $$
DELIMITER ;
您不应尝试更新整个 ps_product_shop
table。相反,只需查看刚刚修改的记录:
DELIMTER $$
CREATE TRIGGER `dis_out_of_stock` AFTER UPDATE ON `ps_stock_available`
FOR EACH ROW
BEGIN
UPDATE ps_product_shop ps
SET active = 0
WHERE ps.id_product = new.id_product and new.quantity = 0;
END;
DELIMITER ;
帮我 please.I 想在 mysql 服务器中创建触发器,但服务器写信给我
SQL 查询:文档
CREATE TRIGGER `dis_out_of_stock` AFTER UPDATE ON `ps_stock_available`
FOR EACH ROW
begin
UPDATE `ps_product_shop` SET active=0 WHERE id_product IN (SELECT
id_product FROM `ps_stock_available` WHERE quantity=0);
MySQL 说:文档
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 '' at line 4
这是我的代码:
在
ps_stock_available
更新后创建触发器 每行
开始
更新
ps_product_shop
SET active=0 WHERE id_product IN (SELECT id_product FROMps_stock_available
WHERE quantity=0);更新
ps_product_shop
SET active=1 WHERE id_product IN (SELECT id_product FROMps_stock_available
WHERE quantity>0);结束
dis_out_of_stock
谢谢,祝你有愉快的一天。
- 您需要将
DELIMITER
重新定义为;
以外的其他内容,例如:$$
- 此外,使用
DROP TRIGGER IF EXISTS
. 检查触发器是否已经存在
- 最后,将
DELIMITER
重新定义为;
尝试:
DELIMITER $$
DROP TRIGGER IF EXISTS dis_out_of_stock $$
CREATE TRIGGER dis_out_of_stock
AFTER UPDATE ON ps_stock_available
FOR EACH ROW begin
UPDATE ps_product_shop
SET active=0
WHERE id_product IN (SELECT id_product
FROM ps_stock_available
WHERE quantity = 0);
END $$
DELIMITER ;
您不应尝试更新整个 ps_product_shop
table。相反,只需查看刚刚修改的记录:
DELIMTER $$
CREATE TRIGGER `dis_out_of_stock` AFTER UPDATE ON `ps_stock_available`
FOR EACH ROW
BEGIN
UPDATE ps_product_shop ps
SET active = 0
WHERE ps.id_product = new.id_product and new.quantity = 0;
END;
DELIMITER ;