SQL - Structured Query Language

SAVE Transaction



SAVE Transaction is used to sets a savepoint within a transaction.

Syntax

-- Syntax --

 

SAVE { TRAN | TRANSACTION } { savepoint_name | @savepoint_variable }

[ ; ]


savepoint_name

savepoint_name is the name assigned to the savepoint.

@savepoint_variable

@savepoint_variable is the name of a user-defined variable containing a valid savepoint name. The variable must be declared with a char, varchar, nchar, or nvarchar data type.

The following example is used to stores some product information in PRODUCT_MASTER table.

-- Example 69 --

 

USE EBusiness

GO

 

CREATE TABLE Product_Master

(

Product_Code varchar(5) PRIMARY KEY,

Product_Name varchar(50) NOT NULL

)

GO

 

BEGIN TRANSACTION Product_Detail

 

INSERT INTO Product_Master VALUES ('P01','Product A')

INSERT INTO Product_Master VALUES ('P02','Product B')

INSERT INTO Product_Master VALUES ('P03','Product C')

INSERT INTO Product_Master VALUES ('P04','Product D')

INSERT INTO Product_Master VALUES ('P05','Product E')

 

SAVE TRANSACTION Product_List

 

INSERT INTO Product_Master VALUES ('P101','Product 101')

INSERT INTO Product_Master VALUES ('P102','Product 102')

INSERT INTO Product_Master VALUES ('P103','Product 103')

INSERT INTO Product_Master VALUES ('P104','Product 104')

INSERT INTO Product_Master VALUES ('P105','Product 105')

 

ROLLBACK TRANSACTION Product_List

COMMIT TRANSACTION Product_Detail

 

SELECT * FROM Product_Master


Query Output Screen



* * * * *


Email Your Comment To AUTHOR