ALTER TRIGGER
Function
ALTER TRIGGER modifies the definition of a trigger.
Precautions
Only the owner of a table where a trigger is created and system administrators can run the ALTER TRIGGER statement.
Syntax
1
|
ALTER TRIGGER trigger_name ON table_name RENAME TO new_name; |
Parameter Description
- trigger_name
Specifies the name of the trigger to be modified.
Value range: an existing trigger
- table_name
Specifies the name of the table where the trigger to be modified is located.
Value range: an existing table having a trigger
- new_name
Specifies the new trigger name.
Value range: a string that complies with the identifier naming convention. A value contains a maximum of 63 characters and cannot be the same as other triggers on the same table.
Example
Create a source table and a trigger table:
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); |
Create the trigger function 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; |
Create an INSERT trigger:
1 2 3 4 |
CREATE TRIGGER insert_trigger BEFORE INSERT ON test_trigger_src_tbl FOR EACH ROW EXECUTE PROCEDURE tri_insert_func(); |
Modified the trigger delete_trigger.
1
|
ALTER TRIGGER insert_trigger ON test_trigger_src_tbl RENAME TO insert_trigger_renamed; |
Disable the trigger insert_trigger.
1
|
ALTER TABLE test_trigger_src_tbl DISABLE TRIGGER insert_trigger_renamed; |
Disable all triggers on the test_trigger_src_tbl table.
1
|
ALTER TABLE test_trigger_src_tbl DISABLE TRIGGER ALL; |
Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot