DDL Rollback

  • Comments posted to this topic are about the item DDL Rollback

  • Huh, what?! I got the following when I tested my answer...

    (1 row(s) affected)

    Msg 208, Level 16, State 1, Line 2

    Invalid object name 'T'.

    Where did I go wrong in my life...

  • I had to fix the code (formatting, nothing else) when I tested the code in SSMS.

  • Sure, I reformatted as well, but that doesn't explain why my results were different than the posted answer. Here is the query I ran, looks the same as the QOD.

    CREATE TABLE T ( ID int NOT NULL, Code varchar(10) NULL)

    INSERT INTO T

    SELECT 1,'AAAA'

    GO

    ---------------------------------

    BEGIN Tran t1

    DROP TABLE T

    ROLLBACK Tran

    GO

    ---------------------------------

    SELECT * FROM T

  • No idea. I just copied your code to SSMS and it ran just fine returning the expected results.

  • Ack, weird. I tried it again and got the expected results as well. I hate Mondays.

  • to do rollback in a right way,

    I wrote:

    -----------------

    BEGIN Tran t1

    DROP TABLE T

    go

    ROLLBACK

    GO

    ----------------

    SELECT * FROM T

    the Question of the Day was wrong, I guess, so, was completed with errors.

    The transaction was used before cross the word "go" so,

    ---------------------------------

    BEGIN Tran t1

    DROP TABLE T

    ROLLBACK

    Tran GO

    ---------------------------------

    rollback doesn't raw

  • I got it wrong, thought it was a trick question about aliasing transactions. I had forgotten you could do that, although it makes sense that you can now that I think about it. Shame on me!

  • ramonaraujop (10/5/2009)


    to do rollback in a right way,

    I wrote:

    -----------------

    BEGIN Tran t1

    DROP TABLE T

    go

    ROLLBACK

    GO

    ----------------

    SELECT * FROM T

    the Question of the Day was wrong, I guess, so, was completed with errors.

    The transaction was used before cross the word "go" so,

    I dont know why you are putting GO in between a transaction. As far as my understanding is concern, a transaction can't be splitted in two batches as you are doing by using GO.

    Now come to the second point where you mentioned it a wrong question, but the question is all about DDL Rollback... Since it is mentioned in BOL that DDL statements cannot be rolled back then why the Table exists?

  • Hari.Sharma (10/6/2009)


    ramonaraujop (10/5/2009)


    to do rollback in a right way,

    I wrote:

    -----------------

    BEGIN Tran t1

    DROP TABLE T

    go

    ROLLBACK

    GO

    ----------------

    SELECT * FROM T

    the Question of the Day was wrong, I guess, so, was completed with errors.

    The transaction was used before cross the word "go" so,

    I dont know why you are putting GO in between a transaction. As far as my understanding is concern, a transaction can't be splitted in two batches as you are doing by using GO.

    Now come to the second point where you mentioned it a wrong question, but the question is all about DDL Rollback... Since it is mentioned in BOL that DDL statements cannot be rolled back then why the Table exists?

    The following is directly from the referenced link in the answer to this question:

    Many types of operations are recorded in the transaction log, including:

    The start and end of each transaction.

    Every data modification (insert, update, or delete). This includes changes to system tables made by system stored procedures or data definition language (DDL) statements.

    Every extent allocation or deallocation.

    The creation or dropping of a table or index.

  • Richard Sisk (10/5/2009)


    Huh, what?! I got the following when I tested my answer...

    (1 row(s) affected)

    Msg 208, Level 16, State 1, Line 2

    Invalid object name 'T'.

    Where did I go wrong in my life...

    I got the same thing when I ran this code:

    CREATE TABLE T

    ( ID int NOT NULL,

    Code varchar(10) NULL)

    INSERT INTO T SELECT 1,'AAAA' GO

    BEGIN Tran t1

    DROP TABLE T

    ROLLBACK Tran GO

    SELECT * FROM T

    But when I moved the "GO" in the ROLLBACK Tran GO to the next line and ran it as this:

    CREATE TABLE T

    ( ID int NOT NULL,

    Code varchar(10) NULL)

    INSERT INTO T SELECT 1,'AAAA' GO

    BEGIN Tran t1

    DROP TABLE T

    ROLLBACK Tran

    GO

    SELECT * FROM T

    it ran just fine with the expected response. SQL was probably looking at the GO as the alias for Tran and that was messing things up as there was no GO transaction. At least, that's what I think is the reason behind why it didn't work the first time.

    -- Kit

  • E@sy

    What you don't know won't hurt you but what you know will make you plan to know better

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply