Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Tracking table History
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01092256
Message ID:
01092461
Vues:
19
This message has been marked as a message which has helped to the initial question of the thread.
>I need to track changes / history of a user table. I have created a history table, and would like to put a trigger on the table to be tracked, inserting into the history table those columns which are modified each time. I can create the trigger with a number of 'IF UPDATE (column)' statements, but was wanting a more elegant way of doing this. Any suggestions?? As always, any help is greatly appreciated.
>
>P.s. - this table should be modified one row at a time. There should not be any bulk inserts.

Rollin,

I have been using a nice CodeSmith template that generates this for you - triggers based on what you want to journals, and all that. If you download the free CodeSmith V2.6 I would be more than glad to send you the template.

The resulting audit tables ends up being like this:
-- Audit Table looks like this
-- CREATE TABLE [dbo].[<%= AuditTableName %>] (
--	[ChangeLogID] [int] IDENTITY (1, 1)  ,
--	[OperationType] [varchar] (10) NOT NULL ,
--	[ChangeTimestamp] [datetime] NOT NULL ,
--	[MadeBy] [varchar] (6)  NOT NULL ,
--	[TableChanged] [varchar] (50)  NOT NULL 
-- ) ON [PRIMARY]
-- Detail Table looks like this
-- CREATE TABLE [dbo].[<%= AuditFieldTableName %>] (
--	[FieldName] [varchar] (50) NOT NULL ,
--	[ChangeLogID] [int] NOT NULL ,
--	[BeforeValue] [sql_variant]  NOT NULL ,
--	[AfterValue] [sql_variant] NOT NULL 
-- ) ON [PRIMARY]
Ricardo A. Parodi
eSolar, Inc.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform