select id from deleted返回的是记录集,可能有多条记录;select @id=id from deleted是把表中第一个id赋值给@id,那么执行的结果就是只删除一条记录了。

解决方案 »

  1.   

    请问:nchln(打倒传奇)对于第二种触发器,如何在不用游标的情况下,使 @id 含有记录集而不是只有一个值呢?
      

  2.   

    CREATE TRIGGER [tr_company_del] ON dbo.t_company
    FOR DELETE
    AS
    DECLARE @id int
    select @id=id from deleted if @id is not null
    BEGIN
    delete t_design where cid in (@id)
    delete t_company_appeal where cid in (@id)
    delete t_company_leadup where cid in (@id)
    delete t_company_revisit where cid in (@id)
    delete t_company_url where cid in (@id)
    END