Skip to content

Instantly share code, notes, and snippets.

@shaneis
Created April 13, 2018 09:03
Show Gist options
  • Save shaneis/297cabc6482a8d10c8cfcb4fc8d868b4 to your computer and use it in GitHub Desktop.
Save shaneis/297cabc6482a8d10c8cfcb4fc8d868b4 to your computer and use it in GitHub Desktop.
Shows how table variables keep data even after a transaction rollback
BEGIN TRAN;
DECLARE @MyHoldingTable TABLE (id int NOT NULL, FirstName varchar(50) NOT NULL, LastName varchar(50) NOT NULL);
INSERT INTO dbo.CustomersTableIdent (FirstName, LastName)
OUTPUT inserted.id, inserted.FirstName, inserted.LastName
INTO @MyHoldingTable (id, FirstName, LastName)
VALUES ('My first name (removed)', 'My last name (removed)');
ROLLBACK
SELECT id, FirstName, LastName FROM @MyHoldingTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment