Re: Is there ever a reason to have a transaction around a select..



It can be very complicated. When you query against any dynamic table (one
that is being constantly updated), there is always a chance that the data
will change in the course of the SELECT. The rows being selected are not
determined until the query engine finds them--row-by-row. Once the internal
cache-size rows (about 4K) are found during the SELECT operation, the client
application is notified and the search (SELECT) process stops. Once the
client empties the cache (as with DataReader.Read) new rows are located and
cached. During this process fetched rows (rows already sent to the client)
could have been deleted, new rows could have been added (in the range of
rows already sent or not yet sent to the client), existing rows could have
been changed--those sent, or those not sent. With the disconnected model (as
opposed to server-side cursors) the client gets a snapshot of the "window"
on the rowset state as the SELECT query walks the query plan fetch rowset.
If it's critical that you need a consistent set of rows at a point in time,
then you need to take steps to build a consistent rowset. I doubt if
transactions will help, but it might. The problem with locking down the
server while you fetch rows is that it cripples scalability--other
applications must wait while a specific client fetches a rowset. I would be
hesitant to endorse this approach. Most reports that require this behavior
but use parallel database snapshots made at specific times during the day.
Another approach is to SELECT into a #temp table that is not subject to
changes. The new database snapshot feature in SQL Server 2005 helps here
too. This is another reason why it does not make sense to do a COUNT(*) to
determine the number of rows that will be fetched with a SELECT--an instant
later when the rows are actually fetched, the count would be off.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:u19eMMJdHHA.4352@xxxxxxxxxxxxxxxxxxxxxxx
Depends on default implicit transaction defined by database on what
records you get.
Anyway, what exactly are "self-consistent" records?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"David Thielen" <thielen@xxxxxxxxxxxxx> wrote in message
news:82C164CA-07CB-4520-9779-593F604D7338@xxxxxxxxxxxxxxxx
I guess my question is if there is no transaction, will the ResultSet come
back self-consistent? I know a split-second later it could be wrong as an
insert or update can hit the table but that is also true with a
transaction
after I call Commit after the select.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"Miha Markic [MVP C#]" wrote:

It depends on your requirements but usually there is no need for
(explicit)
transaction.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"David Thielen" <thielen@xxxxxxxxxxxxx> wrote in message
news:88DB2D9D-01F6-403F-93AF-1CABC892247B@xxxxxxxxxxxxxxxx
1) that will always return 0 or 1 rows?

2) that will retun N rows?

In each case where the results will be displayed to the user and so
there
can be changes that occur to the DB after the select completes.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm







.



Relevant Pages

  • Re: Is there ever a reason to have a transaction around a select..
    ... Cubicle Wars - http://www.windwardreports.com/film.htm ... cache-size rows are found during the SELECT operation, the client ... on the rowset state as the SELECT query walks the query plan fetch rowset. ... Hitchhiker's Guide to Visual Studio and SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: SqlDataReader performance
    ... much of the database to the client to process. ... As far as making the server-side query run faster, ... Hitchhiker's Guide to Visual Studio and SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: SQL Server 2000 query time out option, what does it do?
    ... The drop down menu ran a select query for 13 hours. ... > SQL sees the query as a valid running query and the timeout is ignored. ... When a client runs a query on SQL Server, and gets back a result set, to ...
    (comp.databases.ms-sqlserver)
  • Re: Order query result
    ... SQL Server let e take ... is free to execute the query in any way it finds to be the most efficient way. ... The client is trying to contact Mr. ... he is on vacation, please let him now about it ...
    (microsoft.public.sqlserver.server)
  • Re: Mysterious Port of SQL Server not shown by netstat
    ... If this fails then yoru SQL Server is not listening on 1433. ... port, only ms-sql-s). ... > My query analyzer client from local machine and remote machine> successfully connects to my server. ... There is a jdbc client which wants> to connect at port 1433 that fails saying could not establish network> connection at port 1433. ...
    (microsoft.public.sqlserver.programming)