我在 lost表中插入一条记录时,在book表中删除一条记录.他们的公共属性是bookid
这样写,有语法错误,请教该怎么写?CREATE TRIGGER  bookdelete  ON  Lost
FOR  INSERT 
AS
delete from book where book.bookid=inserted.bookid

解决方案 »

  1.   

    create or replace trigger <TRIGGER_NAME>
      before insert or update
    on <table_name>
      for each row
    declare
      <VARIABLE DECLARATIONS>
    begin
        <CODE>
    exception
        <EXCEPTION HANDLERS>
    end <TRIGGER_NAME>;
      

  2.   

    CREATE TRIGGER  bookdelete  
    ON  Lost
    FOR  INSERT 
    AS
    delete from book where book.bookid in (select bookid from lost.bookid)--这里到底是删---除lost表还是inserted表,楼主自己换GO
      

  3.   

    SQL很简单的.
    上面好像有Oralce的语法吧.
      

  4.   

    除了用whbo(王红波)的触发器外,
    也可以在程序中用代码写SQL语句来删除
      

  5.   

    CREATE TRIGGER bookdelete  ON [dbo].[Lost] 
    FOR insert
    AS
    begin
      declare @bookid varchar(4)
      select @bookid=bookid from inserted  -- ‘inserted ' 这个表是系统自动建立的表,表结构和建立触发器的表结果一致
      delete from book where bookid =@bookid
    end