Rajanand Ilangovan
Rajanand Ilangovan

Rajanand Ilangovan

What happens to the records inserted into a table variable, if the transaction rollback?

What happens to the records inserted into a table variable, if the transaction rollback?

Rajanand Ilangovan's photo
Rajanand Ilangovan
·Mar 24, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Question:

DECLARE @People TABLE (first_name VARCHAR(50), age int);
BEGIN TRAN
INSERT INTO @People VALUES ('John', 25);
INSERT INTO @People VALUES ('Daniel', 30);

ROLLBACK

SELECT * FROM @People;

Answer:

The records inserted into a table variable will not be affected by the transaction rollback.

1118_20220406_004013.png

Reference: Brent Ozar

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