獲取資料庫表的資訊(大小,索引大小,建立時間,行數)
-- =============================================
-- Author:
-- Create date:
-- Description:
--Thanks to ,, RBarry Young
-- =============================================
CREATE PROCEDURE [dbo].[spTableInformation]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
SCHEMA_NAME ( SYSTBL.SCHEMA_ID ) AS [SCHEMA] ,
SYSTBL.NAME ,
coalesce
(
(
SELECT NAME FROM sys.database_principals AS SDBP
WHERE ( PRINCIPAL_ID = SYSTBL.PRINCIPAL_ID )
) , SCHEMA_NAME ( SYSTBL.SCHEMA_ID )
)
AS OWNER ,
SYSTBL.MAX_COLUMN_ID_USED AS COLUMNS ,
cast
(
CASE SINDX_1.INDEX_ID
WHEN 1 THEN 1
ELSE 0
END
AS bit
)
AS HASCLUSIDX ,
coalesce
(
(
SELECT sum ( rows ) FROM sys.partitions AS SPART
WHERE ( object_id = SYSTBL.OBJECT_ID )
AND
( INDEX_ID < 2 )
) , 0
)
AS [ROWCOUNT] ,
coalesce
(
(
SELECT cast ( SPTV.low / 1024.0 AS float ) * sum
(
SAU_1.USED_PAGES -
CASE
WHEN SAU_1.TYPE <> 1 THEN SAU_1.USED_PAGES
WHEN SYSP.INDEX_ID < 2 THEN SAU_1.DATA_PAGES
ELSE 0
END
)
FROM sys.indexes AS SINDX_2
INNER JOIN sys.partitions AS SYSP ON SYSP.OBJECT_ID = SINDX_2.OBJECT_ID AND SYSP.INDEX_ID = SINDX_2.INDEX_ID
INNER JOIN sys.allocation_units AS SAU_1 ON SAU_1.CONTAINER_ID = SYSP.PARTITION_ID
WHERE ( SINDX_2.OBJECT_ID = SYSTBL.OBJECT_ID )
) , 0.0
)
AS INDEXKB ,
coalesce
(
(
SELECT cast ( SPTV.low / 1024.0 AS float ) * sum
(
CASE
WHEN SAU_2.TYPE <> 1 THEN SAU_2.USED_PAGES
WHEN SYSP.INDEX_ID < 2 THEN SAU_2.DATA_PAGES
ELSE 0
END
)
AS Expr1 FROM sys.indexes AS SINDX_2
INNER JOIN sys.partitions AS SYSP ON SYSP.OBJECT_ID = SINDX_2.OBJECT_ID AND SYSP.INDEX_ID = SINDX_2.INDEX_ID
INNER JOIN sys.allocation_units AS SAU_2 ON SAU_2.CONTAINER_ID = SYSP.PARTITION_ID
WHERE ( SINDX_2.OBJECT_ID = SYSTBL.OBJECT_ID )
) , 0.0
)
AS DATAKB ,
SYSTBL.CREATE_DATE ,
SYSTBL.MODIFY_DATE
FROM sys.tables AS SYSTBL
INNER JOIN sys.indexes AS SINDX_1 ON SINDX_1.OBJECT_ID = SYSTBL.OBJECT_ID AND SINDX_1.INDEX_ID < 2
INNER JOIN master.dbo.spt_values AS SPTV ON SPTV.NUMBER = 1 AND SPTV.type = 'E'
END
GO
-- Author:
-- Create date:
-- Description:
--Thanks to ,, RBarry Young
-- =============================================
CREATE PROCEDURE [dbo].[spTableInformation]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
SCHEMA_NAME ( SYSTBL.SCHEMA_ID ) AS [SCHEMA] ,
SYSTBL.NAME ,
coalesce
(
(
SELECT NAME FROM sys.database_principals AS SDBP
WHERE ( PRINCIPAL_ID = SYSTBL.PRINCIPAL_ID )
) , SCHEMA_NAME ( SYSTBL.SCHEMA_ID )
)
AS OWNER ,
SYSTBL.MAX_COLUMN_ID_USED AS COLUMNS ,
cast
(
CASE SINDX_1.INDEX_ID
WHEN 1 THEN 1
ELSE 0
END
AS bit
)
AS HASCLUSIDX ,
coalesce
(
(
SELECT sum ( rows ) FROM sys.partitions AS SPART
WHERE ( object_id = SYSTBL.OBJECT_ID )
AND
( INDEX_ID < 2 )
) , 0
)
AS [ROWCOUNT] ,
coalesce
(
(
SELECT cast ( SPTV.low / 1024.0 AS float ) * sum
(
SAU_1.USED_PAGES -
CASE
WHEN SAU_1.TYPE <> 1 THEN SAU_1.USED_PAGES
WHEN SYSP.INDEX_ID < 2 THEN SAU_1.DATA_PAGES
ELSE 0
END
)
FROM sys.indexes AS SINDX_2
INNER JOIN sys.partitions AS SYSP ON SYSP.OBJECT_ID = SINDX_2.OBJECT_ID AND SYSP.INDEX_ID = SINDX_2.INDEX_ID
INNER JOIN sys.allocation_units AS SAU_1 ON SAU_1.CONTAINER_ID = SYSP.PARTITION_ID
WHERE ( SINDX_2.OBJECT_ID = SYSTBL.OBJECT_ID )
) , 0.0
)
AS INDEXKB ,
coalesce
(
(
SELECT cast ( SPTV.low / 1024.0 AS float ) * sum
(
CASE
WHEN SAU_2.TYPE <> 1 THEN SAU_2.USED_PAGES
WHEN SYSP.INDEX_ID < 2 THEN SAU_2.DATA_PAGES
ELSE 0
END
)
AS Expr1 FROM sys.indexes AS SINDX_2
INNER JOIN sys.partitions AS SYSP ON SYSP.OBJECT_ID = SINDX_2.OBJECT_ID AND SYSP.INDEX_ID = SINDX_2.INDEX_ID
INNER JOIN sys.allocation_units AS SAU_2 ON SAU_2.CONTAINER_ID = SYSP.PARTITION_ID
WHERE ( SINDX_2.OBJECT_ID = SYSTBL.OBJECT_ID )
) , 0.0
)
AS DATAKB ,
SYSTBL.CREATE_DATE ,
SYSTBL.MODIFY_DATE
FROM sys.tables AS SYSTBL
INNER JOIN sys.indexes AS SINDX_1 ON SINDX_1.OBJECT_ID = SYSTBL.OBJECT_ID AND SINDX_1.INDEX_ID < 2
INNER JOIN master.dbo.spt_values AS SPTV ON SPTV.NUMBER = 1 AND SPTV.type = 'E'
END
GO
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16436858/viewspace-609719/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何獲取 PostgreSQL 資料庫中的表大小、資料庫大小、索引大小、模式大小、表空間大小、列大小SQL資料庫索引模式
- [轉帖]達夢資料庫-統計資料表資料量及空間表大小資料庫
- 查詢MySQL資料庫,MySQL表的大小MySql資料庫
- 在MySQL中,如何獲取資料庫下所有表的資料行數?MySql資料庫
- 查詢資料庫大小資料庫
- 達夢資料庫表空間等空間大小查詢方法總結資料庫
- 查詢資料庫每個表佔用的大小資料庫
- 獲取bitmap大小
- 查詢資料庫的資料量的大小資料庫
- 統計資料庫中表大小資料庫
- MySQL命令檢視資料庫和表容量大小MySql資料庫
- SQLServer查詢所有資料庫大小SQLServer資料庫
- 資料庫之建立索引資料庫索引
- 達夢資料庫之初始化頁大小對於表及表空間的影響分析資料庫
- DB2建立資料庫,建立表空間DB2資料庫
- SQL Server統計資料庫中表大小SQLServer資料庫
- 檢視oracle資料庫真實大小Oracle資料庫
- 獲取網路圖片的大小
- Oracle獲取資料庫中的物件建立語句Oracle資料庫物件
- expdp在匯出時對資料大小進行評估
- windows資料夾大小Windows
- 更改undo表空間大小
- mongodb資料庫如何建立索引?MongoDB資料庫索引
- mysql資料庫中decimal資料型別比較大小MySql資料庫Decimal資料型別
- ODI基於源表時間戳欄位獲取增量資料時間戳
- 如何獲取 Linux 中的目錄大小Linux
- jquery獲取圖片的真實大小jQuery
- JavaScript獲取圖片的真實大小JavaScript
- 建立資料庫表資料庫
- ElasticSearch 獲取es資訊以及索引操作Elasticsearch索引
- SAP中的資料庫表索引資料庫索引
- 實用小工具——快速獲取資料庫時間寫法資料庫
- Oracle獲取所有表名資訊和獲取指定表名欄位資訊Oracle
- MySQL 資料庫表格建立、資料插入及獲取插入的 ID:Python 教程MySql資料庫Python
- SQL SERVER 2012查詢資料庫和所有表的大小方法彙總SQLServer資料庫
- 2.6.5 指定資料塊大小
- 如何獲取EMMC記憶體大小記憶體
- 取樣頻率、時間、聲道、量化、儲存大小
- Classy:根據資料庫表在執行時建立類/模型資料庫模型