<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblogcasts.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>My two cents</title><link>http://sqlblogcasts.com/blogs/leopasta/default.aspx</link><description>Tips, opinions, tests (and misspellings) from a Brazilian DBA in UK</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>How atomic is a SELECT INTO?</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2012/05/22/how-atomic-is-a-select-into.aspx</link><pubDate>Tue, 22 May 2012 22:47:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16215</guid><dc:creator>leo.pasta</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=16215</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=16215</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2012/05/22/how-atomic-is-a-select-into.aspx#comments</comments><description>&lt;p&gt;Last week I got an interesting situation that prompted me to challenge a long standing assumption. I always thought that a &lt;em&gt;SELECT INTO&lt;/em&gt; was an atomic statement, i.e. it would either complete successfully or the table would not be created.&lt;/p&gt;

&lt;p&gt;So I got very surprised when, after a “select into” query was chosen as a deadlock victim, the next execution (as the app would handle the deadlock and retry) would fail with:&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000" face="Courier New"&gt;Msg 2714, Level 16, State 6, Line 1 
    &lt;br /&gt;There is already an object named &amp;#39;#test&amp;#39; in the database.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The only hypothesis we could come up was that the “create table” part of the statement was committed independently from the actual “insert”. We can confirm that by capturing the “Transaction Log” event on Profiler (filtering by SPID0). The result is that when we run:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;INTO&lt;/span&gt; #results &lt;span class="kwrd"&gt;FROM&lt;/span&gt; master.sys.objects&lt;/pre&gt;

