If I ask anyone how to find the number of rows in a table everyone would give in a immediate answer just do count(*) from the table to find the total row count.
Now let me add some more restrcitions to the same , I would want the query not to be using the table name in the from clause,then you might wonder how is that possible , use the below query to acheive the same.
select rowcnt
from sysindexes
where indid = 1
and id = object_id('sysobjects')
Here Indid = 1 refers to the clustered index,hence needless to say that the query will work only if table has clustered index and the indexes are built regularly.
No comments:
Post a Comment