H
hbnew
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是表ReturnCurDayDetail 的删除触发器的内容
当发出命令:delete from ReturnCurDayDetail 时
ReturnCurDayDetail 表中的记录全部删除,但ReturnCurDay
(需要触发删除)表中的记录却只能删除一条对应的记录(实际应是全部删除),
请高手指教!
CREATE TRIGGER TR_Delete ON dbo.ReturnCurDayDetail
FOR DELETE
AS
begin
---声明变量,用于定位
declare @ItemUnitCode char(10),@CounterCode char(20),@ItemType char(2),@ReturnType char(2),@UserId char(6),@ReturnDate datetime
--定义游标
declare cur_dele scroll cursor for select ItemUnitCode,CounterCode,ItemType,ReturnType,UserId ,Convert(char(10),ReturnDate,20) from deleted
--打开
open cur_dele
fetch cur_dele into @ItemUnitCode ,@CounterCode ,@ItemType ,@ReturnType ,@UserId ,@ReturnDate
while @@FETCH_STATUS=0
begin
select @ItemUnitCode=ItemUnitCode ,@CounterCode=CounterCode,@ItemType=ItemType , @ReturnType=ReturnType,@UserId=UserId,@ReturnDate=ReturnDate from deleted
delete from ReturnCurDay
where ItemUnitCode=@ItemUnitCode and CounterCode=@CounterCode and ItemType=@ItemType and ReturnType=@ReturnType and UserId=@UserId
and convert(char(10),ReturnDate,20)=Convert(char(10),@ReturnDate,20)
fetch cur_dele into @ItemUnitCode ,@CounterCode ,@ItemType ,@ReturnType ,@UserId ,@ReturnDate
end
close cur_dele
DEALLOCATE cur_dele
end
当发出命令:delete from ReturnCurDayDetail 时
ReturnCurDayDetail 表中的记录全部删除,但ReturnCurDay
(需要触发删除)表中的记录却只能删除一条对应的记录(实际应是全部删除),
请高手指教!
CREATE TRIGGER TR_Delete ON dbo.ReturnCurDayDetail
FOR DELETE
AS
begin
---声明变量,用于定位
declare @ItemUnitCode char(10),@CounterCode char(20),@ItemType char(2),@ReturnType char(2),@UserId char(6),@ReturnDate datetime
--定义游标
declare cur_dele scroll cursor for select ItemUnitCode,CounterCode,ItemType,ReturnType,UserId ,Convert(char(10),ReturnDate,20) from deleted
--打开
open cur_dele
fetch cur_dele into @ItemUnitCode ,@CounterCode ,@ItemType ,@ReturnType ,@UserId ,@ReturnDate
while @@FETCH_STATUS=0
begin
select @ItemUnitCode=ItemUnitCode ,@CounterCode=CounterCode,@ItemType=ItemType , @ReturnType=ReturnType,@UserId=UserId,@ReturnDate=ReturnDate from deleted
delete from ReturnCurDay
where ItemUnitCode=@ItemUnitCode and CounterCode=@CounterCode and ItemType=@ItemType and ReturnType=@ReturnType and UserId=@UserId
and convert(char(10),ReturnDate,20)=Convert(char(10),@ReturnDate,20)
fetch cur_dele into @ItemUnitCode ,@CounterCode ,@ItemType ,@ReturnType ,@UserId ,@ReturnDate
end
close cur_dele
DEALLOCATE cur_dele
end