how to rollback deleted query in sql server .
how to retrieve deleted | updated data in sql server by using rollback and begin transaction .
sometimes we think if i will delete that particular row then where it will effect.
specially when you are working on live project then it will give more impact.
so ,in this article i have shown how to retrieve deleted data with help of transaction and rollback in sql server 2005 | 2008.
SELECT * FROM STUD --it will give table data
id name
1 dev
2 deva
4 deva
5 deva
6 deva
8 "dsouza"
8 "d-souza"
now i want to delete record where id=4 and after deletion i want to retrieve it .
then , what to do.
just write the query .
begin transaction
delete from stud where id =4
(1 row(s) affected)
now check whether data deleted or it exists.
SELECT * FROM STUD
1 dev
2 deva
5 deva
6 deva
8 "dsouza"
8 "d-souza"
record is deleted .now i want to back fourth record what i will do , i will just write rollback .
rollback transaction
Command(s) completed successfully.
SELECT * FROM STUD
1 dev
2 deva
4 deva
5 deva
6 deva
8 "dsouza"
8 "d-souza"
here is your record.but don't forget to use begin transaction at the time of deletion of record.
else , it Will be difficult to retrieve data again .