当前位置: 首页>>代码示例>>C#>>正文


C# SQL.AddTrigger方法代码示例

本文整理汇总了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);
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:21,代码来源:DatabaseManager.cs

示例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);
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:19,代码来源:DatabaseManager.cs


注:本文中的SQL.AddTrigger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。