Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trigger for tracking changes in table
Message
De
21/06/2003 11:44:34
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Trigger for tracking changes in table
Divers
Thread ID:
00802591
Message ID:
00802591
Vues:
60
Hi all,
I have this trigger to track the changes in the table dbo.tbl_gc_CodZonas, but it creates two reg for update and insert, any chance to create only one for UPDATE and one for INSERT. I know if i have one for UPDATE one FOR INSERT and one for DELETE it works, but my database have about 150 tables, or is there any other way to do that?
CREATE TRIGGER SystemLog_CodZonas ON dbo.tbl_gc_CodZonas
FOR INSERT, UPDATE, DELETE
AS
DECLARE @TypeTrans CHAR(6) 
DECLARE @TRCodigo VARCHAR(16)
IF EXISTS(SELECT * FROM inserted) AND EXISTS(SELECT * FROM deleted) 
SET @TypeTrans = 'UPDATE' 
ELSE 
IF EXISTS(SELECT * FROM inserted)
SET @TypeTrans = 'INSERT' 
ELSE IF EXISTS(SELECT * FROM deleted)
SET @TypeTrans = 'DELETE'
IF @TypeTrans = 'INSERT' 
BEGIN
SET @TRCodigo = (SELECT c_codigo  FROM Inserted)
INSERT INTO dbo.tbl_system_log (c_tablename,c_accao,c_codigoalt,c_username, d_datetime)
VALUES ('dbo.tbl_gc_CodZonas','INSERT',@TRCodigo,suser_sname(), getdate())
END
IF @TypeTrans = 'UPDATE' 
BEGIN
SET @TRCodigo = (SELECT c_codigo  FROM Inserted)
INSERT INTO dbo.tbl_system_log (c_tablename,c_accao,c_codigoalt,c_username, d_datetime)
VALUES ('dbo.tbl_gc_CodZonas','UPDATE',@TRCodigo,suser_sname(), getdate())
END
IF @TypeTrans = 'DELETE' 
BEGIN
SET @TRCodigo = (SELECT c_codigo  FROM deleted)
INSERT INTO dbo.tbl_system_log (c_tablename,c_accao,c_codigoalt,c_username, d_datetime)
VALUES ('dbo.tbl_gc_CodZonas','DELETE',@TRCodigo,suser_sname(), getdate())
END
Thanks

Joao Batista
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform