SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Applying TRANSACTION for DDL statements


Applying TRANSACTION for DDL statements

Author
Message
AJ07
AJ07
SSC Veteran
SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)

Group: General Forum Members
Points: 202 Visits: 198
Hi Guys,

I had this understanding that the DDL statements are autocommit statements and if any DDL statement is written in any TRANSACTION then as the DDl statement executes all the DML before it got commit.
I tried below script -

CREATE TABLE AJ1 (ID INT IDENTITY(-1,1))
--CREATE TABLE AJ2(ID INT IDENTITY(-1,-1))

INSERT INTO AJ1 Default values
INSERT INTO AJ1 Default values
INSERT INTO AJ1 Default values

BEGIN TRAN

INSERT INTO AJ1 Default values
INSERT INTO AJ1 Default values
INSERT INTO AJ1 Default values
--DROP TABLE AJ1
CREATE TABLE AJ2(ID INT IDENTITY(-1,-1))

INSERT INTO AJ1 Default values
INSERT INTO AJ1 Default values
INSERT INTO AJ1 Default values

RollBack

select * from AJ1
select * from AJ2

I am getting the below mentioned message -

(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
ID
-----------
-1
0
1

(3 row(s) affected)

Msg 208, Level 16, State 1, Line 23
Invalid object name 'Aj2'

So now I am a bit confused that DDL statements can be rolledback if written in TRANSACTION.

Any suggestion or reference.

Regards,
AJ
HowardW
HowardW
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2231 Visits: 9892
No, pretty much everything that happens within the scope of an individual database is part of the transaction and can be rolled back, including DDL and indeed TRUNCATE (another transaction myth).

Have a look here for T-SQL Statements that are not allowed within a transaction:

http://msdn.microsoft.com/en-us/library/ms191544.aspx
AJ07
AJ07
SSC Veteran
SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)

Group: General Forum Members
Points: 202 Visits: 198
Hey thanks HowardW.

I got the details and now I have updated myself :-P


Regards,
AJ
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