zoukankan      html  css  js  c++  java
  • SQL使用触发器避免记录重复插入

      drop   table   bb   
      
    create   table     bb   (id   int,name   varchar(8))   
        
      
    ---添加记录   
      insert   bb   select   1,'a'   
      
    union   all   select   2,'b'   
      
    union   all   select   3,'c'   
      
    union   all   select   4,'d'   
        
      
    --创建触发器   
      create   trigger   tr1     
      
    on   bb   
      
    for     insert     
      
    as     
      
    begin   tran     
      
    if   exists(select   id   from   bb   group   by   id   having   count(id)=2   )   
      
    begin     
      
    rollback   tran     
      
    end   
      
    else     
      
    begin     
      
    commit   tran     
      
    end   
        
        
        
      
    --测试     
        
      
    insert   into   bb     values   (5,'d')
  • 相关阅读:
    Github简单使用
    软件架构
    软件架构
    软件架构
    VB.net 捕获项目全局异常
    C#里面的三种定时计时器:TIMER
    深入分析委托与事件
    C#预处理器指令
    C# 实现透明可移动窗体
    多元一次方程解法 C++
  • 原文地址:https://www.cnblogs.com/hyd309/p/1328938.html
Copyright © 2011-2022 走看看