CREATE TRIGGER [TABLE1_del] ON dbo.TABLE1
FOR DELETE 
AS
delete from table2 where table2.ID=deleted.ID没怎么测试,但应该没有问题的

解决方案 »

  1.   

    to ArcherFem(诸葛不亮):
      谢谢你,你能解释一下deleted.id 是怎么来的呢?
      

  2.   

    Two special tables are used in trigger statements: the deleted table and the inserted table. You can use these temporary tables to test the effects of certain data modifications and to set conditions for trigger actions. You cannot alter the data in the trigger test tables directly, but you can use the tables in SELECT statements to determine whether the trigger was fired by an INSERT, UPDATE, or DELETE statement.The deleted table stores copies of the affected rows during DELETE and UPDATE statements. During the execution of a DELETE or UPDATE statement, rows are deleted from the trigger table and transferred to the deleted table. The deleted table and the trigger table ordinarily have no rows in common.The inserted table stores copies of the affected rows during INSERT and UPDATE statements. During an INSERT or UPDATE transaction, new rows are added simultaneously to both the inserted table and the trigger table. The rows in the inserted table are copies of the new rows in the trigger table.An UPDATE transaction is like a delete followed by an insert; the old rows are copied to the deleted table first, and then the new rows are copied to the trigger table and to the inserted table.When you set trigger conditions, use the inserted and deleted tables appropriately for the action that fired the trigger. Although referencing deleted while testing an INSERT, or inserted while testing a DELETE does not cause any errors, these trigger test tables will not contain any rows in these cases. 
      

  3.   

    To ArcherFem(诸葛不亮):  为什么
    CREATE TRIGGER [TRIGGER NAME] ON [TABLE_q] 
    FOR DELETE 
    AS
    delete from tablev where tablev.ID=deleted.ID做语法检查时通不过呢?我的数据表是 table_q 和 tablev 关联字段是 tablev.p_id=table_q.id
     
      

  4.   

    不好意思,上次写的太急,犯了一个低级错误,下面的应该可以了!!
    table_q 和 tablev 关联字段是 tablev.p_id=table_q.id CREATE TRIGGER [Del_table_q] ON [table_q] 
    FOR DELETE 
    AS
    delete from tablev where tablev.p_id in (select id from  deleted)