sql server - Delete after insert inside transaction -
i have inherited nightmarish wtf sproc inserts 300k rows table of outbound marketing emails. want not queue messages email addresses bouncing. have separate table of bouncing emails.
the right way modify sproc not insert rows bouncing email.
nobody wants touch nightmarish clusterfuck particular sproc. considering adding delete command sproc thusly.
begin transaction --400+ lines of nightmarish wtf t-sql, string , xml replacement nonsense goes here-- delete emailqueueitems toaddress in (select emailstatuses.email emailstatuses inner join emaileventtypes on emaileventtypes.emaileventtypeid = emailstatuses.emaileventtypeid emaileventtypes.cansendmarketing = 0) commit transaction
so.... work? can delete inserts table before transaction commits?
yes, can insert records, , delete same, table within transaction.
try sample proof of concept:
declare @foo table (id int) begin tran insert @foo values (1),(2),(3) delete @foo id = 2 select * @foo --will result in 2 rows: 1 , 3 commit tran
Comments
Post a Comment