1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SQLServerでテーブルごとの統計情報の最終更新日時を取得したい

Posted at

SQLServerでテーブルごとの統計情報の最終更新日時を取得したい場合、sys.statsテーブルとSTATS_DATE関数を活用します。

たとえばEMPテーブルとDEPTテーブルの統計情報の最終更新日時を取得したい場合は以下のようなSQLで実現できます。

SELECT 
  OBJECT_NAME(object_id) AS table_name,
  name AS index_name,
  STATS_DATE(object_id, stats_id) AS last_updated
FROM sys.stats
WHERE OBJECT_NAME(object_id) IN ('EMP', 'DEPT')

このSQLを実行すると、以下のような結果を得ることができるはずです。

table_name index_name last_updated
EMP PK_EMP_001 2022/10/29 12:15:08.157
EMP IX_EMP_001 2022/10/29 12:15:08.163
EMP IX_EMP_002 2022/10/29 12:15:08.167
EMP IX_EMP_003 2022/10/29 12:15:08.173
DEPT PK_DEPT_001 2022/10/29 12:15:08.190
DEPT IX_DEPT_001 2022/10/29 12:15:08.200
DEPT IX_DEPT_002 2022/10/29 12:15:08.203

環境情報

Microsoft SQL Server 2019 (RTM-CU9) (KB5000642) - 15.0.4102.2 (X64) 
	Jan 25 2021 20:16:12 
	Copyright (C) 2019 Microsoft Corporation
	Developer Edition (64-bit) on Linux (Ubuntu 18.04.5 LTS) <X64>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?