1

我计划在 sql server 2000 中获取所有表及其总行数。

我为此做了:

sp_msforeachtable 'select count(*) from ?' 

在这个列标题中没有提到,因为它无法区分哪个行数属于哪个表

为此我改变了这个:

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

但它抛出一个错误:

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

你能指导一下吗

4

3 回答 3

3

尝试这个:

SELECT
    sysobjects.Name, sysindexes.Rows
FROM
    sysobjects
    INNER JOIN sysindexes
    ON sysobjects.id = sysindexes.id
WHERE
    type = 'U'
    AND sysindexes.IndId < 2
于 2013-01-08T10:36:32.393 回答
3

我想我明白了:

exec sp_MSforeachtable 'select count(*) as nr_of_rows, ''?'' 
  as table_name from ?'
于 2013-01-08T10:37:34.237 回答
0

试试这个:

sp_MSforeachtable 'select ''?'' Tablename, count(*) ''Rows'' from ?'
于 2013-01-08T10:39:10.460 回答