A trigger is a special kind of a store procedure that executes in response to certain action on the table like insertion, deletion or updation of data. It is a database object which is bound to a table and is executed automatically.
You should have the following privileges:
In Database Explorer, make sure that the connection to your server containing the base is active
Navigate to the node of a certain table and expand it.
Right-click the Triggers node and select New Trigger on the shortcut menu. A trigger editor document will appear.
Input a name of the trigger and type a script that will represent the trigger.
Save the document by clicking the Update Database button at the bottom of the window, or the Save button on the Standard toolbar. If there are any errors in the SQL syntax, you will be notified about it.
CREATE TRIGGER dEmployee ON HumanResources.Employee INSTEAD OF DELETE NOT FOR REPLICATION AS BEGIN DECLARE @Count int; SET @Count = @@ROWCOUNT; IF @Count = 0 RETURN; SET NOCOUNT ON; BEGIN RAISERROR (N'Employees cannot be deleted. They can only be marked as not current.', -- Message 10, -- Severity. 1); -- State. -- Rollback any active or uncommittable transactions IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; END END; END;
To simplify the process of a Trigger creation, you may use the CreateTrigger snippet.
Click the New SQL button on the Devart - Main toolbar.
Right-click anywhere in the SQL document, and then click Insert Snippet. The snippets list will appear.
Double-click the CreateTrigger snppet.
The following code will be inserted to the document.
Edit the code accordingly and save the trigger. If there are any errors in the SQL syntax, you will be notified about it.
Edit a view by selecting Edit Trigger from Database Explorer on the shortcut menu. In the document that opens, you can alter the query text. Save the document to apply changes you’ve made to the query text.
Drop a trigger by selecting Delete from Database Explorer on the shortcut menu.
Enable or disable a trigger by selecting Enable or Disable from Database Explorer on the sgortcut menu.
To enable or disable all triggers at once, select Enable All or Disable ALL from Database Explorer on the shortcut menu.