The or replace clause allows you to replace a trigger's definition using create trigger.
In versions earlier than SAP ASE 16.0, consecutive create trigger commands dropped the old trigger and replaced it with a new trigger definition. However, the auditing options for the trigger were also dropped. Using the optional or replace clause, the definition is replaced, and auditing options are preserved.
Changes are in bold.
create [or replace] trigger [owner.]trigger_name on [owner.]table_name {for {insert , update} | instead of {insert, update, delete}} [order integer] [as [if update (column_name) [{and | or} update (column_name)]...] SQL_statements] ...] [if update (column_name) [{and | or} update (column_name)]... SQL_statements]...]
In SAP ASE version 16.0 and later, when there are multiple triggers, specifying create without or replace raises an error if the trigger name is same. If you specify a different trigger name, a new trigger is created and the old trigger remains. Also see, Multiple Triggers
In versions of SAP ASE earlier than 16.0, if an existing trigger was replaced with the new trigger definition by specifying create without or replace, the name of the new trigger did not need to be same as the name of the old trigger name.
This example creates a trigger that prints a message when anyone tries to insert or update data in the titles table:
create trigger reminder on titles for insert, update as print "Don't forget to print a report for accounting." select object_id("reminder") ----------- 1312004674
The next command changes the message of the printed trigger when anyone tries to update data in the titles table using the or replace clause:
create or replace trigger reminder on titles for update as print "Don't forget to give a report to accounting." select object_id("reminder") ----------- 1312004674
Any user who impersonates the trigger owner through an alias or setuser cannot replace the trigger.
Changes for replacing a trigger are in bold.
Granular permissions enabled | With granular permissions enabled, you must be the table owner and the create trigger privilege must not have been revoked. You must have the create any trigger privilege to run create trigger on another user's table. You must be the trigger owner to replace the trigger. |
Granular permissions disabled | With granular permissions disabled: Only a system security officer can grant or revoke permissions to create triggers. The database owner has implicit permission to create a trigger on any user table. Users can create triggers only on tables that they own. The system security officer may revoke user permission to create triggers. Revoking permission to create triggers affects only the database in which the systems security officer issues the revoke command. Permission to run the create trigger command is restored to the users whose permission was revoked when the system security officer explicitly grants them create trigger permission. You must be the trigger owner to replace the trigger. |
Changes are in bold.
Event | Audit Option | Command or access audited | Information in extrainfo |
---|---|---|---|
12 | create | create trigger |
|