Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DDL Rollback


DDL Rollback

Author
Message
Kit G
Kit G
Mr or Mrs. 500
Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)

Group: General Forum Members
Points: 562 Visits: 4113
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
BudaCli
BudaCli
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1166 Visits: 598
E@sy

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


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search