1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| CREATE TABLE dbo.auditModifications (
quand datetime2(0) NOT NULL DEFAULT(SYSDATETIME()),
qui sysname NOT NULL DEFAULT(SUSER_SNAME()),
ou sysname NOT NULL DEFAULT(HOST_NAME()),
app sysname NOT NULL DEFAULT(APP_NAME()),
quoi varchar(1000) NOT NULL
)
GO
ALTER TRIGGER atr_u$Societe$audit
ON dbo.Societe
AFTER UPDATE
AS BEGIN
IF @@ROWCOUNT = 0 RETURN;
SET NOCOUNT ON;
INSERT INTO Outils.dbo.auditModifications (quoi)
SELECT 'annulation de la société ' + i.Nom
FROM inserted i
JOIN deleted d ON i.SocieteId = d.SocieteId
WHERE i.Statut = 'A'
AND (d.Statut <> 'A' OR d.Statut IS NULL);
INSERT INTO Outils.dbo.auditModifications (quoi)
SELECT 'désannulation de la société ' + i.Nom
FROM inserted i
JOIN deleted d ON i.SocieteId = d.SocieteId
WHERE d.Statut = 'A'
AND (i.Statut <> 'A' OR i.Statut IS NULL);
END;
GO |
Partager