Status of Data in Rollback of Large Transaction in SQL Server
Posted
by
Lloyd Banks
on Stack Overflow
See other posts from Stack Overflow
or by Lloyd Banks
Published on 2012-09-14T15:35:33Z
Indexed on
2012/09/14
15:38 UTC
Read the original article
Hit count: 521
I have a data warehousing procedure that downloads and replaces dozens of tables from a linked server to a local database. Every once in a while, the code will get stuck on one of the tables on the linked server because the table on the linked server is in a state of transition. I am under the assumption that since the entire procedure is considered one transaction commit, when the procedure gets stuck, none of the changes made by the procudure so far would have committed. But the opposite seems to be true, tables that were "downloaded" before the procedure got stuck would have been updated with today's versions on the local server. Shouldn't SQL Server wait for the entire procedure to finish before the changes are durable?
CREATE PROCEDURE MYIMPORT
AS
BEGIN
SET NOCOUNT ON
IF EXISTS (SELECT * FROM INFORMATION.SCHEMA.TABLES WHERE TABLE_NAME = 'TABLE1')
DROP TABLE TABLE1
SELECT COLUMN1, COLUMN2, COLUMN3
INTO TABLE1
FROM OPENQUERY(MYLINK, 'SELECT COLUMN1, COLUMN2, COLUMN3 FROM TABLE1')
IF EXISTS (SELECT * FROM INFORMATION.SCHEMA.TABLES WHERE TABLE_NAME = 'TABLE2')
DROP TABLE TABLE2
SELECT COLUMN1, COLUMN2, COLUMN3
INTO TABLE2
FROM OPENQUERY(MYLINK, 'SELECT COLUMN1, COLUMN2, COLUMN3 FROM TABLE2')
--IF THE PROCEDURE GETS STUCK HERE, THEN CHANGES TO TABLE1 WOULD HAVE BEEN MADE ON THE LOCAL SERVER WHILE NO CHANGES WOULD HAVE BEEN MADE TO TABLE3 ON THE LOCAL SERVER
IF EXISTS (SELECT * FROM INFORMATION.SCHEMA.TABLES WHERE TABLE_NAME = 'TABLE3')
DROP TABLE TABLE3
SELECT COLUMN1, COLUMN2, COLUMN3
INTO TABLE3
FROM OPENQUERY(MYLINK, 'SELECT COLUMN1, COLUMN2, COLUMN3 FROM TABLE3')
END
© Stack Overflow or respective owner