-2

これが私のトリガーです

Create TRIGGER [dbo].[tri_before_update]
   ON  [dbo].[test]
   instead of update
AS 
BEGIN

 SET NOCOUNT ON;
 if update (test_a)
 begin
  *.. my update & insert query*
 end
END


create TRIGGER [dbo].[tri_before_update_price] 
  ON [dbo].[co_ticket] 
  instead of update 
AS 
BEGIN 
  SET NOCOUNT ON; 
  if update (t_price) 
  begin 
     insert into old_price_log (t_id,insert_time,process_id,old_t_price) 
      select i.t_id,getdate(),2,t_price 
      from Inserted i,co_ticket t where i.t_id = t.t_id 
     update t set t_price = i.t_price 
      from co_ticket t, inserted i 
      where t.t_id = i.t_id 
  end 
  else 
  begin 
    -- if update other then (t_price) then the update comand not execute. 
    -- example when i update t_cancel_flag or t_quantity and etc. end 
  END

このトリガーは、列「test_a」を更新すると完全に実行されます。ただし、列「test_a」以外を更新すると実行されません。「else」コマンドを入力できることはわかっていますが、列がたくさんあります。他の 2 つの列を更新することもあれば、3 つまたは 4 つの列を更新することもあります。毎回すべての列を更新したくありません。ELSE「その後、元のクエリを実行する」ことは可能ですか? 私は多くの異なる方法を試しましたが、まだうまくいきません。:( 助けてください!

4

1 に答える 1

0
create TRIGGER [dbo].[tri_on_update_price] 
  ON [dbo].[co_ticket] 
AS 
BEGIN 
  SET NOCOUNT ON; 
  if update (t_price) 
  begin 
     insert into old_price_log (t_id,insert_time,process_id,old_t_price) 
      select d.t_id, getutcdate(),2,d.price 
      from deleted d
  END
end

通常の after トリガーは、必要なことだけを行います。価格が更新された場合、価格変更のログを挿入します。INSTEAD OF は必要ありません。古い価格を取得するには、deleted 疑似テーブルを調べる必要があります。現地時間をデータベースに保存しないでください。

于 2013-10-03T07:51:14.573 に答える