我創建了一個觸發如下後觸發update語句採取
alter trigger sale_Trigger_Update on sale
after update
as
begin
Declare @old_value varchar(50)
Declare @new_value varchar(50)
Declare @sale_id UNIQUEIDENTIFIER
DECLARE new_cur CURSOR FORWARD_ONLY READ_ONLY LOCAL FOR
SELECT saleid
FROM INSERTED
open new_cur
Fetch Next from new_cur into @sale_id
while @@FETCH_STATUS = 0
Begin
set @old_value = (select enddate from deleted where SaleID = @sale_id)
set @new_value = (select enddate from inserted where SaleID = @sale_id)
insert into zzz (old_value,new_value) values(@old_value,@new_value)
end
CLOSE new_cur
DEALLOCATE new_cur
end
很長一段時間。然後我做了一個更新語句如下
update sale
set enddate = null
Sale
表只包含2
行
和執行繼續無限。
我試圖
update sale
set enddate = null
where saleid = 10
同樣的問題。
然後我強行停止執行。然後檢查sale
表和zzz
表。沒有發生變化。 我相信遊標中存在一些問題。有人可以展示一些光。
**** ****編輯
其實我需要檢查enddate in deleted is null and enddate in inserted is not null
open new_cur
Fetch Next from new_cur into @sale_id
while @@FETCH_STATUS = 0
Begin
set @old_value = (select enddate from deleted where SaleID = @sale_id)
set @new_value = (select enddate from inserted where SaleID = @sale_id)
if @old_value = null and @new_value != null
begin
SELECT approval.*,
(select diag.*
from diag diag
where approval.id =diag.id
FOR XML PATH('diag'), TYPE
),
(select ser.*
from ser ser
where approval.id =ser.id
FOR XML PATH('ser'), TYPE
)
FROM approval approval,
where approval.id = 1
and approval.saleid [email protected]
FOR XML PATH, ELEMENTS,
root('Head')
end if
end
CLOSE new_cur
DEALLOCATE new_cur
當你說銷售表只包含兩行,即使你的光標(這是不需要的)不應該採取多time.did您檢查任何鎖定,通過以代替該光標阻塞 – TheGameiswar
啓動簡單加入... – mxix
@mxix其實我需要從插入和刪除enddate來檢查一些條件。 – Sachu