tsql - Reading Deleted or Update Value from the Open Transaction -
i trying open transaction , delete 1 record need insert deleted record event table. problem can't see result because has been deleted.
create procedure [dbo].[testdata] ( @clientid bigint ) begin print ''abc'' insert client_event_log values ( getdate(),0,@clientid,100,''b0ae3162-671c-e211-af2a-00155d051024'',null) begin try begin tran delete access_types -- there record in table. 8559230 abc 101 0 2010-01-01 10:25:25.000 select * access_types -- cann't see deleted record before session. declare @cgtaeventlog bigint select @cgtaeventlog=access_type_id access_types exec testdata @cgtaeventlog -- passing 8559230 sp insert event table has been delete before can't insert null commit tran end try begin catch rollback tran --error message print 'error: ' + convert(varchar,error_number()) + ' - ' + convert(varchar,error_severity()) + ' - ' + convert(varchar,error_state()) + ' - ' + error_message() + ' raise error occurred @ line ' + convert(varchar,error_line()) end catch end
i need find way access data after deleting can insert event table.
assuming on sql server 2005 or later, can use output clause
access virtual 'deleted' table , park contents in table variable. following
declare @tmptable table (id int, ......) delete access_types output deleted.id,... @tmptable select * @tmptable