SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to get the number of rows from a table reside in a linked server as fast as possible.


How to get the number of rows from a table reside in a linked server as fast as possible.

Author
Message
abhishek.sahoo
abhishek.sahoo
SSC-Enthusiastic
SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)

Group: General Forum Members
Points: 169 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).
brainy
brainy
Mr or Mrs. 500
Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)

Group: General Forum Members
Points: 593 Visits: 649
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.
Jacob Luebbers
Jacob Luebbers
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1360 Visits: 1215
@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
brainy
brainy
Mr or Mrs. 500
Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)Mr or Mrs. 500 (593 reputation)

Group: General Forum Members
Points: 593 Visits: 649
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search