Wednesday, 22 July 2020

[SQL Server] Index created date, Index last modified date

[SQL Server] Index created date, Index last modified date

How do we know the index created date or index last modified date?
The correct answer (so far) is "WE DON'T KNOW!"

You can get created date for PK(Primary key), FK(Foreign key) and UK(Unique key) by the following script.
SELECT 
    OBJECT_NAME(o.parent_object_id) AS TableName,
    i.NAME AS 'Index Name', 
    o.create_date
FROM sys.indexes i
     INNER JOIN sys.objects o ON i.NAME = o.NAME
WHERE o.is_ms_shipped = 0
    AND o.type IN('PK', 'FK', 'UQ')
    AND OBJECT_NAME(o.parent_object_id) = 'Employee'
ORDER BY
 OBJECT_NAME(o.parent_object_id)
;



You can also get the stats created date for the indexes by the following script.

SELECT 
 'HumanResources.Employee' AS TableName,
 Name AS IndexName, 
    STATS_DATE(object_id, index_id) AS IndexStatsDate
FROM sys.indexes
WHERE object_id = OBJECT_ID('HumanResources.Employee');





No comments:

Post a Comment

(KOR)☁️ AWS Solutions Architect Associate 자격증 취득 여정

  !저의 경험 , 팁 , 그리고 SAA-C03 자격증 합격을 위한 노하우 공유! 조금 늦은 포스팅이지만 , 꼭 공유하고 싶었던 이야기입니다 . 회사 내 주변 동료들이 자주 이렇게 말하곤 했습니다 . “ 님 실...