Its like wanting to test everything is fine and also not having to change the underlying database which you are testing.
I have found the solution , Implicit transactions. Which are transactions which do not commit any changes to the database until appropriate commands are executed.
Pros
This is helpful for testing any sql scripts, which run in a batch and we can test the integrity of the data and fix any errors by just not commiting the transaction.
Cons
Transaction take longer to process, as a lot of information is logged and stored in temp , so as to allow to commit the transaction later on.But this is not noticeable in small transactions. However if the transactions are in the range of tens of thousands, then I would use explicit transactions.
How to set query editor to perform implicit transactions
- Open SQL Server Management Studio
- Select Tools menu , options
- Select Query Execution
- Select ANSI
- Select Implicit Transactions
When this is selected , any transaction you perform thereafter on the query editors , the transactions will not be commited automatically. Its like having autocommit off.
In SQL Scripts you can achive this by manually adding the opration.
SET IMPLICIT TRANSACTIONS ON
This is a useful tip for people working on sql scripts.