guneysus
7/28/2016 - 12:51 PM

Smart Trigger

Smart Trigger


DROP TRIGGER IF EXISTS AFTER_MYTABLE

GO

CREATE TRIGGER dbo.AFTER_MYTABLE ON dbo.HOURLYGENERATION AFTER INSERT, UPDATE, DELETE 

AS BEGIN 

	--- FILL THE BEGIN/END SECTION FOR YOUR NEEDS.

	SET NOCOUNT ON;

    IF EXISTS(SELECT * FROM INSERTED)  AND EXISTS(SELECT * FROM DELETED) 
		BEGIN PRINT 'UPDATE' END 
	ELSE IF EXISTS(SELECT * FROM INSERTED)  AND NOT EXISTS(SELECT * FROM DELETED) 
		BEGIN PRINT 'INSERT' END 
	ELSE IF    EXISTS(SELECT * FROM DELETED) AND NOT EXISTS(SELECT * FROM INSERTED)
		BEGIN PRINT 'DELETED' END
	ELSE BEGIN PRINT 'NOTHING CHANGED'; RETURN; END  -- NOTHING
			
END