[英]Audit Trail Trigger generation
Working on Audit Trail system and decided to do it with Shadow/History table with triggers. 正在使用Audit Trail系统,并决定使用带触发器的Shadow / History表进行处理。
Followed this Audit Trail Article and trying to use CodeSmith Generator tool 关注了此审计跟踪文章并尝试使用CodeSmith Generator工具
I dont understand how it creates the history table and the trigger. 我不明白它如何创建历史记录表和触发器。
Is any one could understand how it works and help me on it. 有谁能理解它的工作原理并为我提供帮助。
I tried google to understand it. 我试图谷歌了解它。 But there is no clear example
但是没有明确的例子
Nothing is clear with the below to me 我对以下内容一无所知
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]
How to generate this and add trigger and how can i insert AuditFieldTableName values? 如何生成并添加触发器,如何插入AuditFieldTableName值?
As we have different types of columns in multiple tables, the audit table that you have specified wouldn't really suffice the cause. 由于我们在多个表中具有不同类型的列,因此您指定的审核表实际上不足以解决问题。 I suggest the following audit table:
我建议使用以下审核表:
TABLE auditEntry (
auditEntryId INTEGER PRIMARY KEY,
operationType VARCHAR(10) NOT NULL, -- For INSERT / UPDATE / DELETE
changeTimestamp DATETIME NOT NULL,
madeBy VARCHAR(50) NOT NULL,
tableName VARCHAR(30) not null, -- stores the name of the table changed
columnName VARCHAR(30) not null, -- stores the name of column changed
oldInt INTEGER,
newInt INTEGER,
oldVarchar VARCHAR(100),
newVarchar VARCHAR(100),
oldDate DATETIME,
newDate DATETIME)
Now I think it's a cakewalk for you to write row level triggers for INSERT
, UPDATE
and DELETE
on your tables, if you have working knowledge of writing them. 现在,如果您具备编写行级触发器的能力,可以在表上为
INSERT
, UPDATE
和DELETE
编写行级触发器,这对我来说是一条小路。 Search MSDN on how to write such triggers and you will be fine. 在MSDN上搜索如何编写这样的触发器,这样就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.