Manage database triggers

In this topic, you will learn how to create, edit, delete, duplicate, and manage triggers from Database Explorer.

Create a DDL trigger

1. In Database Explorer, right-click a trigger or Programmability > Database Triggers node and select New DDL Trigger.

2. Update the CREATE TRIGGER statement template. For more information, see Database Trigger Designer.

3. At the bottom of the SQL document, click Apply Changes.

Edit a DDL trigger

1. In Database Explorer, right-click the DDL trigger you want to edit and select Modify via SQL.

2. Edit the DDL trigger.

3. At the bottom of the SQL document, click Apply Changes.

Alternatively, on the top menu, select File > Save or press Ctrl+S.

Delete a trigger

1. In Database Explorer, right-click the trigger you want to delete and select Delete, or press Delete.

2. Click Yes to confirm the deletion.

Note

You cannot undo the drop trigger operation, as this action permanently deletes its structure. It is recommended that you back up the database before deleting it.

Enable a DDL trigger

To enable a trigger, in Database Explorer, right-click the DDL trigger and select Enable.

To enable all triggers, right-click the Database Triggers node and select Enable All.

Disable a DDL trigger

To disable a trigger, in Database Explorer, right-click the DDL trigger and select Disable.

To disable all triggers, right-click the Database Triggers node and select Disable All.

View a DDL trigger

To view a DDL trigger, do one of the following:

  • In Database Explorer, right-click the trigger and select Open Editor.
  • In Database Explorer, double-click the trigger.

Duplicate a DDL trigger

1. In Database Explorer, right-click a required DDL trigger and select Duplicate Object.

2. In the Duplicate Object dialog, configure the object settings:

  • In Destination connection, select the target server.
  • In Destination database, select the target database.
  • In Destination schema, select the target schema.
  • In New object name, specify the object name.
  • Select Drop destination object to drop the destination object if it already exists.
  • Optional: Select Script Changes, then select To New SQL Window to open the generated script in a new SQL document, or To Clipboard to copy it to the clipboard.

3. Click OK.

Generate a script for a DDL trigger

1. In Database Explorer, right-click a required trigger and select Generate Script As, then select the statement type.

2. Select the output option:

  • To New SQL Window – The script opens in a new SQL document.
  • To File – The script is generated to a .sql file.
  • To Clipboard – The script is copied to the clipboard.

For more information, see Generate the DDL and DML statements for database objects.

View DDL trigger properties

To view trigger properties, in Database Explorer, right-click the trigger or Database Triggers node and select Show Details.

Object Viewer opens, displaying detailed information about the DDL trigger.

Refresh a DDL trigger

To update the DDL trigger to reflect the latest changes, in Database Explorer, right-click the trigger or Database Triggers node and select Refresh, or press F5.

Open the Properties pane

To open the Properties window, in Database Explorer, right-click the trigger and select Properties, or press F4.

Filter DDL triggers

You can set which DDL triggers should appear in Database Explorer.

To filter DDL triggers:

1. In Database Explorer, right-click the Database Triggers node and select Filter.

2. In the Filter Settings dialog, configure the filter parameters.

3. Click OK to apply the filter.

Note

When you open the Database Triggers node, the number of objects it contains appears in parentheses next to the node name. This number changes based on your filter settings.