Managing Triggers
A database trigger is a stored subprogram associated with a database table, view, or event. You can use Object Browser to create, view, edit, compile, download, drop, and disable or enable a trigger.
The trigger can be called once, for example when an event occurs, or many times, for example for each row affected by an INSERT, UPDATE, or DELETE statement.
Creating a Trigger
Create a trigger using Object Browser.
To create a trigger in Object Browser:
-
In Object Browser, click the Create Database Objects menu and select Trigger.
Tip:
To create new objects from the Object Tree, right-click the object and select the Create option.
The Create Trigger Wizard appears.
-
On Create Trigger:
-
Table - Select the table you want to create a trigger on.
-
Trigger Name - Trigger name is automatically generated based on selected table. Modify the trigger name, if required. This name must conform to Oracle naming conventions and cannot contain spaces, or start with a number or underscore.
-
Firing Point - Specify the firing point:
-
Before - Causes the database to fire the trigger before running the triggering event.
-
After - Causes the database to fire the trigger after running the triggering event.
-
-
-
Click Create Trigger.
Viewing a Trigger
Select a trigger from the Object Tree and access tabs in the Object Detail View.
To view a trigger:
-
In Object Browser, Object Tree, expand Triggers and select a trigger.
-
The Object Detail View appears and displays four tabs:
Tip:
The Code and DDL tabs feature a fully functional Code Editor. To learn more about the Code Editor, seeCode Editor in Object Browser.
-
Code - View the trigger code, or edit it manually. Available actions include:
-
Download
-
Save and Compile
-
Drop
-
Refresh
-
-
Errors - View errors related to the current trigger. Select the Refresh button to refresh the list of errors.
-
Object Details - View the details of the trigger. Available actions include:
-
Compile
-
Drop
-
Enable
-
Disable
-
Refresh
-
-
DDL - Displays the DDL necessary to re-create the trigger. Available actions include:
-
Download
-
Refresh
-
-
Editing a Trigger
Select a trigger from the Object Tree.
-
The Object Detail View appears.
-
In the Code tab, edit the code. Other edit controls include:
-
Undo
-
Redo
-
Find
-
Auto Complete
Tip:
To learn more about the Code Editor, seeCode Editor in Object Browser.
-
- Select Save and Compile to save your changes.
Compiling a Trigger
Select a trigger from the Object Tree and click Save and Compile.
To compile a trigger in Object Browser:
-
In Object Browser, Object Tree, expand Triggers and select a trigger.
The Object Detail View appears.
-
Compile the trigger:
-
On the Code tab, click Save and Compile.
-
On the Object Details tab, click Compile.
If the compilation fails, an error message displays. Correct the error, and compile the trigger again.
-
Downloading a Trigger
Select a trigger from the Object Tree and click Download to save the trigger as a file.
To download a trigger as a file:
-
In Object Browser, Object Tree, expand Triggers and select a trigger.
The Object Details View appears.
-
Download the trigger:
-
On the Code tab, click Download.
-
On the DDL tab, click Download.
-
-
Enter a file name for the file and click Save.
The file saves in
.sqlformat.
Disabling and Enabling a Trigger
Select a trigger from the Object Tree and click Enable or Disable.
To disable and enable a trigger in Object Browser:
-
In Object Browser, Object Tree, expand Triggers and select a trigger.
The Object Detail View appears.
-
On the Object Details tab, click Enable or Disable.
Tip:
Trigger Status, on the Object Details tab, indicates whether the trigger is currently
ENABLEDorDISABLED.
The Trigger Status updates.
Dropping a Trigger
Select a trigger from the Object Tree and click Drop.
To drop a trigger:
-
In Object Browser, Object Tree, expand Triggers and select a trigger.
The Object Detail View appears.
-
Drop the trigger:
-
On the Code tab, click Drop.
-
On the Object Details tab, click Drop.
-
-
Click Drop to drop the trigger.