English 中文(简体)
2008年5月5日
原标题:MS SQL 2008 - get all table names and their row counts in a DB

我试图通过申请(由他人开发)确定哪些表格受到数据更新的影响。 亚洲开发银行有200多个表格,我想避免对每个表格进行改动。

Is there any other way where I can list all table names along with their row count?

select table_name from information_schema.tables

在我的行文中列出所有表格,我如何也包含一些行文?

最佳回答
SELECT sc.name + . + ta.name TableName
 ,SUM(pa.rows) RowCnt
 FROM sys.tables ta
 INNER JOIN sys.partitions pa
 ON pa.OBJECT_ID = ta.OBJECT_ID
 INNER JOIN sys.schemas sc
 ON ta.schema_id = sc.schema_id
 WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
 GROUP BY sc.name,ta.name
 ORDER BY SUM(pa.rows) DESC

参见:

问题回答

将所有表格输入数据库:

select * from INFORMATION_SCHEMA.TABLES

a. 将所有栏目输入数据库:

select * from INFORMATION_SCHEMA.columns

a. 收集所有意见。

select * from INFORMATION_SCHEMA.TABLES where table_type =  view 

简单而快捷

SELECT T.name AS [TABLE NAME], I.rows AS [ROWCOUNT] 
FROM   sys.tables AS T 
   INNER JOIN sys.sysindexes AS I ON T.object_id = I.id 
   AND I.indid < 2 ORDER  BY I.rows DESC

将每个表格的浏览量输入数据库。 也可以通过改变SCHEMA_NAME来过滤。

SELECT
      QUOTENAME(SCHEMA_NAME(sOBJ.schema_id)) +  .  + QUOTENAME(sOBJ.name) AS [TableName]
      , SUM(sPTN.Rows) AS [RowCount]

FROM 
      sys.objects AS sOBJ
      INNER JOIN sys.partitions AS sPTN
            ON sOBJ.object_id = sPTN.object_id
WHERE
      sOBJ.type =  U 
      AND SCHEMA_NAME(sOBJ.schema_id) =  dbo 
      AND sOBJ.is_ms_shipped = 0x0
      AND index_id < 2 -- 0:Heap, 1:Clustered
GROUP BY 
      sOBJ.schema_id
      , sOBJ.name
ORDER BY SUM(sPTN.Rows),[TableName]




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8