<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>T-SQL on Andy M Mallon - AM²</title><link>https://am2.co/tag/t-sql/</link><description>Recent content in T-SQL on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 13 Feb 2024 12:41:20 -0500</lastBuildDate><atom:link href="https://am2.co/tag/t-sql/index.xml" rel="self" type="application/rss+xml"/><item><title>T-SQL Tuesday: The last ticket I closed</title><link>https://am2.co/2024/02/13/the-last-ticket-i-closed/</link><pubDate>Tue, 13 Feb 2024 12:41:20 -0500</pubDate><guid>https://am2.co/2024/02/13/the-last-ticket-i-closed/</guid><description>&lt;p&gt;&lt;a href="https://www.brentozar.com/archive/2024/02/tsql2sday-invitation-describe-the-most-recent-issue-you-closed/"&gt;&lt;img src="https://am2.co/wp-content/uploads/TSQLTuesday1.jpg" alt="T-SQL Tuesday logo" width="300" height="300" class="alignright size-full wp-image-395" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;blockquote&gt;For &lt;a href="https://www.brentozar.com/archive/2024/02/tsql2sday-invitation-describe-the-most-recent-issue-you-closed/"&gt;this month's T-SQL Tuesday&lt;/a&gt;, Brent Ozar (&lt;a href="http://www.brentozar.com/archive/author/brento/" rel="noopener" target="_blank"&gt;blog&lt;/a&gt;|&lt;a href="https://instagram.com/BrentO" rel="noopener" target="_blank"&gt;Instagram&lt;/a&gt;) asks us to describe the most recent ticket we closed.&lt;/blockquote&gt;&#10;&lt;h2 id="we-had-a-pretty-significant-wait-spike"&gt;&amp;ldquo;We had a pretty significant wait spike&amp;hellip;&amp;rdquo;&lt;/h2&gt;&#10;&lt;p&gt;The literal last ticket I closed was &amp;ldquo;please run this script in production&amp;hellip;&amp;rdquo;, and I don&amp;rsquo;t think it would be a very interesting blog post to talk about how I copy &amp;amp; pasted a query into SSMS, so let&amp;rsquo;s talk about &lt;em&gt;a recent&lt;/em&gt; ticket instead, from the last couple of weeks.&lt;/p&gt;</description></item><item><title>Using OPENJSON, can't get results to GROUP BY</title><link>https://am2.co/2022/12/24/using-openjson-cant-get-results-to-group-by/</link><pubDate>Sat, 24 Dec 2022 18:35:57 -0500</pubDate><guid>https://am2.co/2022/12/24/using-openjson-cant-get-results-to-group-by/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/306522/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I'm passing a JSON string to a stored procedure in order to insert warehouse inventory.&lt;/p&gt;&#10;&lt;p&gt;Sometimes, there will be multiple line items with the same product, going to the same shelf, on the same pallet (LPN), with the same date. I would like to aggregate those into one line in the table.&lt;/p&gt;</description></item><item><title>How do I prevent a trigger from firing for one process?</title><link>https://am2.co/2022/03/08/how-do-i-prevent-a-trigger-from-firing-for-one-process/</link><pubDate>Tue, 08 Mar 2022 09:00:16 -0500</pubDate><guid>https://am2.co/2022/03/08/how-do-i-prevent-a-trigger-from-firing-for-one-process/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=RLG-jkwuwh8" rel="noopener" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/julius-drost-C8wlYF8ubBo-unsplash-769x1024.jpg" alt="playing cards on fire" width="384" height="512" class="alignright size-large wp-image-11594" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;I recently saw a question on DBA Stack Exchange (it has since been deleted by the author), who had a &amp;ldquo;special process&amp;rdquo; that ran regularly, and as part of that process, they disabled the trigger, did some stuff, and re-enabled it. During that process, the step that disables the trigger would deadlock, and cause problems. So the asker was wondering how to catch &amp;amp; handle the deadlock during the &lt;code&gt;DISABLE TRIGGER&lt;/code&gt; step.&lt;/p&gt;</description></item><item><title>Querying SERVERPROPERTY() and DATABASEPROPERTYEX() from a view (without knowing magic)</title><link>https://am2.co/2021/12/17/querying-serverproperty-and-databasepropertyex-from-a-view/</link><pubDate>Fri, 17 Dec 2021 11:11:50 -0500</pubDate><guid>https://am2.co/2021/12/17/querying-serverproperty-and-databasepropertyex-from-a-view/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:378px"&gt;&lt;a href="https://www.youtube.com/watch?v=nF4-OOlbvl8" rel="noopener" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/ElphieWitch_Tall-504x1024.jpg" alt="Puppy in a witch costume" width="378" height="768" class="size-large wp-image-10541" /&gt;&lt;/a&gt; Elphaba the pup is growing up!&lt;/figure&gt;&#10;I'm not going to beat around the bush. I hate the `SERVERPROPERTY()` and `DATABASEPROPERTYEX()` system functions. &#10;&lt;h2 id="loathing"&gt;Loathing&lt;/h2&gt;&#10;&lt;p&gt;The thing I hate the most about these two functions is that you need to know the right magic spells to make them work. Let&amp;rsquo;s look at &lt;code&gt;SERVERPROPERTY()&lt;/code&gt; first. The syntax for the function is &lt;code&gt;SERVERPROPERTY( &amp;lsquo;propertyname&amp;rsquo; )&lt;/code&gt;, which is easy enough syntax, but the list of values for &lt;code&gt;propertyname&lt;/code&gt; isn&amp;rsquo;t discoverable from SQL Server metadata, DMVs, or even IntelliSense. Instead, I need to check &lt;a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver15" rel="noopener" target="_blank"&gt;the docs&lt;/a&gt; for the list of allowable values. These property names are essentially magic words, and I need to check my &lt;a href="https://amzn.to/3H6p0Ph" rel="noopener" target="_blank"&gt;spell book&lt;/a&gt; to make sure I get it right.&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #143: My favorite short scripts</title><link>https://am2.co/2021/10/12/t-sql-tuesday-143-my-favorite-short-scripts/</link><pubDate>Tue, 12 Oct 2021 10:00:22 -0400</pubDate><guid>https://am2.co/2021/10/12/t-sql-tuesday-143-my-favorite-short-scripts/</guid><description>&lt;p&gt;&lt;a href="https://johnmccormack.it/2021/10/t-sql-tuesday-143-short-code-examples/"&gt;&lt;img src="https://am2.co/wp-content/uploads/TSQLTuesday1.jpg" alt="T-SQL Tuesday logo" width="300" height="300" class="alignright size-full wp-image-395" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;blockquote&gt;For &lt;a href="https://johnmccormack.it/2021/10/t-sql-tuesday-143-short-code-examples/"&gt;this month's T-SQL Tuesday&lt;/a&gt;, John McCormack (&lt;a href="https://johnmccormack.it/" rel="noopener" target="_blank"&gt;blog&lt;/a&gt;|&lt;a href="https://twitter.com/actualjohn" rel="noopener" target="_blank"&gt;twitter&lt;/a&gt;) asks us: “What are your go-to short, handy scripts”? I've got so many handy dandy scripts, it was hard to choose.&lt;/blockquote&gt;&#10;&lt;h2 id="where-to-start"&gt;Where to start?&lt;/h2&gt;&#10;&lt;p&gt;I have so many go-to scripts that are short, amazing, and I use all the time. I&amp;rsquo;ve been using SQL Server since the turn of the century, and over the last two decades, I&amp;rsquo;ve found and written a lot of helpful things. And I have a terrible memory, so even if it&amp;rsquo;s just a few lines, I often keep it bookmarked or saved for when I need it. As an aside&amp;ndash;remember that having a folder of utility scripts isn&amp;rsquo;t a sign of weakness or incompetence. If anything, it&amp;rsquo;s the opposite&amp;ndash;those utility scripts are basically all battle scars for the database battles you&amp;rsquo;ve fought over your career. As we become senior, we just fine-tune our collection. With seniority, you don&amp;rsquo;t stop having that collection of scripts&amp;ndash;you just get better at curating them, at making them generic &amp;amp; reusable.&lt;/p&gt;</description></item><item><title>What time is it in Oz?</title><link>https://am2.co/2021/10/05/what-time-is-it-in-oz/</link><pubDate>Tue, 05 Oct 2021 15:54:03 -0400</pubDate><guid>https://am2.co/2021/10/05/what-time-is-it-in-oz/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:300px"&gt;&lt;a href="https://www.youtube.com/watch?v=R4rpG-dipYA"&gt;&lt;img src="https://am2.co/wp-content/uploads/ElphiePup2-300x300.jpg" alt="Black dog wearing bandana standing on grass" width="300" height="300" class="size-medium wp-image-9493" /&gt;&lt;/a&gt; This is our puppy &lt;a href="https://en.wikipedia.org/wiki/Elphaba" rel="noopener" target="_blank"&gt;Elphaba&lt;/a&gt;. She's from &lt;a href="https://en.wikipedia.org/wiki/Name_of_Australia#Oz" rel="noopener" target="_blank"&gt;Oz&lt;/a&gt;...No, the &lt;a href="https://en.wikipedia.org/wiki/Land_of_Oz" rel="noopener" target="_blank"&gt;other Oz&lt;/a&gt;. She's &lt;a href="https://www.youtube.com/watch?v=R4rpG-dipYA" rel="noopener" target="_blank"&gt;popular&lt;/a&gt;.&lt;/figure&gt;&#10;&lt;p&gt;There was a &lt;a href="https://dba.stackexchange.com/q/300618/52344" rel="noopener" target="_blank"&gt;recent post on Database Administrators&lt;/a&gt;, where there was some confusion over Daylight Saving Time(DST) in Australian timezones. Let&amp;rsquo;s be honest though&amp;ndash;timezones are confusing, especially when DST comes into play. Arizona Time doesn&amp;rsquo;t observe Daylight Saving Time, so sometimes it&amp;rsquo;s the same as Mountain Time, and sometimes it&amp;rsquo;s Pacific Time.&lt;/p&gt;</description></item><item><title>Stop using sp_hexadecimal &amp; sp_help_revlogin</title><link>https://am2.co/2021/07/06/dba-serverlogins/</link><pubDate>Tue, 06 Jul 2021 09:00:52 -0400</pubDate><guid>https://am2.co/2021/07/06/dba-serverlogins/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:400px"&gt;&lt;a href="https://vm.tiktok.com/ZMduBrPEB/" rel="noopener" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/GreenCaterpillar.png" alt="" width="400" height="400" class="size-medium wp-image-8240" /&gt;&lt;/a&gt; Caterpillars transform into beautiful butterflies to realize their full self, much in the same way &lt;code&gt;CONVERT()&lt;/code&gt; changes binary into beautiful hexadecimal strings.&lt;/figure&gt;&#10;&lt;p&gt;Since &lt;a href="https://twitter.com/AMtwo/status/1384126645053771780" rel="noopener" target="_blank"&gt;I started at Stack Overflow&lt;/a&gt;, I&amp;rsquo;ve had the chance to see some of the interesting challenges with running our databases at our scale.&lt;/p&gt;</description></item><item><title>Find the SQL Server service account with sys.dm_server_services</title><link>https://am2.co/2020/05/12/find-the-sql-server-service-account-with-sys-dm_server_services/</link><pubDate>Tue, 12 May 2020 09:00:56 -0400</pubDate><guid>https://am2.co/2020/05/12/find-the-sql-server-service-account-with-sys-dm_server_services/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:384px"&gt;&lt;a href="https://www.youtube.com/watch?v=oxYiYApx_F8" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/HappyCallie-768x1024.jpg" alt="" width="384" height="512" class="alignright size-large wp-image-3012" /&gt;&lt;/a&gt; This is &lt;a href="https://twitter.com/CalliePie" rel="noopener noreferrer" target="_blank"&gt;Callie&lt;/a&gt;. She has nothing to do with DMVs, but isn't she cute?!&lt;/figure&gt;&#10;&lt;p&gt;SQL Server 2005 introduced &lt;a href="https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/system-dynamic-management-views" rel="noopener noreferrer" target="_blank"&gt;Dynamic Management Views(DMVs)&lt;/a&gt;. Technically, there are both views &amp;amp; functions&amp;ndash;DMVs &amp;amp; DMFs, but colloquially they&amp;rsquo;re often simply referred to as just &amp;ldquo;DMVs&amp;rdquo;. DMVs simply return information about the state of the server or database and can be used for monitoring and troubleshooting of server/database health &amp;amp; performance.&lt;/p&gt;</description></item><item><title>Making non-SARGable queries seek, without changing the query</title><link>https://am2.co/2020/05/06/making-non-sargable-queries-seek-without-changing-the-query/</link><pubDate>Wed, 06 May 2020 08:36:27 -0400</pubDate><guid>https://am2.co/2020/05/06/making-non-sargable-queries-seek-without-changing-the-query/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=tALDcVmWE9w" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/sarg-pubs-featured-1024x577.png" alt="" width="512" height="289" class="alignright size-large wp-image-3253" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;We&amp;rsquo;ve all been there. You&amp;rsquo;ve got a query where the &lt;code&gt;JOIN&lt;/code&gt; or &lt;code&gt;WHERE&lt;/code&gt; predicate is not &lt;a href="https://dba.stackexchange.com/a/217983/52344" rel="noopener noreferrer" target="_blank"&gt;SARGable&lt;/a&gt;. You&amp;rsquo;ve read about how &lt;a href="https://www.erikdarlingdata.com/2019/04/slightly-less-not-sargable/" rel="noopener noreferrer" target="_blank"&gt;this can be a problem&lt;/a&gt;, and &lt;a href="https://www.erikdarlingdata.com/2019/04/slightly-less-not-sargable/" rel="noopener noreferrer" target="_blank"&gt;how bad it is for performance&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Alas, you cannot change the query. Sometimes this reason is political, sometimes it&amp;rsquo;s because you&amp;rsquo;ve got a third-party app and simply don&amp;rsquo;t have access to the code. But you do have access to the database&amp;hellip;&lt;/p&gt;</description></item><item><title>Fixing tempdb: Growing, shrinking, and removing data files</title><link>https://am2.co/2020/04/21/fixing-tempdb/</link><pubDate>Tue, 21 Apr 2020 09:00:37 -0400</pubDate><guid>https://am2.co/2020/04/21/fixing-tempdb/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:500px"&gt;&lt;a href="https://www.youtube.com/watch?v=RaCodgL9cvk"&gt;&lt;img src="https://am2.co/wp-content/uploads/drop-files-here-extra.jpg" alt="" width="500" height="224" class="size-full wp-image-3070" /&gt;&lt;/a&gt; Dropping tempdb files like they're hot&lt;/figure&gt;&#10;&lt;p&gt;I recently came across a server where &lt;code&gt;tempdb&lt;/code&gt; was breaking all the rules.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&#9;&lt;li&gt;Data files were all different sizes. I want all data files to be the same size so that proportional fill uses them evenly.&lt;/li&gt;&#10;&#9;&lt;li&gt;There were 10 &lt;code&gt;tempdb&lt;/code&gt; files, with 8 files on a dedicated disk, and 2 on a slower disk shared with other data files. And free space was sky high, so the extra files aren't needed anymore! (They were probably added to fix a short-term emergency, and never cleaned up.)&lt;/li&gt;&#10;&#9;&lt;li&gt;The log file was tiny, and didn't have room to grow. For a 500GB tempdb, the log file was only 4GB!&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="three-fixes"&gt;Three fixes&lt;/h2&gt;&#10;&lt;p&gt;There are three problems I&amp;rsquo;ve got to fix. I need to (1) remove those two extra files, (2) grow the &lt;code&gt;tempdb&lt;/code&gt; log file, and (3) even out the size of the data files (and shrink them a little to make room for the larger log file. We&amp;rsquo;re going to tackle these in the reverse order than I listed them&amp;ndash;partially out of necessity, and partially because it&amp;rsquo;s going to be easier.&lt;/p&gt;</description></item><item><title>When STRING_SPLIT() falls short</title><link>https://am2.co/2020/03/20/when-string_split-falls-short/</link><pubDate>Fri, 20 Mar 2020 10:00:54 -0400</pubDate><guid>https://am2.co/2020/03/20/when-string_split-falls-short/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:400px"&gt;&lt;a href="https://www.youtube.com/watch?v=vY1TQ9pb2J4"&gt;&lt;img src="https://am2.co/wp-content/uploads/STONE_SPLIT.jpg" alt="" width="400" height="300" class="size-medium wp-image-2828" /&gt;&lt;/a&gt; &lt;a href="https://twitter.com/AaronBertrand" rel="noopener noreferrer" target="_blank"&gt;Aaron&lt;/a&gt; attempting a STONE_SPLIT at a recent curling competition.&lt;/figure&gt;&#10;This morning, my friend Aaron Bertrand (&lt;a href="http://sqlblog.org" rel="noopener noreferrer" target="_blank"&gt;blog&lt;/a&gt;|&lt;a href="https://twitter.com/AaronBertrand" rel="noopener noreferrer" target="_blank"&gt;twitter&lt;/a&gt;) posted &lt;a href="https://sqlperformance.com/2020/03/t-sql-queries/please-help-string-split-improvements" rel="noopener noreferrer" target="_blank"&gt;a plea for help with &lt;code&gt;STRING_SPLIT()&lt;/code&gt; improvements&lt;/a&gt;. I'm very much in Aaron's corner on this, having &lt;a href="https://am2.co/2015/04/21/converting-delimited-values-to-a-table-efficiently/" rel="noopener noreferrer" target="_blank"&gt;written about the olden days myself&lt;/a&gt;. &#10;&lt;h3&gt;Why &lt;code&gt;STRING_SPLIT()&lt;/code&gt; is supposed to be awesome&lt;/h3&gt;&#10;CLR was fast, but inaccessible to many DBAs. XML was almost as good, but ugh, XML. And multi-statement table valued functions are evil but prevalent. &#10;&lt;p&gt;&lt;code&gt;STRING_SPLIT()&lt;/code&gt; promised to be both super fast, and lift the code maintenance problem for DBAs who don&amp;rsquo;t know .NET and struggle with the crazy XML syntax.&lt;/p&gt;</description></item><item><title>Blocking with OBJECT_NAME()</title><link>https://am2.co/2019/12/24/blocking-with-object_name/</link><pubDate>Tue, 24 Dec 2019 10:38:36 -0500</pubDate><guid>https://am2.co/2019/12/24/blocking-with-object_name/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:512px"&gt;&lt;a href="https://www.youtube.com/watch?v=bphPp8k9aZo"&gt;&lt;img src="https://am2.co/wp-content/uploads/berkay-gumustekin-ngqyo2AYYnE-unsplash-1024x683.jpg" alt="" width="512" height="341" class="size-large wp-image-2392" /&gt;&lt;/a&gt; Doggos increase blog readership by 140%. 14/10. They are good doggos.&lt;/figure&gt;&#10;&lt;p&gt;As a DBA, you probably use the &lt;code&gt;OBJECT_NAME()&lt;/code&gt; function quite a bit. I know I do. If you aren&amp;rsquo;t familiar with it, you can read &lt;a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/object-name-transact-sql?view=sql-server-ver15" rel="noopener noreferrer" target="_blank"&gt;the documentation&lt;/a&gt; if you want, but it&amp;rsquo;s a pretty straightforward function that converts object IDs into object names.&lt;/p&gt;</description></item><item><title>Testing as another user...without their password</title><link>https://am2.co/2019/12/18/testing-as-another-user-without-their-password/</link><pubDate>Wed, 18 Dec 2019 11:50:35 -0500</pubDate><guid>https://am2.co/2019/12/18/testing-as-another-user-without-their-password/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:512px"&gt;&lt;a href="https://www.youtube.com/watch?v=6AXd5tcyneE"&gt;&lt;img src="https://am2.co/wp-content/uploads/greg-ortega-1LCzr14Ah5U-unsplash-1024x684.jpg" alt="" width="512" height="342" class="size-large wp-image-2381" /&gt;&lt;/a&gt; This guy doesn't have Elvis's password and is still able to impersonate him.&lt;/figure&gt;&#10;As a DBA or SQL Developer, you've surely encountered a scenario where something worked for you, but not for another user. DBAs usually are part of the sysadmin role, or have a collection of powerful permissions. If I run code as myself, I will *never* have permissions problems because my account is sysadmin. If I want to ensure permissions are correct, I need to run the code as the less-privileged account. &#10;&lt;h2 id="can-you-try-now"&gt;Can you try now?&lt;/h2&gt;&#10;&lt;h3 id="can-you-try-now-1"&gt;Can you try now?&lt;/h3&gt;&#10;&lt;h4 id="can-you-try-now-2"&gt;Can you try now?&lt;/h4&gt;&#10;&lt;h5 id="can-you-try-now-3"&gt;Can you try now?&lt;/h5&gt;&#10;&lt;p&gt;I honestly don&amp;rsquo;t think there is a more frustrating experience than getting into the feedback loop of making a permission change, and asking the user if it works, and when it doesn&amp;rsquo;t work, you try another change, and ask them to try again, and when it doesn&amp;rsquo;t work, you try another change, and ask them to try again, and when it doesn&amp;rsquo;t work, you try another change, and ask them to try again, and when it doesn&amp;rsquo;t work, you try another change, and ask them to try again&amp;hellip;&lt;/p&gt;</description></item><item><title>Changing a column from int to bigint, without downtime</title><link>https://am2.co/2019/12/11/changing-a-column-from-int-to-bigint-without-downtime/</link><pubDate>Wed, 11 Dec 2019 08:00:41 -0500</pubDate><guid>https://am2.co/2019/12/11/changing-a-column-from-int-to-bigint-without-downtime/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=YHKGUu2gaOg" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/AlterOnline2.png" alt="" width="481" height="396" class="alignright size-full wp-image-2359" /&gt;&lt;/a&gt;&#10;Changing a column from &lt;code&gt;int&lt;/code&gt; to &lt;code&gt;bigint&lt;/code&gt; has gotten a lot easier since I started working on SQL Server back at the turn of the century. SQL Server 2016 introduced the ability to do &lt;code&gt;ALTER TABLE...ALTER COLUMN&lt;/code&gt; as an online operation using the &lt;code&gt;WITH (ONLINE=ON)&lt;/code&gt; syntax in Enterprise Edition. This wonderful syntax now allows you to alter a column from &lt;code&gt;int&lt;/code&gt; to &lt;code&gt;bigint&lt;/code&gt; without causing major blocking. The &lt;code&gt;int&lt;/code&gt; to &lt;code&gt;bigint&lt;/code&gt; conversion is one of the most popular data type changes I see&amp;ndash;A developer inevitably creates the table thinking they will never have more than 2 billion rows&amp;hellip; then some years or months later 2 billion becomes a reality.&lt;/p&gt;</description></item><item><title>How to create date buckets in T-SQL</title><link>https://am2.co/2019/10/28/how-to-create-date-buckets-in-t-sql/</link><pubDate>Mon, 28 Oct 2019 10:00:47 -0400</pubDate><guid>https://am2.co/2019/10/28/how-to-create-date-buckets-in-t-sql/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=zYY6Q4nRTS4" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/StockSnap_MHIAORM8Q6.jpg" alt="" width="512" height="341" class="alignright size-full wp-image-2263" /&gt;&lt;/a&gt;&#10;I was fiddling around with some data, looking at making a quick aging report. I probably should have reached for &lt;a href="https://powerbi.microsoft.com/en-us/desktop/" rel="noopener noreferrer" target="_blank"&gt;Power BI Desktop&lt;/a&gt;, but sometimes I can be stubborn, and I wanted to get my T-SQL to work&amp;ndash;if nothing else to figure out how to make it work.&lt;/p&gt;</description></item><item><title>Why does ALTER let me DROP?</title><link>https://am2.co/2019/08/28/why-does-alter-let-me-drop/</link><pubDate>Wed, 28 Aug 2019 09:00:19 -0400</pubDate><guid>https://am2.co/2019/08/28/why-does-alter-let-me-drop/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=m3f0aW_-6gc" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/chuttersnap-cGXdjyP6-NU-unsplash.jpg" alt="" width="400" height="267" class="alignright size-medium wp-image-2102" /&gt;&lt;/a&gt;&#10;I was recently chatting with a coworker, discussing why there is no discrete &lt;code&gt;DROP&lt;/code&gt; permission for tables, procedures, etc. The conversation actually came from a &lt;a href="https://sqlcommunity.slack.com/messages/C1MS1RA4B" rel="noopener noreferrer" target="_blank"&gt;#SQLHelp&lt;/a&gt; question on &lt;a href="http://sqlslack.com" rel="noopener noreferrer" target="_blank"&gt;SQL Slack&lt;/a&gt; that was asked along the lines of &amp;ldquo;What if I want to let a user &lt;code&gt;CREATE&lt;/code&gt; and &lt;code&gt;ALTER&lt;/code&gt; objects, but not &lt;code&gt;DROP&lt;/code&gt; them?&amp;rdquo;&lt;/p&gt;</description></item><item><title>Year 4: May 2017 - May 2018</title><link>https://am2.co/2019/05/21/year-4-2017-2018/</link><pubDate>Tue, 21 May 2019 08:30:21 -0400</pubDate><guid>https://am2.co/2019/05/21/year-4-2017-2018/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=RUaEDuxAVhY" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/david-pisnoy-562428-unsplash-300x225.jpg" alt="" width="300" height="225" class="alignright size-medium wp-image-1876" /&gt;&lt;/a&gt;&#10;In &lt;a href="https://am2.co/2019/05/20/year-3-2016-2017/" rel="noopener noreferrer" target="_blank"&gt;Year Three&lt;/a&gt;, I had a pretty big year. I kind of felt like I had peaked. I had received the &lt;a href="https://blogs.sentryone.com/aaronbertrand/2016-community-influencer/" rel="noopener noreferrer" target="_blank"&gt;Community Influencer of the Year Award&lt;/a&gt; and &lt;a href="2017/03/congratulations-2017-microsoft-mvp/" rel="noopener noreferrer" target="_blank"&gt;Microsoft MVP Award&lt;/a&gt;. Where do you go from there? Mostly, I just wanted to keep up what I was doing, and keep sharing what I was doing.&lt;/p&gt;</description></item><item><title>Code to purge data based on creation date</title><link>https://am2.co/2019/04/04/code-to-purge-data-on-creation-date/</link><pubDate>Thu, 04 Apr 2019 08:30:16 -0400</pubDate><guid>https://am2.co/2019/04/04/code-to-purge-data-on-creation-date/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:678px"&gt;&lt;a href="https://www.youtube.com/watch?v=nHlJODYBLKs"&gt;&lt;img src="https://am2.co/wp-content/uploads/MarieKondoData-678x381.png" alt="" width="678" height="381" class="size-mh-magazine-lite-content wp-image-1743" /&gt;&lt;/a&gt; Only one thing can spark more joy than cleaning up old data. Doggos. &lt;/figure&gt;&#10;Yesterday, &lt;a href="https://am2.co/2019/04/03/purging-data-with-batched-deletes/"&gt;I talked about batching deletes&lt;/a&gt;, and the day before I talked about &lt;a href="https://am2.co/2019/04/02/the-thrill-of-purging-old-data/"&gt;how much I like to delete data&lt;/a&gt;, and why it's necessary to do it, despite being a data packrat.&#10;&lt;p&gt;Today, let&amp;rsquo;s look at just one scenario, and how I like to handle it. In my experience, this is one of the most common purge requirements (and probably the easiest), so first, let&amp;rsquo;s look at the business requirements.&lt;/p&gt;</description></item><item><title>Purging data with batched deletes</title><link>https://am2.co/2019/04/03/purging-data-with-batched-deletes/</link><pubDate>Wed, 03 Apr 2019 08:30:13 -0400</pubDate><guid>https://am2.co/2019/04/03/purging-data-with-batched-deletes/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:678px"&gt;&lt;a href="https://www.youtube.com/watch?v=4VO1nYGHw0c" target="_blank" rel="noopener noreferrer"&gt;&lt;img src="https://am2.co/wp-content/uploads/pawel-czerwinski-759725-unsplash-678x381.jpg" alt="" width="678" height="381" class="size-mh-magazine-lite-content wp-image-1739" /&gt;&lt;/a&gt; This person understands that batching deletes can be helpful.&lt;/figure&gt;&#10;Yesterday, I wrote about &lt;a href="https://am2.co/2019/04/02/the-thrill-of-purging-old-data/"&gt;the importance of planning your data purges&lt;/a&gt;. Today, let's look at the simplest requirement for purging data: Keep data for X days after it's created. There are &lt;strong&gt;tons&lt;/strong&gt; of cases where this is the rule. Log data, telemetry data, even transactional data is often retained based on X days since it is created.&#10;&lt;p&gt;Given how common this scenario is, let&amp;rsquo;s talk in a bit more detail about I like to go about deleting it. Deleting data is easy, right? &lt;code&gt; DELETE t FROM dbo.Transactions AS t WHERE CreateDate &amp;lt;= DATEADD(dd,-90,GETDATE());&lt;/code&gt;&lt;/p&gt;</description></item><item><title>The thrill of purging old data</title><link>https://am2.co/2019/04/02/the-thrill-of-purging-old-data/</link><pubDate>Tue, 02 Apr 2019 09:00:54 -0400</pubDate><guid>https://am2.co/2019/04/02/the-thrill-of-purging-old-data/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:678px"&gt;&lt;a href="https://www.youtube.com/watch?v=wdGARtyNaQQ" target="_blank" rel="noopener noreferrer"&gt;&lt;img src="https://am2.co/wp-content/uploads/priscilla-du-preez-101759-unsplash-678x381.jpg" alt="" width="678" height="381" class="size-mh-magazine-lite-content wp-image-1737" /&gt;&lt;/a&gt; I get a thrill from roller coasters, but for some people it just makes them purge their lunch.&lt;/figure&gt;&#10;&lt;p&gt;DBAs &amp;amp; Data professionals tend to be digital pack rats. My personal Google Drive is filled with random files that I refused to part with&amp;ndash;even though it&amp;rsquo;s of questionable value. I lament that I do not have a copy of every paper I typed in high school or college&amp;ndash;and I envy those who do. You never know when you&amp;rsquo;ll need notes from that meeting 6 years ago, or when you&amp;rsquo;ll need that funny GIF you created for an inside joke you no longer remember.&lt;/p&gt;</description></item><item><title>TSQL Tuesday #104: dbo.Check_FileSize</title><link>https://am2.co/2018/07/09/tsql-tuesday-104/</link><pubDate>Mon, 09 Jul 2018 23:18:12 -0400</pubDate><guid>https://am2.co/2018/07/09/tsql-tuesday-104/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=D04uazu547A"&gt;&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" alt="TSQL2SDAY" width="300" height="300" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;blockquote&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener noreferrer"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener noreferrer"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Bert Wagner&lt;/strong&gt; (&lt;a href="https:/bertwagner.com/" target="_blank" rel="noopener noreferrer"&gt;blog&lt;/a&gt; | &lt;a href="http://youtube.com/bertwagner" target="_blank" rel="noopener noreferrer"&gt;vlog&lt;/a&gt;| &lt;a href="https://twitter.com/bertwagner" target="_blank" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;). The topic: &lt;strong&gt;&lt;a href="https://bertwagner.com/2018/07/03/code-youd-hate-to-live-without-t-sql-tuesday-104-invitation/" target="_blank" rel="noopener noreferrer"&gt;Code You Would Hate To Live Without &lt;/a&gt;&lt;/strong&gt;&lt;/blockquote&gt;&#10;&lt;p&gt;It&amp;rsquo;s been a little bit since the last T-SQL Tuesday I joined, when I blogged about religion &amp;amp; politics (aka, &lt;a href="https://am2.co/2018/02/13/tsql-tuesday-99-tabs-vs-spaces/"&gt;Tabs vs Spaces&lt;/a&gt;). When I saw Bert&amp;rsquo;s excellent topic this month, I decided I&amp;rsquo;d try to get back on the horse again and do join the blog party again this month.&lt;/p&gt;</description></item><item><title>TSQL Tuesday #99: Tabs vs Spaces</title><link>https://am2.co/2018/02/13/tsql-tuesday-99-tabs-vs-spaces/</link><pubDate>Tue, 13 Feb 2018 07:02:30 -0500</pubDate><guid>https://am2.co/2018/02/13/tsql-tuesday-99-tabs-vs-spaces/</guid><description>&lt;p&gt;&lt;a href="https://sqlblog.org/2018/02/06/t-sql-tuesday-99"&gt;&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" alt="TSQL2SDAY" width="300" height="300" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;blockquote&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Aaron Bertrand&lt;/strong&gt; (&lt;a href="https://sqlblog.org/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt; | &lt;a href="https://twitter.com/aaronbertrand" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). The topic: &lt;strong&gt;&lt;a href="https://sqlblog.org/2018/02/06/t-sql-tuesday-99" target="_blank" rel="noopener"&gt;Dealer's Choice (Door Number 2: Bad Habits) &lt;/a&gt;&lt;/strong&gt;&lt;/blockquote&gt;&#10;&lt;p&gt;When I was a kid, &lt;a href="http://amzn.to/2GaEWjH" target="_blank" rel="noopener"&gt;Choose Your Own Adventure books&lt;/a&gt; were overwhelming because I wanted to explore every possible option&amp;ndash;some things never change. This month for T-SQL Tuesday, Aaron offers two blogging options and I&amp;rsquo;ve chosen to do both. &amp;ldquo;Door Number 1&amp;rdquo; is a challenge to write about what you do in your free time, inspired by &lt;a href="http://port1433.com/2017/12/13/keeping-sqlibirum-looking-back-on-what-mattered-most-this-year/" target="_blank" rel="noopener"&gt;Drew Furgiuele&amp;rsquo;s #sqlibirum post&lt;/a&gt;. That blog post is over &lt;a href="https://am2.co/2018/02/13/tsql-tuesday-99-sql-tourism/"&gt;here&lt;/a&gt;. This post is for the &amp;ldquo;Door Number 2&amp;rdquo; option is to talk about his Bad Habits series&amp;ndash;I&amp;rsquo;ve opted to bring up a topic Aaron hasn&amp;rsquo;t blogged about: tabs vs spaces.&lt;/p&gt;</description></item><item><title>TSQL Tuesday #99: SQL Tourism</title><link>https://am2.co/2018/02/13/tsql-tuesday-99-sql-tourism/</link><pubDate>Tue, 13 Feb 2018 07:00:45 -0500</pubDate><guid>https://am2.co/2018/02/13/tsql-tuesday-99-sql-tourism/</guid><description>&lt;p&gt;&lt;a href="https://sqlblog.org/2018/02/06/t-sql-tuesday-99"&gt;&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" alt="TSQL2SDAY" width="300" height="300" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;blockquote&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener noreferrer"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener noreferrer"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Aaron Bertrand&lt;/strong&gt; (&lt;a href="https://sqlblog.org/" target="_blank" rel="noopener noreferrer"&gt;blog&lt;/a&gt; | &lt;a href="https://twitter.com/aaronbertrand" target="_blank" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;). The topic: &lt;strong&gt;&lt;a href="https://sqlblog.org/2018/02/06/t-sql-tuesday-99" target="_blank" rel="noopener noreferrer"&gt;Dealer's Choice (Door Number 1: #sqlibrium) &lt;/a&gt;&lt;/strong&gt;&lt;/blockquote&gt;&#10;When I was a kid, &lt;a href="http://amzn.to/2GaEWjH" target="_blank" rel="noopener noreferrer"&gt;Choose Your Own Adventure books&lt;/a&gt; were overwhelming because I wanted to explore every possible option--some things never change. This month for T-SQL Tuesday, Aaron offers two blogging options and I've chosen to do both. "Door Number 1" is a challenge to write about what you do in your free time, inspired by &lt;a href="http://port1433.com/2017/12/13/keeping-sqlibirum-looking-back-on-what-mattered-most-this-year/" target="_blank" rel="noopener noreferrer"&gt;Drew Furgiuele's #sqlibirum post&lt;/a&gt;. That blog post is below. My other post is for the "Door Number 2" option is to talk about his Bad Habits series--I've opted to bring up a topic Aaron hasn't blogged about: &lt;a href="https://am2.co/2018/02/13/tsql-tuesday-99-tabs-vs-spaces/"&gt;tabs vs spaces&lt;/a&gt;.&#10;## SQL Tourism? What's that?&#10;I made it the term, but it's a very real thing. When I started travelling to speak at SQL Server events, I committed that I would make the most of it. To me, that means a lot more than just attending the event where I'm speaking. Sure, I want to learn and network at the event, but it means more than that, too. It means actually seeing the city where I'm speaking. It means enjoying the *entire* trip. It means making new friends, and connecting with old friends. Sometimes, it even means bringing my husband with me.&#10;&lt;p&gt;I work really hard. Some days I&amp;rsquo;m at my desk before 7:30, and working again after dinner until bedtime. My blog doesn&amp;rsquo;t write itself&amp;ndash;most posts are written nights &amp;amp; weekends after I&amp;rsquo;ve finished my work obligations for my paying work. That makes it really important to have some down time when I can. When Drew Furgiuele (&lt;a href="http://port1433.com/" target="_blank" rel="noopener noreferrer"&gt;blog&lt;/a&gt; | &lt;a href="http://twitter.com/pittfurg" target="_blank" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;) posted his &lt;a href="http://port1433.com/2017/12/13/keeping-sqlibirum-looking-back-on-what-mattered-most-this-year/" target="_blank" rel="noopener noreferrer"&gt;#sqlibrium post&lt;/a&gt;, it really struck me, because it&amp;rsquo;s something that a lot of us struggle with&amp;ndash;remembering to strike that balance between work and life.&lt;/p&gt;</description></item><item><title>Parsing file names from paths using T-SQL</title><link>https://am2.co/2018/01/17/parsing-file-names-paths-using-t-sql/</link><pubDate>Wed, 17 Jan 2018 07:00:40 -0500</pubDate><guid>https://am2.co/2018/01/17/parsing-file-names-paths-using-t-sql/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:400px"&gt;&lt;a href="https://www.youtube.com/watch?v=ijTEn2q-jFM"&gt;&lt;img class="wp-image-1265" src="https://am2.co/wp-content/uploads/maarten-van-den-heuvel-73123-300x200.jpg" alt="" width="400" height="267" /&gt;&lt;/a&gt; These files are way neater than the ones on my laptop.&lt;/figure&gt;&#10;&lt;p&gt;SQL Server is great at a lot of things. I spend a lot of time blogging about all the cool things that SQL Server does. But (you knew there was a &amp;ldquo;but&amp;rdquo;, didn&amp;rsquo;t you) SQL Server isn&amp;rsquo;t great at everything. Lets write about something that SQL Server is bad at.&lt;/p&gt;</description></item><item><title>Finding active transactions</title><link>https://am2.co/2018/01/02/finding-active-transactions/</link><pubDate>Tue, 02 Jan 2018 09:04:07 -0500</pubDate><guid>https://am2.co/2018/01/02/finding-active-transactions/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:400px"&gt;&lt;a href="http://amzn.to/2CDwuZP"&gt;&lt;img class="wp-image-1249" src="https://am2.co/wp-content/uploads/monika-grabkowska-452366-200x300.jpg" alt="" width="400" height="600" /&gt;&lt;/a&gt; Confessions of a carbaholic: When I start thinking about `ROLLBACK`, I start thinking about rolls.&lt;/figure&gt;&#10;&lt;p&gt;Have you ever forgot to commit a transaction? Maybe you&amp;rsquo;ve even &lt;a href="https://am2.co/2017/10/26/finding-leader-blocker/"&gt;left for lunch&lt;/a&gt; and caused a problem while you were gone. Uncommitted transactions can cause all sorts of problems&amp;ndash;not just blocking, but it can affect your Availability Groups &amp;amp; Mirroring, your TempDB version store if you&amp;rsquo;re using one of the snapshot &lt;a href="https://www.sql.kiwi/2014/07/isolation-levels/" target="_blank" rel="noopener noreferrer"&gt;isolation levels&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Finding the Leader Blocker</title><link>https://am2.co/2017/10/26/finding-leader-blocker/</link><pubDate>Thu, 26 Oct 2017 23:55:09 -0400</pubDate><guid>https://am2.co/2017/10/26/finding-leader-blocker/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:500px"&gt;&lt;a href="https://www.youtube.com/watch?v=iHzzSao6ypE"&gt;&lt;img class="wp-image-1194" src="https://am2.co/wp-content/uploads/evgeny-tchebotarev-247145-300x200.jpg" alt="" width="500" height="334" /&gt;&lt;/a&gt; Who's at the front of the line blocking all the traffic?&lt;/figure&gt;&#10;&lt;p&gt;During the course of normal processing in a database, blocking happens. Blocking is &amp;ldquo;by design&amp;rdquo; because &lt;a href="https://en.wikipedia.org/wiki/ACID" target="_blank" rel="noopener noreferrer"&gt;your database is on ACID&lt;/a&gt;. In an OLTP database, most of your transactions are short in duration, so we expect blocking to also be short in duration. If blocking occurs for a long time, this can cause problems.&lt;/p&gt;</description></item><item><title>Multi-Statement TVFs in Dynamics CRM</title><link>https://am2.co/2017/08/22/multi-statement-tvfs-in-dynamics-crm/</link><pubDate>Tue, 22 Aug 2017 13:19:18 -0400</pubDate><guid>https://am2.co/2017/08/22/multi-statement-tvfs-in-dynamics-crm/</guid><description>&lt;p&gt;If you&amp;rsquo;re familiar with supporting the database behind Microsoft Dynamics CRM, you probably know that it&amp;rsquo;s not the fastest-performing database. Honestly, that shouldn&amp;rsquo;t be a surprise&amp;ndash;it&amp;rsquo;s not designed to be a screaming-fast database. It&amp;rsquo;s designed to be a &lt;em&gt;flexible&lt;/em&gt; database. Most Customer Relationship Management (CRM) systems are designed to be flexible so that they can meet the needs of many businesses in many industries with vastly different business requirements. They put those requirements ahead of database performance. That&amp;rsquo;s probably smart business, but I&amp;rsquo;m not a business person&amp;ndash;I&amp;rsquo;m a database person. My experience with Dynamics CRM is when people come to me and say&lt;/p&gt;</description></item><item><title>What’s wrong with DELETE EXISTS?</title><link>https://am2.co/2017/06/30/whats-wrong-delete-exists/</link><pubDate>Fri, 30 Jun 2017 14:26:41 -0400</pubDate><guid>https://am2.co/2017/06/30/whats-wrong-delete-exists/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:300px"&gt;&lt;a href="https://archive.org/details/msdos_Number_Munchers_1990"&gt;&lt;img class="wp-image-1060 size-medium" src="https://am2.co/wp-content/uploads/NumberMunchers-300x187.png" alt="" width="300" height="187" /&gt;&lt;/a&gt; I loved playing Number Munchers on my Apple IIc&lt;/figure&gt;&#10;&lt;p&gt;This morning, when I logged into Twitter, the tweet at the top of my timeline was from Shane O&amp;rsquo;Neill (&lt;a href="https://nocolumnname.wordpress.com/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|&lt;a href="https://www.twitter.com/SOZDBA" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). It was to his blog post, &lt;a href="https://nocolumnname.wordpress.com/2017/06/30/shane-whats-wrong-with-delete-exists/" target="_blank" rel="noopener"&gt;Shane, What&amp;rsquo;s wrong with DELETE EXISTS?&lt;/a&gt;.  It&amp;rsquo;s not that unusual that Shane would talk to himself in the third person, but I was intrigued by the title.&lt;/p&gt;</description></item><item><title>TSQL Tuesday #85: Backup + Recovery + ☁️</title><link>https://am2.co/2016/12/13/tsql-tuesday-85-backup-recovery/</link><pubDate>Tue, 13 Dec 2016 22:11:48 -0500</pubDate><guid>https://am2.co/2016/12/13/tsql-tuesday-85-backup-recovery/</guid><description>&lt;blockquote&gt;&lt;a href="https://sqlstudies.com/2016/12/06/4169/"&gt;&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" alt="TSQL2SDAY" width="300" height="300" /&gt;&lt;/a&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Kenneth Fisher&lt;/strong&gt; (&lt;a href="https://sqlstudies.com/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;| &lt;a href="https://twitter.com/sqlstudent144" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). The topic: &lt;strong&gt;&lt;a href="https://sqlstudies.com/2016/12/06/4169/" target="_blank" rel="noopener"&gt;Backup &amp;amp; Recovery&lt;/a&gt;&lt;/strong&gt;&lt;/blockquote&gt;&#10;## Your backups are my bread &amp;amp; butter&#10;Backup &amp;amp; recovery are a DBA's &lt;a href="https://en.wikipedia.org/wiki/Glossary_of_baseball_(B)#bread_and_butter" target="_blank" rel="noopener"&gt;bread &amp;amp; butter&lt;/a&gt;. I always tell people that if you can't restore from backup in an emergency, you should at least make sure your resume is up to date--you'll need it. Part of my approach to making sure I have foolproof backups is making sure my setup is scripted and fool-proof to configure. Traditionally, this has been as simple as some T-SQL scripts that create the &lt;a href="https://ola.hallengren.com/sql-server-backup.html"&gt;backup stored procedure&lt;/a&gt;, and create a few SQL Agent jobs.&#10;&lt;p&gt;The SQL Agent jobs would write to the NAS, use the company standard retention, and everything was set. No muss, no fuss.&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #83: Roundup</title><link>https://am2.co/2016/10/16/t-sql-tuesday-83-roundup/</link><pubDate>Sun, 16 Oct 2016 20:49:50 -0400</pubDate><guid>https://am2.co/2016/10/16/t-sql-tuesday-83-roundup/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=ImaYMoTi2g8"&gt;&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" alt="TSQL2SDAY" width="300" height="300" /&gt;&lt;/a&gt;For this month&amp;rsquo;s T-SQL Tuesday, I asked people to blog about &lt;a href="https://am2.co/2016/10/04/t-sql-tuesday-83/"&gt;the same old problems we&amp;rsquo;ve been dealing with for years&lt;/a&gt;. There were some great posts, including a batch of first-time contributors. You&amp;rsquo;ll notice some overlapping themes as you read through these responses&amp;ndash;I think those themes represent some of the biggest, most important problems we have (like being able to restore backups). Thanks for everyone who contributed this month!&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #83: We're still dealing with the same problems</title><link>https://am2.co/2016/10/04/t-sql-tuesday-83/</link><pubDate>Tue, 04 Oct 2016 09:00:37 -0400</pubDate><guid>https://am2.co/2016/10/04/t-sql-tuesday-83/</guid><description>&lt;h3 id="what-is-t-sql-tuesday"&gt;What is T-SQL Tuesday?&lt;/h3&gt;&#10;&lt;p&gt;&lt;img class="alignright size-full wp-image-532" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" alt="TSQL2SDAY" width="300" height="300" /&gt;T-SQL Tuesday is a monthly blog party hosted by a different blogger each month. This blog party was started by Adam Machanic (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). You can take part by posting your own participating post that fits the topic of the month and follows the requirements below. Additionally, if you are interested in hosting a future T-SQL Tuesday, contact Adam Machanic on his blog.&lt;/p&gt;</description></item><item><title>Will a SELECT . . . INTO use short-circuit evaluation for a COALESCE?</title><link>https://am2.co/2016/08/02/will-a-select-into-use-short-circuit-evaluation-for-a-coalesce/</link><pubDate>Tue, 02 Aug 2016 14:45:55 -0400</pubDate><guid>https://am2.co/2016/08/02/will-a-select-into-use-short-circuit-evaluation-for-a-coalesce/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/145644/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I'm building a stored proc that can take in two separate values that each can be used to identify a single record. One of these values may be null.&lt;/p&gt;&#10;&lt;p&gt;My logic is as follows: if &lt;code&gt;IN_ORDER_ID&lt;/code&gt; is not NULL, save it to &lt;code&gt;V_ORDER_ID&lt;/code&gt;. If it is NULL, then retrieve &lt;code&gt;ORDER_ID&lt;/code&gt; with a query and save that to &lt;code&gt;V_ORDER_ID&lt;/code&gt;. &lt;code&gt;V_ORDER_ID&lt;/code&gt; is then used in the rest of the procedure.&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #79 - COMPRESS()ing LOB data</title><link>https://am2.co/2016/06/14/t-sql-tuesday-79/</link><pubDate>Tue, 14 Jun 2016 09:00:25 -0400</pubDate><guid>https://am2.co/2016/06/14/t-sql-tuesday-79/</guid><description>&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" width="300" height="300" /&gt;&#10;&lt;blockquote&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Michael J Swart&lt;/strong&gt; (&lt;a href="http://michaeljswart.com/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;| &lt;a href="https://twitter.com/mjswart" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). The topic: &lt;strong&gt;&lt;a href="http://michaeljswart.com/2016/06/t-sql-tuesday-079-its-2016/" target="_blank" rel="noopener"&gt;SQL Server 2016 is out!&lt;/a&gt;&lt;/strong&gt;&lt;/blockquote&gt;&#10;SQL Server 2016 is hot off the presses, and Michael challenges us to blog about it.&#10;&lt;p&gt;I&amp;rsquo;ve been using SSMS 2016 (I&amp;rsquo;m impressed!), but I haven&amp;rsquo;t spent tons of time using the server-side bits. As I type this intro, the 2016 installer is chugging along getting a fresh instance ready for me to explore so I can write about&amp;hellip;&lt;/p&gt;</description></item><item><title>Add-Equals operator</title><link>https://am2.co/2016/05/24/add-equals-operator/</link><pubDate>Tue, 24 May 2016 10:00:19 -0400</pubDate><guid>https://am2.co/2016/05/24/add-equals-operator/</guid><description>&lt;h2 id="shortcuts--tips-from-an-impatient-dba"&gt;Shortcuts &amp;amp; tips from an Impatient DBA&lt;/h2&gt;&#10;&lt;p&gt;This series of short posts will demonstrate some lesser-known features, keyboard shortcuts, and other tips that make my day as a DBA more productive. None of these are groundbreaking super-secret features–they are the little things that I do as part of my daily work that make me more efficient.&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #78– sys.dm_db_file_space_usage</title><link>https://am2.co/2016/05/10/tsql-tuesday-78/</link><pubDate>Tue, 10 May 2016 10:00:59 -0400</pubDate><guid>https://am2.co/2016/05/10/tsql-tuesday-78/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=R0xoMhCT-7A"&gt;&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" width="300" height="300" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;blockquote&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Wendy Pastrick&lt;/strong&gt; (&lt;a href="http://wendyverse.blogspot.com/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;| &lt;a href="https://twitter.com/wendy_dance" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). The topic: &lt;a href="http://wendyverse.blogspot.com/2016/04/its-time-for-t-sql-tuesday-78-may-2016.html" target="_blank" rel="noopener"&gt;&lt;strong&gt;Learn something new and blog about it&lt;/strong&gt;&lt;/a&gt;&lt;/blockquote&gt;&#10;SQL Server 2016 is coming out next month, and it's chock full of new features that I can learn. &lt;a href="https://msdn.microsoft.com/en-us/library/dn765131.aspx" target="_blank" rel="noopener"&gt;Row-level security&lt;/a&gt; is interesting. &lt;a href="https://msdn.microsoft.com/en-us/library/mt130841.aspx" target="_blank" rel="noopener"&gt;Dynamic data masking&lt;/a&gt; sounds fun.&#10;&lt;p&gt;If you&amp;rsquo;re a regular reader of my blog, you probably know I try to approach questions from a unique angle. Instead of blogging about something cutting edge or sexy, I decided to scroll through the list of system views until I found one I didn&amp;rsquo;t recognize.&lt;/p&gt;</description></item><item><title>How to shrink a database in 4 easy steps</title><link>https://am2.co/2016/04/28/shrink-database-4-easy-steps/</link><pubDate>Thu, 28 Apr 2016 11:00:22 -0400</pubDate><guid>https://am2.co/2016/04/28/shrink-database-4-easy-steps/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:238px"&gt;&lt;a href="https://www.youtube.com/watch?v=03L8u9S1vyY" rel="noopener noreferrer" target="_blank"&gt;&lt;img class="wp-image-438 size-medium" src="https://am2.co/wp-content/uploads/ShrinkyDinks-1-238x300.jpg" alt="I pity the fool who shrinks his database!" width="238" height="300" /&gt;&lt;/a&gt; I pity the fool who needs to shrink his database!&lt;/figure&gt;&#10;&lt;p&gt;It&amp;rsquo;s a really common question: &amp;ldquo;How do I shrink my database?&amp;rdquo;&#10;Luckily, there&amp;rsquo;s also a really common answer: &amp;ldquo;Don&amp;rsquo;t.&amp;rdquo;&lt;/p&gt;&#10;&lt;h3 id="but-what-if-you-really-have-to"&gt;&amp;hellip;but what if you really have to?&lt;/h3&gt;&#10;&lt;p&gt;Perhaps you just implemented &lt;a href="https://am2.co/category/data-compression/"&gt;data compression&lt;/a&gt;, and have 60% free space in your database.&#10;Perhaps you just deleted a bunch of old data, and have significant free space in your database.&#10;There are a handful of scenarios where you have free space in the database, you&amp;rsquo;ll never use it, and you need to shrink. Just don&amp;rsquo;t make a habit of it.&lt;/p&gt;</description></item><item><title>CONVERT() to float using scientific notation</title><link>https://am2.co/2016/04/20/convert-float-using-scientific-notation/</link><pubDate>Wed, 20 Apr 2016 10:57:01 -0400</pubDate><guid>https://am2.co/2016/04/20/convert-float-using-scientific-notation/</guid><description>&lt;p&gt;Someone posted to &lt;a href="https://twitter.com/search?f=tweets&amp;amp;vertical=default&amp;amp;q=%23sqlhelp" target="_blank"&gt;#sqlhelp&lt;/a&gt; on Twitter, asking the following: &amp;ldquo;Wondered if anyone could enlighten me as to why ISNUMERIC(&amp;lsquo;7d8&amp;rsquo;) returns 1?&amp;rdquo;&lt;/p&gt;&#10;&lt;p&gt;Sure enough, &lt;code&gt;SELECT ISNUMERIC('7d8')&lt;/code&gt; returns a 1.&lt;/p&gt;&#10;&lt;h3 id="wtf-d-isnt-numeric"&gt;WTF? d isn&amp;rsquo;t numeric!&lt;/h3&gt;&#10;&lt;p&gt;OK, sure, if you say &amp;ldquo;seven-dee-eight&amp;rdquo; out loud it &lt;em&gt;sounds&lt;/em&gt; like a number, but &amp;ldquo;d&amp;rdquo; is a letter, not a number.&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #77– My favorite SQL Server feature</title><link>https://am2.co/2016/04/12/tsql-tuesday-77/</link><pubDate>Tue, 12 Apr 2016 22:51:47 -0400</pubDate><guid>https://am2.co/2016/04/12/tsql-tuesday-77/</guid><description>&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" width="300" height="300" /&gt;&#10;&lt;blockquote&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Jens Vestergaard&lt;/strong&gt; (&lt;a href="http://t-sql.dk/" target="_blank" rel="noopener"&gt;blog &lt;/a&gt;| &lt;a href="https://twitter.com/vestergaardj" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). The topic: &lt;a href="http://t-sql.dk/?p=1492" target="_blank" rel="noopener"&gt;&lt;strong&gt;Favorite SQL Server Feature&lt;/strong&gt;&lt;/a&gt;.&lt;/blockquote&gt;&#10;When I saw this topic, I was really excited. My mind started racing through all the awesome features in SQL Server. I spend a lot of time dealing with HA and DR--so many features to choose from...but are any of them my &lt;strong&gt;favorite&lt;/strong&gt;? No, probably not. &lt;a href="https://www.mssqltips.com/sqlservertip/2445/sql-server-multi-server-administration/" target="_blank" rel="noopener"&gt;MSX&lt;/a&gt; and &lt;a href="https://msdn.microsoft.com/en-us/library/bb895144.aspx" target="_blank" rel="noopener"&gt;CMS&lt;/a&gt; have made my life so much easier, and they are incredibly cool, and I've not blogged about either of them...but...neither is my favorite.&#10;&lt;p&gt; &lt;/p&gt;</description></item><item><title>Decoding sql_handle</title><link>https://am2.co/2016/02/29/decoding_sql_handle/</link><pubDate>Mon, 29 Feb 2016 10:05:54 -0500</pubDate><guid>https://am2.co/2016/02/29/decoding_sql_handle/</guid><description>&lt;p&gt;If you&amp;rsquo;ve ever looked at sys.sysprocesses or sys.dm_exec_requests (or a number of other DMVs), you&amp;rsquo;ve noticed there is a column called &amp;ldquo;sql_handle&amp;rdquo; that contains some binary gobbledygook. Books Online gives the (un)helpful definition as &amp;ldquo;Hash map of the SQL text of the request.&amp;rdquo;&lt;/p&gt;&#10;&lt;h3 id="sp_whoisactive"&gt;sp_WhoIsActive&lt;/h3&gt;&#10;&lt;p&gt;In the context of currently-running processes, most people decode sql_handle with Adam Machanic&amp;rsquo;s (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|&lt;a href="https://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;) &lt;a href="http://whoisactive.com/" target="_blank" rel="noopener"&gt;sp_WhoIsActive&lt;/a&gt;. It&amp;rsquo;s really easy &amp;amp; straightforward&amp;ndash;if you&amp;rsquo;re not familiar with Adam&amp;rsquo;s utility, download it and check it out. My friend Mike Kane (&lt;a href="http://www.michaelkane.me/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|&lt;a href="https://twitter.com/tcp1433" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;) has an &lt;a href="http://www.michaelkane.me/2016/03/how-i-use-sp_whoisactive/" target="_blank" rel="noopener"&gt;interesting post&lt;/a&gt; on parameter combinations he regularly uses when using sp_WhoIsActive.&lt;/p&gt;</description></item><item><title>RECONFIGURE—When to use WITH OVERRIDE?</title><link>https://am2.co/2015/11/17/reconfigure-when-to-use-with-override/</link><pubDate>Tue, 17 Nov 2015 11:00:19 -0500</pubDate><guid>https://am2.co/2015/11/17/reconfigure-when-to-use-with-override/</guid><description>&lt;p&gt;When you&amp;rsquo;re using sp_configure to change a system configuration, you have to run a RECONFIGURE to finalize your change. You even get the helpful output that reminds you to run RECONFIGURE:&lt;/p&gt;&#10;&lt;pre&gt;Configuration option 'max degree of parallelism' changed from 0 to 1. &#10;Run the RECONFIGURE statement to install.&lt;/pre&gt;&#10;&lt;p&gt;There are many places online with code samples (Books Online, blog posts, vendor documentation, etc) that actually use the additional &amp;ldquo;RECONFIGURE WITH OVERRIDE&amp;rdquo; syntax:&#10;&lt;a href="http://blog.sqlauthority.com/2007/10/20/sql-server-set-server-level-fillfactor-using-t-sql-script/" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;.&#10;&lt;a href="https://msdn.microsoft.com/en-us/library/ms189094.aspx" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;.&#10;&lt;a href="http://www.mytechmantra.com/LearnSQLServer/How-to-Enable-and-Disable-XP_CMDSHELL-using-SP_CONFIGURE/" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;.&#10;There are even posts that switch between including &amp;ldquo;WITH OVERRIDE&amp;rdquo; and not including it&#10;&lt;a href="http://www.snapdba.com/2013/04/enabling-and-configuring-database-mail-in-sql-server-using-t-sql/" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Converting delimited values to a table (efficiently?)</title><link>https://am2.co/2015/04/21/converting-delimited-values-to-a-table-efficiently/</link><pubDate>Tue, 21 Apr 2015 15:33:00 -0400</pubDate><guid>https://am2.co/2015/04/21/converting-delimited-values-to-a-table-efficiently/</guid><description>&lt;p&gt;This is a pretty common problem. I think it&amp;rsquo;s a question every developer has asked at one time or another: &amp;ldquo;I want to pass in a comma-separated list of values, then convert it into a table.&amp;quot;&lt;br /&gt;&lt;br /&gt;Every company I&amp;rsquo;ve ever worked for has had a function that does this. Everyone does it differently. It&amp;rsquo;s never efficient. I&amp;rsquo;ve seen it done in CLR, I&amp;rsquo;ve seen it done as a multi-statement table-valued user-defined function (which we all know is the devil&amp;rsquo;s work). The CLR works, but it&amp;rsquo;s a black-box to the average DBA or SQL developer. The multi-statement TVF performs terribly, but has never been used heavily enough to make it to the top of my tuning list. &lt;br /&gt;&lt;br /&gt;This morning, I saw Pinal Dave (&lt;a href="https://twitter.com/pinaldave" target="_blank" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;|&lt;a href="http://blog.sqlauthority.com/" target="_blank" rel="noopener noreferrer"&gt;blog&lt;/a&gt;) &lt;a href="http://blog.sqlauthority.com/2015/04/21/sql-server-split-comma-separated-list-without-using-a-function/" target="_blank" rel="noopener noreferrer"&gt;post on his blog&lt;/a&gt; about this topic, and he used a really elegant XML-based solution. It&amp;rsquo;s one of those solutions that&amp;rsquo;s so simple, it&amp;rsquo;s incredibly hard.&lt;br /&gt;&lt;br /&gt;When I got to my desk this morning, I immediately wrapped Pinal&amp;rsquo;s code into a function that was backwards compatible to a multi-statement TVF version and performance tested them head-to-head.&lt;br /&gt;&lt;br /&gt;Here&amp;rsquo;s my function definition:&lt;br /&gt;&lt;/p&gt;</description></item><item><title>sp_executesql with output parameters</title><link>https://am2.co/2015/01/22/sp_executesql-with-output-parameters/</link><pubDate>Thu, 22 Jan 2015 20:05:00 -0500</pubDate><guid>https://am2.co/2015/01/22/sp_executesql-with-output-parameters/</guid><description>&lt;p&gt;One of my coworkers asked me about output parameters from dynamic SQL today. I pointed him at sp_executesql, which allows for passing parameters into or out of dynamic SQL. The syntax can be confusing at first blush (especially for a new DBA or developer), but it&amp;rsquo;s really pretty straightforward, easy, and useful.&lt;/p&gt;</description></item></channel></rss>