表结构如下:问题:如何在主表插入一条记录以后同步更新两张从表的data字段?(data字段为varbinary(max)类型)注:1)主表的id字段为自增长类型
    2)三张表的所有字段均不允许为空,所以必须同时更新吧(insert和update里面我都定义为层叠了)
    3)两张从表的data字段要插入数据为一个大型二进制文件,我不知道在参数传递上是否涉及到什么问题请各位前辈多多指教~~

解决方案 »

  1.   

    取值可以用:@@IDENTITY/SCOPE_IDENTITY( )
      

  2.   

    这是操作id的,你的data字段不清楚如何处理.create trigger my_trig on tb_index for insert 
    as
    begin
      insert into tb_data6601(id) select id from inserted
      insert into tb_data4474(id) select id from inserted
    end
    go
      

  3.   

    http://topic.csdn.net/t/20041028/09/3498141.html
      

  4.   

    回复的各位:触发器不可以传参数吧?请问我的从表的data字段的值如何插入进去呢?
      

  5.   

    ID可以通过触发器同步,Data数据哪里来呀。
      

  6.   

    例如:固定值create trigger my_trig on tb_index for insert 
    as
    begin
      insert into tb_data6601(id,data) select id , '某值' from inserted
      insert into tb_data4474(id,data) select id , '某值' from inserted
    end
    go需要从其他表传入?create trigger my_trig on tb_index for insert 
    as
    begin
      insert into tb_data6601(id,data) select m.id , n.val from inserted m , 其他表 n where 条件
      insert into tb_data4474(id,data) select m.id , n.val from inserted m , 其他表 n where 条件
    end
    go
      

  7.   

    data字段不存在于其他任何表中,是从硬盘中读取的二进制文件放到Stream中的
      

  8.   

    插入附表的时间取主表max(ID)就好了,最大值ID一定是刚才添加的.
      

  9.   

    应该使用触发器就能解决,级联操作吗?
    create trigger trig_tab_index on tab_index
    for insert
    as
    begin
    insert tb_data6601 select id from tb_index
    insert tb_data4474 select id from tb_index
    end
    go
      

  10.   

    思路:通过触发器 返回新增的ID 然后再根据此ID 返回想要的数据