Re: counting records in select query
From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 02/01/05
- Next message: cschang: "Re: Call javascript function without using any event call"
- Previous message: Kevin Yu [MSFT]: "Re: date format in parameter"
- In reply to: Konrad: "Re: counting records in select query"
- Next in thread: Konrad: "Re: counting records in select query"
- Reply: Konrad: "Re: counting records in select query"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 31 Jan 2005 18:24:35 -0800
Yes, but the count might not be particularly accurate and it will hurt
performance.
You can execute a SELECT COUNT(*) with the appropriate WHERE clause to
return a count of the rows that qualify for the rowset. However, this takes
almost the same amount of time (especially for complex queries) to run the
query. This means it will cost nearly twice as much as executing the query
without counting the rows first. In addition, since the number of member
rows could change from the time you count to the time you query, the count
could be off--way off. For simple queries counting is fine--but it just
hurts scalability.
hth
-- ____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP 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. __________________________________ "Konrad" <konrad007@poczta.onet.pl> wrote in message news:OtftJu2BFHA.2016@TK2MSFTNGP15.phx.gbl... > Iterate through all records isn't big problem in my case > because number of records returned is about to 1000. > And as I see it takes lower than 1 sec. > But I'am using SQL Server over internet and sending > this records is bigger problem. So I want to know > how many records is to send and does this operation should > be completed or not. > Do you know how count number of records to send > having select query? > > Best regards > Konrad > > > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message > news:e6UA0ewBFHA.2428@TK2MSFTNGP14.phx.gbl... >> Hi, >> >> This not a good practice. Counting records has to iterate through all >> records on server and you'll probably have to run one select for counting >> and the other for returning the actual records. >> Why don't you simply limit the select with TOP (or similar) clause? >> >> -- >> Miha Markic [MVP C#] - RightHand .NET consulting & development >> SLODUG - Slovene Developer Users Group >> www.rthand.com >> >> "Konrad" <konrad007@poczta.onet.pl> wrote in message >> news:OCshCLwBFHA.2196@TK2MSFTNGP14.phx.gbl... >> > Hi >> > >> > I have complicated select query >> > how to get prior number of records >> > returned from this query. >> > One number, to decide >> > if records should be loaded. >> > >> > Thanks >> > Konrad >> > >> > >> >> > >
- Next message: cschang: "Re: Call javascript function without using any event call"
- Previous message: Kevin Yu [MSFT]: "Re: date format in parameter"
- In reply to: Konrad: "Re: counting records in select query"
- Next in thread: Konrad: "Re: counting records in select query"
- Reply: Konrad: "Re: counting records in select query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|