Similar to LAST_INSERT_ID()
, is there a nice mechanism in MySQL to get the last deleted ID after a row has been deleted?
By "ID", I assume you mean "auto-increment"?
Since you can delete any arbitrary row (or set of rows) at any time: no, there's no way to tell WHICH row (or rows) you most recently deleted.
You can, however, create a "trigger" to save this information for you:
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
Instead of creating a trigger, you need to use this each and every time when you delete
declare @table1 table(id int identity,name varchar(50))
insert into @table1 (name) values('abc')
insert into @table1 (name) values('xyz')
insert into @table1 (name) values('pqr')
insert into @table1 (name) values('wqe')
delete from @table1 output deleted.name,deleted.id where id=3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With