本文整理汇总了C#中SQL.AddTrigger方法的典型用法代码示例。如果您正苦于以下问题:C# SQL.AddTrigger方法的具体用法?C# SQL.AddTrigger怎么用?C# SQL.AddTrigger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQL
的用法示例。
在下文中一共展示了SQL.AddTrigger方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupInsertUpdateTrigger
private void SetupInsertUpdateTrigger(SQL.DataClasses.Table Table)
{
StringBuilder Columns = new StringBuilder();
StringBuilder Builder = new StringBuilder();
Builder.Append("CREATE TRIGGER dbo.").Append(Table.Name).Append("_Audit_IU ON dbo.")
.Append(Table.Name).Append(" FOR INSERT,UPDATE AS IF @@rowcount=0 RETURN declare @AuditType")
.Append(" char(1) declare @DeletedCount int SELECT @DeletedCount=count(*) FROM DELETED IF @DeletedCount=0")
.Append(" BEGIN SET @AuditType='I' END ELSE BEGIN SET @AuditType='U' END")
.Append(" INSERT INTO dbo.").Append(Table.Name).Append("Audit").Append("(");
string Splitter = "";
foreach (Utilities.SQL.DataClasses.Interfaces.IColumn Column in Table.Columns)
{
Columns.Append(Splitter).Append(Column.Name);
Splitter = ",";
}
Builder.Append(Columns.ToString());
Builder.Append(",AuditType) SELECT ");
Builder.Append(Columns.ToString());
Builder.Append(",@AuditType FROM inserted");
Table.AddTrigger(Table.Name + "_Audit_IU", Builder.ToString(), TriggerType.INSERT);
}
示例2: SetupDeleteTrigger
private void SetupDeleteTrigger(SQL.DataClasses.Table Table)
{
StringBuilder Columns = new StringBuilder();
StringBuilder Builder = new StringBuilder();
Builder.Append("CREATE TRIGGER dbo.").Append(Table.Name).Append("_Audit_D ON dbo.")
.Append(Table.Name).Append(" FOR DELETE AS IF @@rowcount=0 RETURN")
.Append(" INSERT INTO dbo.").Append(Table.Name).Append("Audit").Append("(");
string Splitter = "";
foreach (Utilities.SQL.DataClasses.Interfaces.IColumn Column in Table.Columns)
{
Columns.Append(Splitter).Append(Column.Name);
Splitter = ",";
}
Builder.Append(Columns.ToString());
Builder.Append(",AuditType) SELECT ");
Builder.Append(Columns.ToString());
Builder.Append(",'D' FROM deleted");
Table.AddTrigger(Table.Name + "_Audit_D", Builder.ToString(), TriggerType.INSERT);
}