数据表三个列 id type x_id
id是标识列 就是自动起始1递增1的列
如果type插入的值是0 x_id和id值相等
如果type是1 x_id是sql语句插入值
请问这要怎么办?

解决方案 »

  1.   

    create trigger kk
    on tb after insert
    as
    begin 
    if(select [type] from inserted )=0
    update tb
    set x_id=id
    from inserted
    where inserted.x_id=x_id and [type]=o
    end
      

  2.   

    请问LS
    我看一个朋友用Access 也做成了 当然我是用Mssql
    不过要知道ACCESS是没有触发器....那要怎么实现?和触发器比哪个快呢
      

  3.   

    Access有约束吗
    你用约束吧
      

  4.   


    declare @type int,@x_id int
    set @type=1 --你想插入的type值
    set @x_id=1--你想插入的x_id值
    if(@type=1)
    begin 
     insert tb
     values(@type,@x_id)
    end
    else
    begin 
    insert tb
    values(@type,(select MAX(id)+1 from tb))
    end