提示下 select c1,count(*) from .. group

解决方案 »

  1.   

    update 一下,或触发器里update
    总之重新统计所有行
      

  2.   

    做个触发器吧
    CREATE TRIGGER upd_id 
    ON Table2 
    FOR update 
    ASupdate table1 set c_cmt=c_cmt-1 from 
    table1 a 
    inner join deleted b 
    on a.c_id=b.c_idupdate table1 set c_cmt=c_cmt+1 from 
    table1 a
    inner join inserted 
    on a.c_id=b.c_id
      

  3.   

    CREATE TRIGGER upd_id 
    ON Table2 
    FOR INSERT, UPDATE, DELETE
    ASupdate table1 a set c_cmt=(select count(s_id) from table2 where id=a.id )go
      

  4.   

    触发器好啦
    CREATE TRIGGER upd_id 
    ON Table2 
    FOR update 
    ASupdate table1 set a.c_cmt=a.c_cmt-1 from 
    table1 a , deleted b where a.c_id=b.c_idupdate table1 set a.c_cmt=a.c_cmt+1 from 
    table1 a,inserted b where a.c_id=b.c_id
      

  5.   

    creat trigger upd_id
    on table2
    for insert ,update,delete
    asTRUNCATE TABLE table1
     insert into #table1 
    select s_id as c_id, count(s_id) as s_id
    group by c_id
      

  6.   

    做个触发器 
    create trigger ... on  biao 
    for update
    update ....
    set ....=sum(....)
    where cid = (select cid from inserted)
      

  7.   

    改一下,前一个写错create trigger t_table2 on table2
    for insert,update,delete
    as 
     update table1 set c_cmt=(select count(s_id) from table2 where c_id=a.c_id )
     from table1 a
    go