ms sql server
字段如下:
条目表a :a_id
类别表b: b_id,b_name
关联表c(a,b两表关联表):a_id,b_id
当往条目表插入数据的时候,同时向关联表c插入2者关联
如表a 插入一条 苹果 记录时
由于它数据b表中 水果 记录 在c表中插入2个关联,也就是2个id

解决方案 »

  1.   

    寫個觸發器
    create trigger trg_a on table a for insert 
    as
    insert c 
     select a_id,b_id from a,b where (a,b兩個表的關連條件)
      

  2.   

    寫個觸發器
    create trigger trg_a on table a for insert 
    as
    insert c 
     select a_id,b_id from a,b,inserted where (a,b兩個表的關連條件) and a_id = inserted.a_id