--TSQLAlerter.sql

USE master

IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'xp_event' AND type = 'X')
   EXEC sp_dropextendedproc 'xp_event'
GO
EXEC sp_addextendedproc xp_event, 'dll_event.dll'

--Create table events

IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'EVENTS' AND type = 'U')
   DROP TABLE EVENTS
GO

CREATE TABLE dbo.EVENTS (
 [ID] INT IDENTITY(1,1)   NOT NULL,
 [LOGIN] CHAR(255)   NULL,
 [MESSAGE] TEXT   NULL
)
GO

--Create trigger

IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'events_trg' AND type = 'TR')
   DROP TRIGGER events_trg
GO

CREATE TRIGGER events_trg
ON EVENTS
FOR INSERT
AS
declare @login varchar(20)
declare @message varchar(2000)
declare @id int
select @login=rtrim(LOGIN),@id = ID from inserted
select @message = EVENTS.MESSAGE from inserted join EVENTS on EVENTS.ID=inserted.ID
EXEC master..xp_event '255.255.255.255',3338,@message,@login,@id
Сайт создан в системе uCoz