What Is Savepoint In SQL?

Forums SQLWhat Is Savepoint In SQL?
Staff asked 2 years ago

Answers (1)

Add Answer
Ashish Kakadiya Marked As Accepted
Staff answered 2 years ago

savepoints offer a mechanism to roll back portions of transactions. Within SQL Server, you can create a savepoint by using the SAVE transaction savepoint_name statement. Later, you run a ROLLBACK transaction savepoint_name statement to roll back to the savepoint instead of rolling back to the start of the transaction.

Syntax :

SAVEPOINT Yoursavepoint_name;

 

Example:

CREATE TABLE emp_data (no NUMBER(3), name VARCHAR(50), code VARCHAR(12) ); 
//Table created. 

SAVEPOINT table_create; 
//Savepoint created. 

insert into emp_data VALUES(1,'raj', '123'); 
//1 row created.

 SAVEPOINT insert_1; //new savepoint create 
//Savepoint created.

insert into emp_data VALUES(2,'mihir', '524'); 
//1 row created. 

SAVEPOINT insert_2; 
//Savepoint created. 

SELECT * FROM emp_data; 
//Output 
NO                      NAME                  CODE 
---------- ------------------------------ ------------ 
1                       raj                    123
2                       mihir                  524

 

yes

 

Ashish Kakadiya replied 2 years ago

can you explain it with a small example?

Shaikh Hafeezjaha replied 2 years ago

Subscribe

Select Categories