F3不可能是NULL,F3是主键值,自增长型

解决方案 »

  1.   

    把代码全贴出来才能找到问题if update(f2) 
    begin 
    select @v1=f3 from inserted 
    insert into D(f4) values(@v1) 
    end 
    这个写法,如果inserted 多条记录,处理时不完全的,也就是说,你这样写触发器很有问题
      

  2.   

    那问题可能出在B表DELETE触发器
      

  3.   

    if update(f2) 
    begin 
    insert into D(f4) select f3 from inserted 
    end 
      

  4.   

    或者:
    if update(f2) 
    begin 
        select @v1=f3 from inserted 
        if @v1 is not null
            insert into D(f4) values(@v1) 
    end 
      

  5.   

    我现在执行: 
    update A set f1 = 1,一切正常没有问题,D表也能插入数据 
    update A set f1 = 0,提示无法将NULL值插入D,好像inserted没有数据 请问各大老大,这是个啥奇怪问题列?咋个解决哟?--------------
    有可能是Inserted表没数据,也可能是Inserted中有f3为Null的行,所以,可以用 :
    --一次更新一条或多条数据都适用
    if update(f2) 
        insert into D(f4) select f3 from inserted where f3 is not null
      

  6.   

    不是Inserted没数据,而有可能f3的数据确实为NULL.改一下试试:
    if update(f2) 
    begin 
    select @v1=isnull(f3,0) from inserted 
    insert into D(f4) values(@v1) 
    end 或者可能你取数不对:
    if update(f2) 
    begin 
    select @v1=isnull(f2,0) from inserted 
    insert into D(f4) values(@v1) 
    end 
      

  7.   

    没有看到F3是主键且自增。试试:
    if update(f2) 
    begin 
    insert into D(f4) select f3 from inserted 
    end 
      

  8.   

    可能B表中数据被删除,若用insert中的数据则b表触发实际没有数据被执行
    所以注意是用insert 表还是用deleted表,及连接关系,可建表接收一下看看触发情况