<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.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>Database Programming: Game, Set, Match -- Why Writing Code In Transact-SQL Is Different Than Writing In A Compiled Language</title><link>http://blogs.technet.com/wardpond/archive/2006/09/19/database-programming-game-set-match-why-writing-code-in-transact-sql-is-different-than-writing-in-a-compiled-language.aspx</link><description>More tidbits from an internal discussion.. it'll take us awhile to get to the answer to the titular question; hopefully you'll find this a worthy journey. Mike asked, in a nutshell, why this batch is taking so long to run: SET NOCOUNT ON DECLARE @Rows</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Database Programming: Game, Set, Match -- Why Writing Code In Transact-SQL Is Different Than Writing In A Compiled Language</title><link>http://blogs.technet.com/wardpond/archive/2006/09/19/database-programming-game-set-match-why-writing-code-in-transact-sql-is-different-than-writing-in-a-compiled-language.aspx#457670</link><pubDate>Wed, 20 Sep 2006 10:50:55 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:457670</guid><dc:creator>Hugo Kornelis</dc:creator><description>Hi Ward,
&lt;br&gt;
&lt;br&gt;Yep, I think I can do faster.
&lt;br&gt;
&lt;br&gt;Five subsequent executions of your code on my sandbox, all with clean cache and buffers, took 890, 906, 940, 1030, and 906 ms respectively. (I discarded the very first execution; that one took about 3 seconds, but I think that the database files had to grow).
&lt;br&gt;
&lt;br&gt;I then tested the code posted below and got 813, 796, 810, 1000, and 846 ms on 5 subsequent executions. I can't really explain the one with 1000 ms - maybe CPU or I/O conflicts with one of the other processes running on my box?
&lt;br&gt;
&lt;br&gt;Anyway, here's the code. Note that I used the same &amp;quot;surrounding&amp;quot; code to measure performance of both your and my versions. Also note that I tested on an empty database; if yoou have a database with at least 1,000 rows in sysobjects, you'll only need two cross-joins of said table.
&lt;br&gt;
&lt;br&gt;drop table SomeTable;
&lt;br&gt;go
&lt;br&gt;checkpoint;
&lt;br&gt;dbcc freeproccache;
&lt;br&gt;dbcc dropcleanbuffers;
&lt;br&gt;go
&lt;br&gt;declare @start datetime;
&lt;br&gt;set @start = getdate();
&lt;br&gt;select top (1000000) newid() as uuid
&lt;br&gt;into SomeTable
&lt;br&gt;from sysobjects a, sysobjects b, sysobjects c, sysobjects d;
&lt;br&gt;select datediff(ms, @start, getdate());
&lt;br&gt;go
&lt;br&gt;select count(*) from SomeTable;
&lt;br&gt;
&lt;br&gt;Best regards,
&lt;br&gt;
&lt;br&gt;Hugo Kornelis</description></item><item><title>Ward Pond's SQL Server blog : Database Programming: Set-Based Update -- Hugo's Syntax Outperforms Shaun's; Ward Tweaks Hugo's Syntax Even Further</title><link>http://blogs.technet.com/wardpond/archive/2006/09/19/database-programming-game-set-match-why-writing-code-in-transact-sql-is-different-than-writing-in-a-compiled-language.aspx#457857</link><pubDate>Thu, 21 Sep 2006 10:06:56 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:457857</guid><dc:creator>Ward Pond's SQL Server blog : Database Programming: Set-Based Update -- Hugo's Syntax Outperforms Shaun's; Ward Tweaks Hugo's Syntax Even Further</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://blogs.technet.com/wardpond/archive/2006/09/20/457856.aspx"&gt;http://blogs.technet.com/wardpond/archive/2006/09/20/457856.aspx&lt;/a&gt;</description></item><item><title>The prime number challenge – great waste of time!</title><link>http://blogs.technet.com/wardpond/archive/2006/09/19/database-programming-game-set-match-why-writing-code-in-transact-sql-is-different-than-writing-in-a-compiled-language.aspx#458523</link><pubDate>Sun, 24 Sep 2006 01:55:59 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:458523</guid><dc:creator>SELECT Hints, Tips, Tricks FROM Hugo Kornelis WHERE RDBMS = 'SQL Server'</dc:creator><description>No sane person would even consider using SQL Server to construct a list of prime numbers. So just to...</description></item><item><title>Denis Offers A Challenge</title><link>http://blogs.technet.com/wardpond/archive/2006/09/19/database-programming-game-set-match-why-writing-code-in-transact-sql-is-different-than-writing-in-a-compiled-language.aspx#1552445</link><pubDate>Thu, 19 Jul 2007 00:17:54 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:1552445</guid><dc:creator>Ward Pond's SQL Server blog</dc:creator><description>&lt;p&gt;&amp;quot; Denis the SQL Menace &amp;quot; is at it again. When we last heard from Denis on a technical matter in this&lt;/p&gt;
</description></item></channel></rss>