SQLUSA

Microsoft SQL Server 2005 Best Practices

How to ROLLBACK a transaction?

 

Execute the following script in Query Editor to demonstrate the ROLLBACK of a transaction. The UPDATE does not take due to the ROLLBACK:



SELECT * FROM [AdventureWorks].[Purchasing].[PurchaseOrderHeader]
WHERE PurchaseOrderID = 3412

BEGIN TRANSACTION

UPDATE [AdventureWorks].[Purchasing].[PurchaseOrderHeader]
SET [ShipMethodID] = 4
,[TaxAmt] = 200.0
WHERE PurchaseOrderID = 3412

ROLLBACK TRANSACTION

SELECT * FROM [AdventureWorks].[Purchasing].[PurchaseOrderHeader]
WHERE PurchaseOrderID = 3412

 

SQLUSA - The Best SQL Server 2005 Training in the World
 
 
SQLUSA.com Home Page