From: Igor on
Is the statement below always true?

I can use TRUNCATE TABLE as in the example below and I am guaranteed
that if INSERT fails for some
reason, table Result will be restored to its initial (before the
transaction began) state?

In other words, can I rely on the fact that the transaction scope
prevents the pages from being reused (assuming there are no nested
transactions)?

BEGIN TRY
BEGIN TRANSACTION
TRUNCATE TABLE Result
INSERT INTO Result
SELECT * FROM Work
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0
ROLLBACK TRANSACTION;
END CATCH


Thanks,


-Igor Binder


From: SQL Menace on
Check out Paul Randal's post here:
http://www.sqlskills.com/blogs/paul/2007/12/05/SearchEngineQA10WhenArePagesFromATruncatedTableReused.aspx

Denis The SQL Menace
http://www.lessthandot.com/
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx


On Jul 18, 1:05 pm, Igor <igor.bin...(a)gmail.com> wrote:
> Is the statement below always true?
>
> I can use TRUNCATE TABLE as in the example below and I am guaranteed
> that if INSERT fails for some
> reason, table Result will be restored to its initial (before the
> transaction began) state?
>
> In other words, can I rely on the fact that the transaction scope
> prevents the pages from being reused (assuming there are no nested
> transactions)?
>
> BEGIN TRY
>       BEGIN TRANSACTION
>             TRUNCATE TABLE Result
>             INSERT INTO Result
>             SELECT * FROM Work
>       COMMIT TRANSACTION
> END TRY
> BEGIN CATCH
>       IF XACT_STATE() <> 0
>             ROLLBACK TRANSACTION;
> END CATCH
>
> Thanks,
>
> -Igor Binder

From: Igor on
Thank you very much, Roy.

This is what I was looking for: simple and straight answer.

-igor
From: Igor on
Thanks, SQL Menace, for the link. It does help alot.
-igor