我正在Sybase ASE數據庫中寫入觸發更新的觸發器,並比較更新前後的值。我這樣做來驗證更新是否實際更改了數據。如果是這樣的話,它會在監控表中添加一行。不幸的是,觸發器只有在更新命令隻影響1行時纔有效。如果影響多行我得到這個錯誤:sybase更新觸發器 - 檢查多個行以進行更新
Msg 512, Level 16, State 5:
Server 'myserver', Procedure 'myproc', Line 2:
Subquery returned more than 1 value. This is illegal when the subquery follows =, !=, <, <= , >, >=, or when the subquery is used as an expression.
我PROC看起來是這樣的:
create trigger mytrigger on mytable for update as
set nocount on
/* now do the insert if colum was updated */
if update(col_a) and (select col_a from inserted) not in (select col_a from deleted)
begin
insert into monitoring_table (login,tablename,field,action,pstamp)
select suser_name(),'mytable','col_a','U',getdate() from inserted
end
/* now do the insert if colum was updated */
if update(col_b) and (select col_b from inserted) not in (select col_b from deleted)
begin
insert into monitoring_table (login,tablename,field,action,pstamp)
select suser_name(),'mytable','col_b','U',getdate() from inserted
end
go
任何想法如何,我可以得到我的周圍觸發器中這種多更新的問題?
把所有的SP,請。 – 2012-02-29 16:29:31
@aF。我編輯了上面的代碼 – dom 2012-02-29 16:38:18