For Day 26 of this series, we start out with Query #59<\/strong>, which is Table Properties. This query retrieves information from the sys.tables<\/a> object catalog view, and the sys.partitions<\/a> object catalog view about various table properties in the current database. Query #59 is shown in Figure 1.<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 1: Query #59 Table Properties<\/strong><\/p>\n This query helps you understand what is going on with properties for the tables in the current database, showing you things such as whether they are being replicated, being tracked by change data capture, whether they are Hekaton tables, whether they are StretchDB<\/a> tables, etc. It also shows you the data compression status for every index in each table. This can help you find possible data compression candidates.<\/p>\n <\/strong> <\/p>\n Query #60<\/strong> is Statistics Update. This query retrieves information from the sys.objects<\/a> object catalog view, the sys.indexes<\/a> object catalog view, the sys.stats<\/a> object catalog view, and the sys.dm_db_partition_stats<\/a> dynamic management view about the properties and status of the statistics in the current database. Query #60 is shown in Figure 2.<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 2: Query #60 Statistics Update<\/strong><\/p>\n This query shows you a number of relevant properties about the index-associated statistics in your current database, ordered by the last time that statistics were updated. This can help you determine whether you might have a problem with out of date statistics. My general guidance about statistics is that you should use the default database properties of auto create and auto update for statistics, plus I think you should also use the auto update statistics asynchronously database property, along with global trace flag 2371<\/a>. In some situations, you may also want\/need to do additional statistics maintenance on highly volatile tables with SQL Server Agent jobs.<\/p>\n","protected":false},"excerpt":{"rendered":" For Day 26 of this series, we start out with Query #59, which is Table Properties. This query retrieves information from the sys.tables object catalog view, and the sys.partitions object catalog view about various table properties in the current database. Query #59 is shown in Figure 1. 1: — Get some key table properties (Query […]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[272],"class_list":["post-1054","post","type-post","status-publish","format-standard","hentry","category-dmv-diagnostic-queries-detailed","tag-dmv-diagnostic-queries-detailed"],"yoast_head":"\n 1:<\/span> -- Get some key table properties (Query 59) (Table Properties)<\/span><\/pre>\n 2:<\/span> SELECT<\/span> OBJECT_NAME(t.[object_id]) AS<\/span> [ObjectName], p.[rows<\/span>] AS<\/span> [Table<\/span> Rows<\/span>], p.index_id, <\/pre>\n 3:<\/span> p.data_compression_desc AS<\/span> [Index<\/span> Data<\/span> Compression],<\/pre>\n 4:<\/span> t.create_date, t.lock_on_bulk_load, t.is_replicated, t.has_replication_filter, <\/pre>\n 5:<\/span> t.is_tracked_by_cdc, t.lock_escalation_desc, t.is_memory_optimized, t.durability_desc, t.is_filetable,<\/pre>\n 6:<\/span> t.temporal_type_desc, t.is_remote_data_archive_enabled, t.remote_data_archive_migration_state_desc, t.is_external -- new for SQL Server 2016<\/span><\/pre>\n 7:<\/span> FROM<\/span> sys.tables AS<\/span> t WITH<\/span> (NOLOCK)<\/pre>\n 8:<\/span> INNER<\/span> JOIN<\/span> sys.partitions AS<\/span> p WITH<\/span> (NOLOCK)<\/pre>\n 9:<\/span> ON<\/span> t.[object_id] = p.[object_id]<\/pre>\n 10:<\/span> WHERE<\/span> OBJECT_NAME(t.[object_id]) NOT<\/span> LIKE<\/span> N'sys%'<\/span><\/pre>\n 11:<\/span> ORDER<\/span> BY<\/span> OBJECT_NAME(t.[object_id]), p.index_id OPTION<\/span> (RECOMPILE);<\/pre>\n 12:<\/span> <\/pre>\n 13:<\/span> -- Gives you some good information about your tables<\/span><\/pre>\n 14:<\/span> -- Is Memory optimized and durability description are Hekaton-related properties that were new in SQL Server 2014<\/span><\/pre>\n 15:<\/span> -- temporal_type_desc, is_remote_data_archive_enabled, remote_data_archive_migration_state_desc, is_external are new in SQL Server 2016<\/span><\/pre>\n 1:<\/span> -- When were Statistics last updated on all indexes? (Query 60) (Statistics Update)<\/span><\/pre>\n 2:<\/span> SELECT<\/span> SCHEMA_NAME(o.Schema_ID) + N'.'<\/span> + o.NAME AS<\/span> [Object<\/span> Name], o.type_desc AS<\/span> [Object<\/span> Type],<\/pre>\n 3:<\/span> i.name AS<\/span> [Index<\/span> Name], STATS_DATE(i.[object_id], i.index_id) AS<\/span> [Statistics<\/span> Date<\/span>], <\/pre>\n 4:<\/span> s.auto_created, s.no_recompute, s.user_created, s.is_incremental, s.is_temporary,<\/pre>\n 5:<\/span> st.row_count, st.used_page_count<\/pre>\n 6:<\/span> FROM<\/span> sys.objects AS<\/span> o WITH<\/span> (NOLOCK)<\/pre>\n 7:<\/span> INNER<\/span> JOIN<\/span> sys.indexes AS<\/span> i WITH<\/span> (NOLOCK)<\/pre>\n 8:<\/span> ON<\/span> o.[object_id] = i.[object_id]<\/pre>\n 9:<\/span> INNER<\/span> JOIN<\/span> sys.stats AS<\/span> s WITH<\/span> (NOLOCK)<\/pre>\n 10:<\/span> ON<\/span> i.[object_id] = s.[object_id] <\/pre>\n 11:<\/span> AND<\/span> i.index_id = s.stats_id<\/pre>\n 12:<\/span> INNER<\/span> JOIN<\/span> sys.dm_db_partition_stats AS<\/span> st WITH<\/span> (NOLOCK)<\/pre>\n 13:<\/span> ON<\/span> o.[object_id] = st.[object_id]<\/pre>\n 14:<\/span> AND<\/span> i.[index_id] = st.[index_id]<\/pre>\n 15:<\/span> WHERE<\/span> o.[type] IN<\/span> ('U'<\/span>, 'V'<\/span>)<\/pre>\n 16:<\/span> AND<\/span> st.row_count > 0<\/pre>\n 17:<\/span> ORDER<\/span> BY<\/span> STATS_DATE(i.[object_id], i.index_id) DESC<\/span> OPTION<\/span> (RECOMPILE); <\/pre>\n 18:<\/span> <\/pre>\n 19:<\/span> -- Helps discover possible problems with out-of-date statistics<\/span><\/pre>\n 20:<\/span> -- Also gives you an idea which indexes are<\/span> the most active<\/pre>\n