您好我想写一个SQL SELECT语句,它显示模式中每个用户表的行数及其当前索引。数据库是SQL Server 2008 R2。
我可以毫无问题地编写行计数,但我不知道如何在结果中添加DBCC CHECKIDENT。
请帮助,谢谢!
答案 0 :(得分:2)
很难从问题中确切地知道您正在寻找什么输出,但以下内容可能提供一个起点:
USE AdventureWorks2012;
GO
SELECT
column_name =
QUOTENAME(OBJECT_SCHEMA_NAME(ic.[object_id])) + N'.' +
QUOTENAME(OBJECT_NAME(ic.[object_id])) + N'.' +
QUOTENAME(ic.name),
ic.seed_value,
ic.increment_value,
ic.last_value,
p.row_count
FROM sys.identity_columns AS ic
CROSS APPLY
(
SELECT
SUM(p.[rows])
FROM sys.partitions AS p
WHERE
p.[object_id] = ic.[object_id]
AND p.index_id IN (0, 1)
) AS p (row_count)
ORDER BY
p.row_count DESC;