{"id":9034,"date":"2022-07-22T06:52:00","date_gmt":"2022-07-22T04:52:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=9034"},"modified":"2022-08-04T14:17:38","modified_gmt":"2022-08-04T12:17:38","slug":"last-time-table-was-updated-sql-server","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/","title":{"rendered":"Last time table was updated in SQL Server"},"content":{"rendered":"\n<p>How to check the last date a table was updated on a SQL Server database? Check the last access and update with a simple SQL query? Thanks to the SQL Server relational database management system tables, a query allows you to display the last changes done. We can apply it to any SQL Server table or view, like last scans, or last updates for example.&nbsp;<\/p>\n\n\n\n<p>This feature is especially useful for audit purpose or database troubleshooting, after data integration for example. The query shows also the number of updates made and the last update time&nbsp; for the table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-get-the-last-date-and-time-a-table-was-updated-in-sql-server\">Get the last date and time a table was updated in SQL Server<\/h2>\n\n\n\n<p>Indeed, the goal here is to know when a specific table has been updated. For exemple when the SQL framework in place do not update metadata like insert date or update. <\/p>\n\n\n\n<p>Please note that the metadata is something highly recommended especially with sensitive data and large amount of data. <\/p>\n\n\n\n<p>The SQL query uses the table <strong>sys.tables<\/strong> and the <strong>sys.dm_db_index_usage_stats<\/strong> system tables.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT\t\n    object_name(STAT.object_id) AS ObjectName, \n    USER_SEEKS,\n    USER_SCANS,\n    USER_LOOKUPS,\n    USER_UPDATES,\n    LAST_USER_SEEK,\n    LAST_USER_SCAN,\n    LAST_USER_LOOKUP,\n    LAST_USER_UPDATE\nFROM\tSYS.DM_DB_INDEX_USAGE_STATS STAT JOIN\n        SYS.TABLES TAB ON (TAB.OBJECT_ID = STAT.OBJECT_ID)\nWHERE \tDATABASE_ID = DB_ID();\n<\/pre>\n\n\n\n<p>In this example, let us consider only the sales table, and the number of access made is one.<\/p>\n\n\n\n<p>I.e., for reading the data, the information is in the column &#8220;<strong>Last User Scan<\/strong>&#8220;. We also see one update in the column named &#8220;<strong>Last User Update<\/strong>&#8220;.<\/p>\n\n\n\n<p>To achieve this result, very useful in some cases, the example uses the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/system-dynamic-management-views\/sys-dm-db-index-usage-stats-transact-sql?view=sql-server-ver15\" target=\"_blank\" rel=\"noopener noreferrer\">SYS.DM_DB_INDEX_USAGE_STATS<\/a> system table.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/expert-only.net\/wp-content\/uploads\/2017\/06\/sql-server-table-query-access-update-stats-1.jpg\" alt=\"Get the last date a table was updated on SQL Server\" class=\"wp-image-452\"\/><figcaption><strong>Get the last date a table was updated on SQL Server<\/strong><\/figcaption><\/figure>\n\n\n\n<p>As per the screenshot, it also displays the seeks, the scans and lookups. Please note that these tables contains many other useful statistics on table.<\/p>\n\n\n\n<p>This article explains how to display the last access and update date to an a given SQL Server table. This SQL code helps for compliance and troubleshooting. <\/p>\n\n\n\n<p>Check this other article to learn how to <a href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-tables\/\">display manage SQL Server tables with T-SQL scripts<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-tutoriels-sql-et-it wp-block-embed-tutoriels-sql-et-it\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-tables\/\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to check the last date a table was updated on a SQL Server database? Check the last access and update with a simple SQL query? Thanks to the SQL Server relational database management system tables, a query allows <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\" title=\"Last time table was updated in SQL Server\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":5509,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-9034","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Last time table was updated in SQL Server - T-SQL<\/title>\n<meta name=\"description\" content=\"T-SQL query to get the last time and date a table was updated in SQL Server, it shows the last update and the number of updates.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Last time table was updated in SQL Server\" \/>\n<meta property=\"og:description\" content=\"T-SQL query to get the last time and date a table was updated in SQL Server, it shows the last update and the number of updates.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-22T04:52:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-04T12:17:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Last time table was updated in SQL Server\",\"datePublished\":\"2022-07-22T04:52:00+00:00\",\"dateModified\":\"2022-08-04T12:17:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\"},\"wordCount\":339,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\",\"name\":\"Last time table was updated in SQL Server - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg\",\"datePublished\":\"2022-07-22T04:52:00+00:00\",\"dateModified\":\"2022-08-04T12:17:38+00:00\",\"description\":\"T-SQL query to get the last time and date a table was updated in SQL Server, it shows the last update and the number of updates.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg\",\"width\":1920,\"height\":1080,\"caption\":\"days of calendar\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Last time table was updated in SQL Server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Last time table was updated in SQL Server - T-SQL","description":"T-SQL query to get the last time and date a table was updated in SQL Server, it shows the last update and the number of updates.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"Last time table was updated in SQL Server","og_description":"T-SQL query to get the last time and date a table was updated in SQL Server, it shows the last update and the number of updates.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-07-22T04:52:00+00:00","article_modified_time":"2022-08-04T12:17:38+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Last time table was updated in SQL Server","datePublished":"2022-07-22T04:52:00+00:00","dateModified":"2022-08-04T12:17:38+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/"},"wordCount":339,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/","url":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/","name":"Last time table was updated in SQL Server - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg","datePublished":"2022-07-22T04:52:00+00:00","dateModified":"2022-08-04T12:17:38+00:00","description":"T-SQL query to get the last time and date a table was updated in SQL Server, it shows the last update and the number of updates.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/02\/calendar-660670_1920.jpg","width":1920,"height":1080,"caption":"days of calendar"},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/last-time-table-was-updated-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Last time table was updated in SQL Server"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=9034"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9034\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/5509"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=9034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=9034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=9034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}