Preventive measures with Delete or Update Command in SQL Server 2005
Though it’s not wise trying to run Delete or Update command in any live database, sometimes situations compel to do so. Truly speaking, this is the most dangerous task. You may end up deleting or updating all of your data. For example
DELETE FROM t_BillMaster WHERE BillMasterID =1;
You execute this command in your Query Window and delete one row form t_BillMaster Table. It is OK up to this. The real problem starts when you execute this command without where clause and lost all data. Sorry to say that you will find yourself in hale directly.
However, you can minimize the risk of losing data using Begin Transaction command. Have a look at this code snippet.
BEGIN TRANSACTION DELETE FROM t_BillMaster WHERE BillMasterID =1;
After executing this snippet, you can retrieve your data if you wish executing ROLLBACK command.
Or if everything is ok, just execute COMMIT command.
Last but not the least; you can’t get your data in previous state after committing the transaction.
A Rahim Khan