Skip to content

Instantly share code, notes, and snippets.

@shaneis
Created April 13, 2018 09:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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