Answers

Question and Answer:

  Home  MS SQL Server

⟩ How To Create a Trigger for INSERT Only?

The trigger, dml_message, provided in previous tutorials was defined to handle all 3 types of DML statements, INSERT, UPDATE, and DELETE.

If you do not want the trigger to handle all 3 types of DML statements, you can list only 1 or 2 of the statement keywords. For example, the following SQL script defines a trigger that only handle the INSERT statement events:

USE GlobalGuideLineDatabase

GO

CREATE TRIGGER new_user ON ggl_users

AFTER INSERT

AS

PRINT 'Time: '+CONVERT(VARCHAR(12),GETDATE())

+ ' New users added.';

GO

INSERT INTO ggl_users (name) VALUES ('Marc MHI');

GO

Time: Jul 1 2007

Records are inserted, updated, or deleted in ggl_users

Time: Jul 1 2007 New users added.

(1 row(s) affected)

 171 views

More Questions for you: