CREATE TRIGGER MojWyzwalacz
ON DaneOsobowe
FOR INSERT, UPDATE, DELETE 
AS
   EXEC master..xp_sendmail 'administrator@poczta.pl', 
      'Dane osobowe zostały zmodyfikowane'
GO

CREATE TRIGGER MojWyzwalacz2
ON MojaTabela
FOR INSERT, UPDATE, DELETE
AS 
   SELECT * FROM MojaTabela
GO

CREATE TRIGGER MojWyzwalacz3
ON MojaTabela
FOR INSERT, UPDATE
AS 
   DECLARE @kol VARCHAR(12)
   SELECT TOP 1 @kol = Kolumna FROM MojaTabela;
   INSERT INTO MojaInnaTabela VALUES(@kol);
GO

CREATE TRIGGER MojWyzwalacz4 ON MojaTabela INSTEAD OF DELETE
AS
    PRINT 'Niestety nie wolno usuwać danych z tabeli: MojaTabela'
GO

CREATE TRIGGER MojWyzwalacz4
ON MojaTabela
FOR INSERT, UPDATE
AS 
  IF UPDATE(Kolumna) BEGIN
    ROLLBACK TRANSACTION;
    RAISERROR('Test',1,1);
    RETURN;
  END;
GO

CREATE TRIGGER MojWyzwalacz5
ON MojaTabela 
FOR UPDATE AS
  PRINT 'Zmieniane wiersze tabeli';
  SELECT * FROM deleted;
  PRINT 'Nowe wiersze';
  SELECT * FROM inserted;
GO
