{"id":826,"date":"2009-06-16T18:27:00","date_gmt":"2009-06-16T18:27:00","guid":{"rendered":"\/blogs\/paul\/post\/Finding-out-who-dropped-a-table-using-the-transaction-log.aspx"},"modified":"2014-02-11T06:24:10","modified_gmt":"2014-02-11T14:24:10","slug":"finding-out-who-dropped-a-table-using-the-transaction-log","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/","title":{"rendered":"Finding out who dropped a table using the transaction log"},"content":{"rendered":"<p><span style=\"font-family: verdana, geneva; font-size: small;\">I came across a <a href=\"http:\/\/serverfault.com\/questions\/26902\/is-there-anyway-to-determine-who-dropped-a-table\">question on ServerFault<\/a> this afternoon that inflamed my desire to be ultra-geeky (it was really already inflamed after teaching backup and restore internals all afternoon). Basically the question boiled down to how to find out who dropped a table if there&#8217;s no other way except the transaction log (e.g. no tracing is available, even the default trace). So I hacked around and figured out at least how to find out *when* a particular table was dropped plus who dropped it.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">Everything hinges on using undocumented commands to look into the transaction log. I&#8217;ve played with this before on the blog: <span style=\"font-family: 'courier new', courier;\">fn_dblog<\/span>.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">First off I created a script to create a database, populate a table and then drop it.<\/span><\/p>\n<blockquote><p><span style=\"font-family: 'courier new', courier; font-size: small;\">USE [master];<br \/>\nGO<br \/>\nCREATE DATABASE [FnDbLogTest];<br \/>\nGO<br \/>\nUSE [FnDbLogTest];<br \/>\nGO<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: small;\">CREATE TABLE [TestTable] (<br \/>\n[c1] INT IDENTITY,<br \/>\n[c2] CHAR (100) DEFAULT &#8216;a&#8217;);<br \/>\nGO<br \/>\nCREATE CLUSTERED INDEX [TT_CL] ON [TestTable] ([c1]);<br \/>\nGO<br \/>\nINSERT INTO [TestTable] DEFAULT VALUES;<br \/>\nGO<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: small;\">SELECT OBJECT_ID (N&#8217;TestTable&#8217;);<br \/>\nGO<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: small;\">DROP TABLE [TestTable];<br \/>\nGO<\/span><\/p><\/blockquote>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">First we need to find the transactions that drop tables in the log:<\/span><\/p>\n<blockquote><p><span style=\"font-family: 'courier new', courier; font-size: small;\">SELECT [Transaction Id], [Begin Time], SUSER_SNAME ([Transaction SID]) AS [User]<br \/>\nFROM fn_dblog (NULL, NULL)<br \/>\nWHERE [Transaction Name] = N&#8217;DROPOBJ&#8217;;<br \/>\nGO<\/span><\/p><\/blockquote>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">The <span style=\"font-family: 'courier new', courier;\">(NULL, NULL)<\/span> is the starting LSN and ending LSN to process &#8211; NULL means\u00a0process everything\u00a0available.\u00a0<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">Results are:<\/span><\/p>\n<blockquote><p><span style=\"font-family: 'courier new', courier; font-size: small;\">Transaction Id Begin Time\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 User<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n0000:000000e0\u00a0 2009\/06\/16 18:23:03:320\u00a0APPLECROSS\\Paul<\/span><\/p><\/blockquote>\n<p><span style=\"font-family: verdana, geneva; font-size: small; line-height: 1.5em;\">Now, this only shows us that a table was dropped, not which table it was. There&#8217;s no way to get the name of the table that was dropped, only the object ID &#8211; so you&#8217;ll need to have some other way to determine what the table ID is if there are multiple table drops and only one of them is malignant.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\"><span style=\"line-height: 1.5em;\">This code will give you the object ID of the dropped table:<\/span><\/span><\/p>\n<blockquote><p><span style=\"font-family: 'courier new', courier; font-size: small;\">SELECT TOP (1) [Lock Information] FROM fn_dblog (NULL, NULL)<br \/>\nWHERE [Transaction Id] = &#8216;0000:000000e0&#8217;<br \/>\nAND [Lock Information] LIKE &#8216;%SCH_M OBJECT%&#8217;;<br \/>\nGO<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\"><span style=\"font-family: 'courier new', courier;\">Lock Information<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nHoBt 0:ACQUIRE_LOCK_SCH_M OBJECT: 25:245575913:0<br \/>\n<\/span><\/span><\/p><\/blockquote>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">The 25:245575913\u00a0is the database ID and object ID of the table that was dropped, and you can look up the object ID in an earlier backup of the database.<\/span><\/p>\n<p><span style=\"font-size: small;\">Now you can go find whoever it was and take whatever action you deem appropriate :-)<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">Hope this helps!<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva; font-size: small;\">PS If you find the you don&#8217;t get enough info from <span style=\"font-family: 'courier new', courier;\">fn_dblog<\/span>, try turning on trace flag 2537. It allows the function to look at *all* possible log, not just the active log.<br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I came across a question on ServerFault this afternoon that inflamed my desire to be ultra-geeky (it was really already inflamed after teaching backup and restore internals all afternoon). Basically the question boiled down to how to find out who dropped a table if there&#8217;s no other way except the transaction log (e.g. no tracing [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,98,100],"tags":[],"class_list":["post-826","post","type-post","status-publish","format-standard","hentry","category-example-scripts","category-transaction-log","category-undocumented-commands"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Finding out who dropped a table using the transaction log - Paul S. Randal<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Finding out who dropped a table using the transaction log - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"I came across a question on ServerFault this afternoon that inflamed my desire to be ultra-geeky (it was really already inflamed after teaching backup and restore internals all afternoon). Basically the question boiled down to how to find out who dropped a table if there&#8217;s no other way except the transaction log (e.g. no tracing [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2009-06-16T18:27:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-02-11T14:24:10+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/\",\"name\":\"Finding out who dropped a table using the transaction log - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2009-06-16T18:27:00+00:00\",\"dateModified\":\"2014-02-11T14:24:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Finding out who dropped a table using the transaction log\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Finding out who dropped a table using the transaction log - Paul S. Randal","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:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/","og_locale":"en_US","og_type":"article","og_title":"Finding out who dropped a table using the transaction log - Paul S. Randal","og_description":"I came across a question on ServerFault this afternoon that inflamed my desire to be ultra-geeky (it was really already inflamed after teaching backup and restore internals all afternoon). Basically the question boiled down to how to find out who dropped a table if there&#8217;s no other way except the transaction log (e.g. no tracing [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/","og_site_name":"Paul S. Randal","article_published_time":"2009-06-16T18:27:00+00:00","article_modified_time":"2014-02-11T14:24:10+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/","name":"Finding out who dropped a table using the transaction log - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2009-06-16T18:27:00+00:00","dateModified":"2014-02-11T14:24:10+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/finding-out-who-dropped-a-table-using-the-transaction-log\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Finding out who dropped a table using the transaction log"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=826"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/826\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}