|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Friday, March 29, 2013 8:18 PM
Points: 829,
Visits: 4,098
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, March 27, 2013 9:02 AM
Points: 1,046,
Visits: 573
|
|
E@sy
What you don't know won't hurt you but what you know will make you plan to know better
|
|
|
|