gpt4 book ai didi

sql - 触发以防止从表中删除任何内容

转载 作者:行者123 更新时间:2023-12-01 07:35:04 25 4
gpt4 key购买 nike

此新租赁历史记录表的触发器,可防止从表中删除。

CREATE OR REPLACE  TRIGGER RENTALHIS_DEL
BEFORE DELETE ON RENTALHISTORY
BEGIN
dbms_output.put_line( 'Records can not be deleted');
END;

DELETE FROM RENTALHISTORY WHERE RENTALID = 1;



-- It is deleting before it says it can not delete

1 rows deleted.

Records can not be deleted

最佳答案

dbms_output.put_line( 'Records can not be deleted');


以上只是打印文本和触发器成功完成,然后删除仍然发生。您想要做的是引发错误以阻止程序完成。

使用标准程序 raise_application_error停止程序并引发错误:
CREATE OR REPLACE  TRIGGER RENTALHIS_DEL
BEFORE DELETE ON RENTALHISTORY
BEGIN
raise_application_error(-20001,'Records can not be deleted');
END;
/

关于sql - 触发以防止从表中删除任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41964979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com