数据仓库服务 GAUSSDB(DWS)-ALTER TRIGGER:示例

时间:2024-10-16 16:27:24

示例

创建源表及触发表:

1
2
3
4
5
DROP TABLE IF EXISTS test_trigger_src_tbl;
DROP TABLE IF EXISTS test_trigger_des_tbl;

CREATE TABLE test_trigger_src_tbl(id1 INT, id2 INT, id3 INT);
CREATE TABLE test_trigger_des_tbl(id1 INT, id2 INT, id3 INT);

创建触发器函数tri_insert_func():

1
2
3
4
5
6
7
8
9
DROP FUNCTION IF EXISTS tri_insert_func;
CREATE OR REPLACE FUNCTION tri_insert_func() RETURNS TRIGGER AS
           $$
           DECLARE
           BEGIN
                   INSERT INTO test_trigger_des_tbl VALUES(NEW.id1, NEW.id2, NEW.id3);
                   RETURN NEW;
           END
           $$ LANGUAGE PLPGSQL;

创建INSERT触发器:

1
2
3
4
CREATE TRIGGER insert_trigger
           BEFORE INSERT ON test_trigger_src_tbl
           FOR EACH ROW
           EXECUTE PROCEDURE tri_insert_func();

修改触发器delete_trigger:

1
ALTER TRIGGER insert_trigger ON test_trigger_src_tbl RENAME TO insert_trigger_renamed;

禁用触发器insert_trigger:

1
ALTER TABLE test_trigger_src_tbl DISABLE TRIGGER insert_trigger_renamed;  

禁用当前表test_trigger_src_tbl所有触发器:

1
ALTER TABLE test_trigger_src_tbl DISABLE TRIGGER ALL; 
support.huaweicloud.com/sqlreference-dws/dws_06_0147.html