DEV Community

rajanand ilangovan
rajanand ilangovan

Posted on • Originally published at blog.rajanand.org on

What happens to the variable value set during the transaction, if its rollback?

DECLARE @my_age INT = 20;

BEGIN TRAN
SET @my_age += 30;
ROLLBACK;

SELECT @my_age;

Enter fullscreen mode Exit fullscreen mode

Answer:

Even though the transaction is rolled back, the value set to the variable remains same.

1117_20220406_003230.png

Changes to variables aren't affected by the rollback of a transaction.

Reference:

Microsoft docs

Brent Ozar

If you like this SQL interview question, you may also like the below interview question and answers.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay