SQL Database Concepts Question:

Can you explain what are COMMIT and ROLLBACK in SQL?

Basic SQL Server Interview Question
Basic SQL Server Interview Question

Answer:

COMMIT statement is used to end the current transaction and once the COMMIT statement is exceucted the transaction will be permanent and undone.

Syntax: COMMIT;

Example:
BEGIN
UPDATE EmpDetails SET EmpName = ‘Arpit’ where Dept = ‘Developer’
COMMIT;
END;

ROLLBACK statement is used to end the current transaction and undone the changes which was made by that transaction.

Syntax: ROLLBACK [TO] Savepoint_name;

Example
BEGIN
Statement1;
SAVEPOINT mysavepoint;
BEGIN
Statement2;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO mysavepoint;
Statement5;
END;
END;


Previous QuestionNext Question
Tell me what is the significance of NULL value and why should we avoid permitting null values?Explain what is the difference between UNION and UNION ALL?