&lt;p&gt;we get the following output on Profiler:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/leopasta/image_188315F8.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/leopasta/image_thumb_2C2FFF8C.png" width="689" height="99" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;It is easy to see the two independent transactions. Although this behaviour was a surprise to me, it is very easy to workaround it if you feel the need (as we did in this case). You can either change it into independent “CREATE TABLE / INSERT SELECT” or you can enclose the SELECT INTO in an explicit transaction:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; XACT_ABORT &lt;span class="kwrd"&gt;ON&lt;/span&gt;
&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;TRANSACTION&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;INTO&lt;/span&gt; #results &lt;span class="kwrd"&gt;FROM&lt;/span&gt; master.sys.objects
COMMIT&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/leopasta/image_3CC7FA7A.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/leopasta/image_thumb_4D5FF568.png" width="679" height="142" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16215" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/SELECT+INTO/default.aspx">SELECT INTO</category><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/Temp+Tables/default.aspx">Temp Tables</category></item><item><title>Coming back from (blog) retirement</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2012/05/22/coming-back-from-blog-retirement.aspx</link><pubDate>Tue, 22 May 2012 21:30:54 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16214</guid><dc:creator>leo.pasta</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=16214</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=16214</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2012/05/22/coming-back-from-blog-retirement.aspx#comments</comments><description>&lt;p&gt;So, it has been more than 3 years without a single blog post. I wished I could have a decent excuse for it, but in the end, I guess it boils down to laziness and procrastination. :-)&lt;/p&gt;  &lt;p&gt;Even though I learned a lot in that period (and added a feel tricks to my bag), I couldn’t find the will to sit down and write. I hope all my readers (yes mom and dad, I’m talking to you) have not been disappointed.&lt;/p&gt;  &lt;p&gt;I will try really hard not to let routine take over. I don’t expect I will be the most active blogger in the community, but hopefully a couple of posts per month is a good target to aim.&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16214" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/Personal/default.aspx">Personal</category></item><item><title>Getting all the Clustered keys in the database</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2009/03/30/getting-all-the-clustered-keys-in-the-database.aspx</link><pubDate>Mon, 30 Mar 2009 15:47:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11502</guid><dc:creator>leo.pasta</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=11502</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=11502</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2009/03/30/getting-all-the-clustered-keys-in-the-database.aspx#comments</comments><description>Jeremiah Peschka (http://twitter.com/peschkaj) asked on twitter if anyone had a script to list all clustered keys in the database. This is my take on it, I hope it helps someone: SELECT i.name , &amp;#39;(&amp;#39; + STUFF ( ( SELECT &amp;#39;,&amp;#39; + c.name + CASE...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2009/03/30/getting-all-the-clustered-keys-in-the-database.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11502" width="1" height="1"&gt;</description></item><item><title>Reducing Transaction Log fragmentation</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2008/09/02/reducing-transaction-log-fragmentation.aspx</link><pubDate>Tue, 02 Sep 2008 22:09:25 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:10772</guid><dc:creator>leo.pasta</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=10772</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=10772</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2008/09/02/reducing-transaction-log-fragmentation.aspx#comments</comments><description>I am taking Kimberly Tripp and Paul Randal&amp;#39;s course on SQL Server Performance &amp;amp; Availability this week in Hatfield and we had an interesting discussion on Transaction Log internal fragmentation. Kimberly summarized the issue, together with other...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2008/09/02/reducing-transaction-log-fragmentation.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=10772" width="1" height="1"&gt;</description></item><item><title>Which queries are missing indexes?</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2008/05/08/which-queries-are-missing-indexes.aspx</link><pubDate>Thu, 08 May 2008 20:48:28 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:10381</guid><dc:creator>leo.pasta</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=10381</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=10381</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2008/05/08/which-queries-are-missing-indexes.aspx#comments</comments><description>One of the things I really enjoy when doing performance tuning on 2005 (I still work on a mix of several SQL 2000 and some SQL 2005) is the sys.dm_db_missing_index* DMVs. As the query processor evaluates queries, it detects if that specific query could...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2008/05/08/which-queries-are-missing-indexes.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=10381" width="1" height="1"&gt;</description></item><item><title>SQLBits</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2008/03/02/sqlbits.aspx</link><pubDate>Sun, 02 Mar 2008 21:47:24 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:8452</guid><dc:creator>leo.pasta</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=8452</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=8452</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2008/03/02/sqlbits.aspx#comments</comments><description>Yesterday I attended the SQL Server focused conference called SQLBits , which this year took place in Birmingham. First of all, many thanks to Tony Rogerson , Simon Sabin and all organisers. You did a hell of a good job!!! As a suggestion for the next...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2008/03/02/sqlbits.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=8452" width="1" height="1"&gt;</description></item><item><title>Data purity</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2007/11/26/data-purity.aspx</link><pubDate>Mon, 26 Nov 2007 22:39:41 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:4776</guid><dc:creator>leo.pasta</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=4776</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=4776</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2007/11/26/data-purity.aspx#comments</comments><description>Reviewing DBCC CHECKDB syntax for SQL Server 2005, I found a [DATA_PURITY] option added to its syntax. This option enable the following checks on each column value of those datatypes: Unicode character - The data length should be a multiple of 2. Datetime...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2007/11/26/data-purity.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=4776" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/Recovery/default.aspx">Recovery</category></item><item><title>Losing your Transaction log</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2007/11/20/losing-your-transaction-log.aspx</link><pubDate>Tue, 20 Nov 2007 00:17:50 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:4348</guid><dc:creator>leo.pasta</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=4348</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=4348</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2007/11/20/losing-your-transaction-log.aspx#comments</comments><description>Technorati Tags: SQL Server , Recovery Some days ago, my boss got on my desk asking if I could take a look at one database that was not opening. That DB was in a virtual machine used for our sales presentations. For some reason, several files got corrupted...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2007/11/20/losing-your-transaction-log.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=4348" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/Recovery/default.aspx">Recovery</category></item><item><title>The sound of silence</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2007/09/06/the-sound-of-silence.aspx</link><pubDate>Thu, 06 Sep 2007 22:14:01 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:2501</guid><dc:creator>leo.pasta</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=2501</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=2501</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2007/09/06/the-sound-of-silence.aspx#comments</comments><description>This one isn't related to SQL Server. But do you know when sometimes you get stuck in an almost infinite loop of dialog boxes and for some reason you don't want to kill the application? "Sorry &amp;lt;beep&amp;gt; guys, this &amp;lt;beep&amp;gt; should &amp;lt;beep&amp;gt; end...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2007/09/06/the-sound-of-silence.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=2501" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Page splits</title><link>http://sqlblogcasts.com/blogs/leopasta/archive/2007/08/13/page-splits.aspx</link><pubDate>Mon, 13 Aug 2007 20:36:07 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:2198</guid><dc:creator>leo.pasta</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/rsscomments.aspx?PostID=2198</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://sqlblogcasts.com/blogs/leopasta/commentapi.aspx?PostID=2198</wfw:comment><comments>http://sqlblogcasts.com/blogs/leopasta/archive/2007/08/13/page-splits.aspx#comments</comments><description>These days, investigating a fairly simple insert which was taking longer than what I would consider reasonable for that particular piece of code, I explored several possible causes. One thing that raised my attention was that the "Pages split/sec" perfmon...(&lt;a href="http://sqlblogcasts.com/blogs/leopasta/archive/2007/08/13/page-splits.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=2198" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/SQL+Server/default.aspx">SQL Server</category></item></channel></rss>