Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

DDL Rollback Expand / Collapse
Author
Message
Posted Tuesday, October 6, 2009 12:10 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, September 5, 2013 2:13 PM
Points: 829, Visits: 4,099
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
Post #798707
Posted Tuesday, October 13, 2009 5:24 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 5, 2013 6:08 AM
Points: 1,079, Visits: 591
E@sy

What you don't know won't hurt you but what you know will make you plan to know better
Post #802071
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse