1

I plan to get all tables with their total row count in sql server 2000.

For which I did :

sp_msforeachtable 'select count(*) from ?' 

In this column header is not mentioned, because of which its not distinguishable to which row count belongs to which table

For which I altered this by :

sp_msforeachtable 'select count(*) as ? from ?' 

But its throwing an error as :

Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '.'.

Could you please guide on this

3 Answers 3

3

Try this:

SELECT
    sysobjects.Name, sysindexes.Rows
FROM
    sysobjects
    INNER JOIN sysindexes
    ON sysobjects.id = sysindexes.id
WHERE
    type = 'U'
    AND sysindexes.IndId < 2
Sign up to request clarification or add additional context in comments.

13 Comments

What do you mean by "sysindexes.IndId < 2" & why?
Only for Heap and clustered Indexes
Will that include all the tables? Tables which will not have any indexes not even primary key?
Yes they will be included too
Looks like it isn't realtime, but could be made to be so: sql-server-performance.com/forum/threads/sysindexes-table.13767 not sure how this would affect performance though!
|
3

I guess I got it :

exec sp_MSforeachtable 'select count(*) as nr_of_rows, ''?'' 
  as table_name from ?'

1 Comment

It helped me to update statistics of all tables in one shot as: EXEC sp_MSforeachtable 'Update Statistics ? with FULLSCAN';
0

Try this instead:

sp_MSforeachtable 'select ''?'' Tablename, count(*) ''Rows'' from ?'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.