eg:
主标A 子表B
A的id与B的sid主外关联
当b表的sid记录大于10条是修改A中Bcount为'大于10'
create trigger forB
on B
for insert
as
   begin
     declare @c int
     select @c=count(*) from B where sid=(select sid from inserted)
     if @c>10
        update A set Bcount='大于10' where id=(select sid from inserted)
     else
        select 'Less then Ten!'
   end
go

解决方案 »

  1.   

    哦,可能是我没说清楚,呵呵!
    简单一点来说,主表A中有一条记录,相对应地在子表B中对应10条记录,A的ID与B的MainID相关联,当子表B中这10条记录的某个字段都满足一个条件时(如字段值大于20),才去修改主表A中的字段。不知可否用触发器写呢?
      

  2.   

    ----不知道可不可以这样
    ----改用proc判断
    create proc test(@id nvarchar(10))
    as
       being
         if not exists(select * from b where mainid=@id and col>20) 
            update a set col='大于20' where id=@id
         else 
            selet 'Exists b.col less then 20' 
       end
    go