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')
  • 相关阅读:
    python 之Twsited
    python之 rabbitmq
    python 之redis
    异常处理
    python select
    线程与进程
    初识socket
    Position属性
    Http协议理解
    BFC(块级格式化上下文)
  • 原文地址:https://www.cnblogs.com/hyd309/p/1328938.html
Copyright © 2011-2022 走看看