Hi @sakuraime ,
How to check last index rebuild time ( instead of checking last update stats time)?
If my understanding is right, you want to know the last update time of executing the t_sql of rebuiding the index.
Actually,you can find all the operations for changing the table in your transaction log, run code as next or use tool as Apex SQL,it will show clearly what you have done of the data, and it is more easier to understand than reading log information by using dbcc log:
DBCC LOG('Adventureworks2017',3)
However, you need to know what the information means of the record , there is one description column, you can check the details of the transaction:
Note: if you want to know last update stats time,you can try code as next, though I guess you have already knew the code.
Try code as next:
DECLARE @table_name NVARCHAR(32);
SET @table_name='Person.Person'
SELECT sch.name + '.' + so.name AS table_name
, so.object_id
, ss.name AS stat_name
, ds.stats_id
, ds.last_updated
, ds.rows
, ds.rows_sampled
, ds.rows_sampled*1.0/ds.rows *100 AS sample_rate
, ds.steps
, ds.unfiltered_rows
--, ds.persisted_sample_percent
, ds.modification_counter
, 'UPDATE STATISTICS ' + QUOTENAME(DB_NAME()) + '.' + QUOTENAME(sch.name) + '.' + QUOTENAME( so.name) + ' "' + RTRIM(LTRIM(ss.name)) + '" WITH SAMPLE 80 PERCENT;'
AS update_stat_script
FROM sys.stats ss
JOIN sys.objects so ON ss.object_id = so.object_id
JOIN sys.schemas sch ON so.schema_id = sch.schema_id
CROSS APPLY sys.dm_db_stats_properties(ss.object_id,ss.stats_id) ds
WHERE so.is_ms_shipped = 0
AND so.object_id NOT IN (
SELECT major_id
FROM sys.extended_properties (NOLOCK)
WHERE name = N'microsoft_database_tools_support' )
AND so.object_id =OBJECT_ID(@table_name)
BR,
Mia
If the answer is helpful, please click "Accept Answer" and upvote it.