I need to get the row count for all the tables in my databse.
Rather than doing:
select count(*) from table_name
I was going to do:
SELECT rows FROM sysindexes
WHERE name = 'table_name'
But this does not always return a row.
For 90% of the tables in my database it does, but for the other 10% no row exists in sysindexes. I'm not sure why this is.
Someone else suggested doing it like this:
SELECT rows FROM sysindexes
WHERE id = OBJECT_ID('table_name')
AND indid < 2
Now, that always returns a row for every table, but the value it returns does not always match with the results of select count(*)
Any ideas or thoughts on what is wrong with how I am doing this, or the quickest way to retrieve row count?
Thanks.
Rather than doing:
select count(*) from table_name
I was going to do:
SELECT rows FROM sysindexes
WHERE name = 'table_name'
But this does not always return a row.
For 90% of the tables in my database it does, but for the other 10% no row exists in sysindexes. I'm not sure why this is.
Someone else suggested doing it like this:
SELECT rows FROM sysindexes
WHERE id = OBJECT_ID('table_name')
AND indid < 2
Now, that always returns a row for every table, but the value it returns does not always match with the results of select count(*)
Any ideas or thoughts on what is wrong with how I am doing this, or the quickest way to retrieve row count?
Thanks.