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 2005 Forums
 Transact-SQL (2005)
 Transaction in select statements?

Author  Topic 

rudesyle
Posting Yak Master

110 Posts

Posted - 2007-09-11 : 09:26:46
Hi guys. I just cracked open a clients Sql 2005 database, and notice that the people who developed this use transactions in simple select statements in stored procedures (no update,del,or ins).

I've never seen this before. Is there a good reason to do so? I mean, there's no database modification going on, so I see no reason to do this?

Kristen
Test

22859 Posts

Posted - 2007-09-11 : 10:00:50
A single SELECT statement is atomic ...

... have they got multiple Select statements within the Transaction?

Kristen
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-09-11 : 10:17:26
No reason, A lot of times I see people use a pre-designed template for all their stored procedures that start with the begin tran syntax. That's probably all this is, it's just what the programmers were used to. There is no need for it though.
Go to Top of Page

rudesyle
Posting Yak Master

110 Posts

Posted - 2007-09-11 : 11:10:14
quote:
Originally posted by Kristen

A single SELECT statement is atomic ...

... have they got multiple Select statements within the Transaction?

Kristen



Usually, but I've seen some singles too. Also, I see them enclose CTE's within a transaction. What sense does this make if no data is being updated?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-09-11 : 11:23:11
I do it, but I don't think it matters

This way all of the sprocs have the same loomk and feel, and I don't have to think about it

Have you seen any error handling?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -