VastbaseE100

基于开源技术的HTAP数据库管理系统。性能优异,稳定可靠,提供诸多专属领域特性。

Menu

ALTER TRIGGER

  • ALTER TRIGGER tg_name DISABLE;

  • ALTER TRIGGER tg_name ENABLE;

  • ALTER TRIGGER tg_name RENAME TO tg_name1;

    CREATE TABLE student (
      id   int primary key,
      name varchar(50)
    );
    CREATE TABLE score (
      studentId  int,
       math     int 
    );
    INSERT INTO student VALUES(1,'April');
    INSERT INTO student VALUES(2,'Harris');
    INSERT INTO score VALUES(1, 98);
    INSERT INTO score VALUES(2,77);
    CREATE OR REPLACE FUNCTION student_delete_trigger()
    RETURNS TRIGGER AS $$
    BEGIN
    DELETE FROM score where studentId = OLD.id;
    RETURN OLD;
    END;
    $$
    LANGUAGE plpgsql;
    CREATE TRIGGER delete_trigger 
    AFTER DELETE ON student
    FOR EACH ROW EXECUTE PROCEDURE student_delete_trigger();
    atlasdb=# \d student
                     Table "atlasdb.student"
    Column |         Type          | Collation | Nullable | Default 
    --------+-----------------------+-----------+----------+---------
    id     | integer               |           | not null | 
    name   | character varying(50) |           |          | 
    Indexes:
    "student_pkey" PRIMARY KEY, btree (id)
    Triggers:
    delete_trigger AFTER DELETE ON student FOR EACH ROW EXECUTE PROCEDURE student_delete_trigger()
    ALTER TRIGGER delete_trigger DISABLE;
    ALTER TRIGGER delete_trigger RENAME TO delete_trigger2;	
    DELETE FROM student where id = 2;
    select * from score
    studentid | math 
    -----------+------
         1 |   98
         2 |   77
    (2 rows)
    ALTER TRIGGER delete_trigger2 ENABLE;
    DELETE FROM student where id = 1;
    select * from score
    studentid | math 
    -----------+------
         2 |   77
    (1 row)