Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 implicit_transactions confusion

Author  Topic 

influent
Constraint Violating Yak Guru

367 Posts

Posted - 2007-07-25 : 14:29:08
I created a table called "version" with one varchar(50) column. The first insert below causes an error because it's greater than 50 characters (intentional) Why does the following insert "test3" into the table, shouldn't the whole thing be rolled back because it's using implicit_transactions?


set implicit_transactions on

insert into version
select '12345678901234657890123456798012345678901234567890123'

insert into version
select 'test3'

commit
set implicit_transactions off

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-25 : 14:35:55
No, implicit transactions commit each statement after it completes. It does not wait to do it after the batch. You need to use explicit transactions.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

influent
Constraint Violating Yak Guru

367 Posts

Posted - 2007-07-25 : 14:44:41
Then I don't see the point of implicit transactions. ???
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-25 : 14:47:06
You shouldn't use them if you have multiple DML operations that need to committed as a batch or rolled back as a batch. If each DML operation is independent of each other, then implicit transactions can be used.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

influent
Constraint Violating Yak Guru

367 Posts

Posted - 2007-07-25 : 16:19:09
What's the point of a having a "transaction" if each operation is independent?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-25 : 16:27:47
You don't need explicit transactions if you don't care about data integrity of the individual statements in the batch.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -