Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

How to get the number of rows from a table reside in a linked server as fast as possible. Expand / Collapse
Author
Message
Posted Wednesday, January 21, 2009 12:25 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 29, 2011 4:36 PM
Points: 129, Visits: 37
Thanks Jacob for your valuable suggestion. Definitely I will try to implement it and let you know if I face any issue. Could you please tell me any other solution where I don't have to create any sp in remote server because we are not the owner of that server and it would be difficult to get permission to create a stored procedure in that server. It is fine if I create a SP in our server (the server belongs to our application).
Post #640459
Posted Wednesday, January 21, 2009 12:34 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, November 14, 2014 12:35 AM
Points: 115, Visits: 647
SELECT rows FROM sysindexes
WHERE id = OBJECT_ID('YourTableName') AND indid < 2


The above query is good, but it will give the accurate count all the time. Since it takes the count using the index.
It depends on the index how you created.

If you need more info on this check msdn help on indexes and rowcount of sysninexs table.
Post #640463
Posted Wednesday, January 21, 2009 1:09 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, March 6, 2014 6:13 PM
Points: 318, Visits: 1,183
@abhishek:

In that case you will have to use Ramesh's approach (if you want to use sysindexes). Make sure that the local server collation matches the remote server collation exactly, and specify Collation Compatible = True on your linker server definition.

If you want an accurate result you're stuck with COUNT(), in which case collation doesn't matter.

Regards,

Jacob
Post #640477
Posted Thursday, January 22, 2009 12:56 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, November 14, 2014 12:35 AM
Points: 115, Visits: 647
The above query is good, but it will give the accurate count all the time. Since it takes the count using the index.
It depends on the index how you created.

If you need more info on this check msdn help on indexes and rowcount of sysninexs table.



sorry for the typo.. it should be....

The above query is good, but it will not give the accurate count all the time. Since it takes the count using the index.
It depends on the index how you created.

If you need more info on this check msdn help on indexes and rowcount of sysnindexs table.
Post #642004
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse