<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.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>Linchi Shea : Scripting</title><link>http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx</link><description>Tags: Scripting</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Transactional replication and massive data updates</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2011/10/06/transactional-replication-and-massive-data-updates.aspx</link><pubDate>Thu, 06 Oct 2011 04:19:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38876</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/38876.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=38876</wfw:commentRss><description>SQL Server transactional replication has been a rather solid feature and works well for delivering data to reporting servers (among other things) in near real time. That said, it may not work too well when you need to perform massive updates on a published...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2011/10/06/transactional-replication-and-massive-data-updates.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=38876" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Replication/default.aspx">Replication</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Scripting for the out-of-band attention</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2010/11/20/scripting-for-the-out-of-band-attention.aspx</link><pubDate>Sun, 21 Nov 2010 02:53:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:30846</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/30846.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=30846</wfw:commentRss><description>I have written a lot of throw-away scripts, some of which were written to control the execution of a large number of SQL scripts. The logic of these control scripts is often simple, but their execution can last for a long time (e.g. hours). When writing...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2010/11/20/scripting-for-the-out-of-band-attention.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=30846" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Automation/default.aspx">Automation</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Best+Practices/default.aspx">Best Practices</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Logging for post-processing</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2010/11/17/logging-for-post-processing.aspx</link><pubDate>Wed, 17 Nov 2010 19:31:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:30685</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/30685.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=30685</wfw:commentRss><description>As a practicing database professional, I'm sure you have done a lot of logging, I mean, output and/or error logging from your scripts, your scheduled jobs, and any other programs you might have written. The primary purpose of logging, of course, is to...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2010/11/17/logging-for-post-processing.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=30685" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Automation/default.aspx">Automation</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Deadlock/default.aspx">Deadlock</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Add-Content and Out-File are not for performance</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2010/01/04/add-content-and-out-file-are-not-for-performance.aspx</link><pubDate>Mon, 04 Jan 2010 21:31:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:20508</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/20508.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=20508</wfw:commentRss><description>When you write Powershell scripts and need to write a text file, you have a number of ways to accomplish that. The often suggested approach is to use cmdlets Add-Content or Out-File. Well, this is not news. But some may not notice that these cmdlets are...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2010/01/04/add-content-and-out-file-are-not-for-performance.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=20508" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category></item><item><title>Get an overview report on your log shipping setups</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/12/21/get-an-overview-report-on-your-log-shipping-setups.aspx</link><pubDate>Tue, 22 Dec 2009 02:45:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:20163</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/20163.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=20163</wfw:commentRss><description>[Updated Dec 23 to include a T-SQL script at the bottom of the post]. You may have an environment where log shipping is set up on various databases between various servers. Would it be handy to have an overview report highlighting which database is being...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2009/12/21/get-an-overview-report-on-your-log-shipping-setups.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=20163" width="1" height="1"&gt;</description><enclosure url="http://sqlblog.com/blogs/linchi_shea/attachment/20163.ashx" length="1746" type="application/x-zip-compressed" /><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Automation/default.aspx">Automation</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Log+shipping/default.aspx">Log shipping</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Perl/default.aspx">Perl</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Performance impact: Speeding up SMO script generation</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/12/13/performance-impact-speeding-up-smo-script-generation.aspx</link><pubDate>Sun, 13 Dec 2009 22:18:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:19824</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>7</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/19824.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=19824</wfw:commentRss><description>Generating scripts through SMO can be as simple as walking down the database object tree and applying the Script() method to each scriptable object. Well, that is until you start to try it on a database that has a large number of objects (say a few thousands),...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2009/12/13/performance-impact-speeding-up-smo-script-generation.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=19824" width="1" height="1"&gt;</description><enclosure url="http://sqlblog.com/blogs/linchi_shea/attachment/19824.ashx" length="13726" type="image/gif" /><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/SMO/default.aspx">SMO</category></item><item><title>Find the complete call tree for a stored procedure</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/10/23/find-the-complete-call-tree-for-a-stored-procedure.aspx</link><pubDate>Fri, 23 Oct 2009 03:11:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:18173</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/18173.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=18173</wfw:commentRss><description>Would it be nice to print out the complete call tree of a stored procedure? By complete call tree , I mean the following: · At the very top level, the call tree should identify all the procedures that are called directly. · For any given level, the next...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2009/10/23/find-the-complete-call-tree-for-a-stored-procedure.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=18173" width="1" height="1"&gt;</description><enclosure url="http://sqlblog.com/blogs/linchi_shea/attachment/18173.ashx" length="1328" type="application/x-zip-compressed" /><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Automation/default.aspx">Automation</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Linked+server/default.aspx">Linked server</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Perl/default.aspx">Perl</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Tools/default.aspx">Tools</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/T-SQL/default.aspx">T-SQL</category></item><item><title>T-SQL Exercise: Simplest data-loading script to produce worst query performance – May 25th Update</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/05/26/t-sql-exercise-simplest-data-loading-script-to-produce-worst-query-performance-may-25th-update.aspx</link><pubDate>Tue, 26 May 2009 12:52:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14275</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/14275.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=14275</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This is a quick update on the &lt;/FONT&gt;&lt;A href="http://sqlblog.com/blogs/linchi_shea/archive/2009/05/22/t-sql-exercise-simplest-data-loading-script-to-produce-worst-query-performance.aspx"&gt;&lt;FONT face="Times New Roman" color=#606420 size=3&gt;T-SQL exercise&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Times New Roman" size=3&gt; I posted a few days ago. The goal was to write a simple T-SQL script to generate and load 4,000,000 rows into a table so that the following query would produce the worst performance, i.e. take longest time to finish:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';"&gt;&lt;FONT size=3&gt;DBCC DROPCLEANBUFFERS&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';"&gt;&lt;FONT size=3&gt;SELECT COUNT(*) FROM dbo.test;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The original intent was to highlight some pitfalls in data loading that may lead to bad query performance. But then I thought why take all the fun away by having too many constraints, and why not just let it loose and see how bad it can get if one is to do it intentionally.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;I must say that just looking at the scripts from Denis, Adam, and Tibor, I came to realize that things were not quite what I had thought they were.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;For instance, I did not anticipate that a heap table could have performed the table scan so terribly in Tibor’s script. I thought that SQL Server would apply an allocation order scan and would optimize on the physical order regardless of forward pointers. Adam’s script surprised me with a freshly created clustered index. I thought that even if you could create a clustered index to push the limit on the fillfactor, the clustered index would defragment the data enabling SQL Server to scan the table efficiently, easily outweighing whatever gains (actually performance loss) you might get from lowering the page density.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;So predicting the query performance turned out to be not very precise at all. It’s better to actually test these scripts out. I ran Adam’s script, Tibor’s script, and my script in a database whose data file was placed on an internal RAID-1 set (i.e. two mirrored physical drives). The internal drive (which was also the system drive C) was used to avoid dealing with the confounding factors because of SAN cache, storage virtualization, and so on. In addition, the test database was given 45GB for data and 20GB for log, significantly larger than what would be required during the tests. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;All tests were done with SQL Server 2008 Enterpries x64 Edition (build 10.0.1600) on Windows Server 2003 Enterprise x64 Edition SP2 on an old HP ProLiant DL365 G1 with four cores and 4GB of physical memory.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Adam Machanic’s script&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;if exists (select * from sysobjects where name = 'test')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;drop table test&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;create table test (&lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;x int not null, &lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;y char(896) not null default (''), &lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;z char(120) not null default('')&lt;BR&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;insert test (x)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;select r&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;from&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;select row_number() over (order by (select 1)) r&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;from master..spt_values a, master..spt_values b&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;) p&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;where r &amp;lt;= 4000000&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;create clustered index ix_x on test (x, y) &lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;with fillfactor=51&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Tibor Karaszi’s script&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;if exists (select * from sysobjects where name = 'test')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;drop table test&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CREATE TABLE test (&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;x int NOT NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;,x2 int NOT NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;,y char(10) NOT NULL DEFAULT ('')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;,z char(10) NOT NULL DEFAULT('')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;DECLARE @rows int = 6666666, @toKeep int = 4000000, @diff int&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;INSERT test (x, x2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SELECT TOP(@rows)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS r&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;,ROW_NUMBER() OVER (ORDER BY (SELECT 1)) % 10 AS s&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;FROM master..spt_values a CROSS JOIN master..spt_values b&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;ALTER TABLE test ALTER COLUMN y char(892)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;ALTER TABLE test ALTER COLUMN z char(100)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CHECKPOINT&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;DECLARE @rows int = 6666666, @toKeep int = 4000000, @diff int&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;DELETE TOP(@rows - @toKeep) &lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;FROM test WHERE x2 IN(2, 4, 6, 8)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:11pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Note that Tibor’s script generated 3768021 rows instead of 4,000,000 rows in my tests. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Linchi Shea’s script&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;if exists (select * from sysobjects where name = 'test')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;drop table test&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;create table test(&lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;c1 int, &lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;c2 int, &lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;c3 char(256) default ' ', &lt;BR&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;c4 char(740) default ' ')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;create clustered index cix_test on test(c2, c3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;set nocount on&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;declare&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;@i int&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;set @i = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;begin tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;while @i &amp;lt;= 4000000&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;insert test(c1, c2) &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;select @i,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;case when @i % 2 = 0 then @i else 4000000 - @i end&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if @i % 100000 = 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;commit tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;begin tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;end&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set @i = @i + 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;end&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;commit tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;To ensure that when the test table was created, the database was in the same state. The test table was dropped at the beginning of each script. And at that point, the database was empty with no user data.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;After the data was loaded by each script, the test query (including DBCC DROPCLEANBUFFERS) was run three times, and each time the query elapsed time was logged. The following table shows the recorded elapsed times.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT:medium none;BORDER-TOP:medium none;MARGIN:auto auto auto 5.4pt;BORDER-LEFT:medium none;BORDER-BOTTOM:medium none;BORDER-COLLAPSE:collapse;mso-border-alt:solid windowtext .5pt;mso-yfti-tbllook:191;mso-padding-alt:0in 5.4pt 0in 5.4pt;mso-border-insideh:.5pt solid windowtext;mso-border-insidev:.5pt solid windowtext;" cellSpacing=0 cellPadding=0 class="MsoTableGrid"&gt;

&lt;TR style="mso-yfti-irow:0;mso-yfti-firstrow:yes;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:windowtext 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Test run&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:windowtext 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Elapsed time (second)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:1;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Adam’s script – test run 1&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;123&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:2;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Adam’s script – test run 2&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;121&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:3;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Adam’s script – test run 3&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;120&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:4;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Tibor’s script – test run 1&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;205&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:5;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Tibor’s script – test run 2&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;207&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:6;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Tibor’s script – test run 3&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;177&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:7;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Linchi’s script – test run 1&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;408&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:8;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Linchi’s script – test run 2&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;354&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:9;mso-yfti-lastrow:yes;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:windowtext 1pt solid;WIDTH:189pt;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Linchi’s script – test run 3&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0in;BORDER-LEFT:#d4d0c8;WIDTH:2.75in;PADDING-TOP:0in;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;TEXT-ALIGN:right;" align=right&gt;&lt;FONT face="Times New Roman" size=3&gt;358&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Afterwards, for validation, the above entire process was repeated one more time. In other words, the test query was run six times for each data-loading script. The test query elapsed times were consistent with those recorded in the above table.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Now, in no way I’d claim that my script has managed to produce the worst query performance. I’m pretty sure that you can find a way to load data to produce much worse query performance. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;In addition, as Adam and Tibor observed, the results may be dependent on many factors including the test system configurations. Although on a given test system the test results should be consistent, it could be misleading to compare the results across different test systems.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;A case in point is that if you disable read-ahead reads entirely, the query performance would be much worse than any of the elapsed times posted above. So perhaps, your dataset can be loaded so that it induces SQL Server not to make effective use of read-ahead reads, and therefore get worse query performance.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;I’m looking forward to seeing more scripts with worse query performance than the three scripts referenced in this post.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=14275" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Disk+I_2F00_O/default.aspx">Disk I/O</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Storage/default.aspx">Storage</category></item><item><title>T-SQL Exercise: Simplest data-loading script to produce worst query performance</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/05/22/t-sql-exercise-simplest-data-loading-script-to-produce-worst-query-performance.aspx</link><pubDate>Fri, 22 May 2009 19:21:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14209</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>19</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/14209.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=14209</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Here is a T-SQL scripting exercise in case you have a few minutes to spare or are bored with whatever else&amp;nbsp;you are doing.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Objective&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The task is to write a simple T-SQL script to generate and load 4,000,000 rows into a test table. The objective is to make the following simple test query to have the &lt;U&gt;worst&lt;/U&gt; performance in terms of elapsed time:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';"&gt;&lt;FONT size=3&gt;DBCC DROPCLEANBUFFERS&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e6e6e6;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';"&gt;&lt;FONT size=3&gt;SELECT COUNT(*) FROM dbo.test;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The longer the elapsed time, the worst it is.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Constraints&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Of course, there must be a number of constraints, and they are as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;tab-stops:list 0in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;The test table can have any number of columns of any fixed-length data types. However, the first column should be an integer column with values from 1 through 4,000,000, inclusive.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;tab-stops:list 0in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;The sum of the all the column widths are between 1000 bytes plus or minus 20 (i.e. between 980 bytes and 1020 bytes). &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;tab-stops:list 0in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;No NULL is allowed for any column.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;tab-stops:list 0in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;No undocumented features are allowed in the script.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;tab-stops:list 0in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;When the test query is run, the test table must meet the following condition:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.9in;TEXT-INDENT:-0.25in;tab-stops:list .9in;"&gt;&lt;SPAN style="FONT-FAMILY:Wingdings;mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;§&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;The test table has 4,000,000 rows.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.9in;TEXT-INDENT:-0.25in;tab-stops:list .9in;"&gt;&lt;SPAN style="FONT-FAMILY:Wingdings;mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;§&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;The total size of data and index must be less than 7.5GB, as measured by sp_spaceused.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.9in;TEXT-INDENT:-0.25in;tab-stops:list .9in;"&gt;&lt;SPAN style="FONT-FAMILY:Wingdings;mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;§&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;Avg. page density is greater than 50% as reported by DBCC SHOWCONTIG().&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.2in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;The test query shown above must be run as is without any change.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoList3 style="MARGIN:0in 0in 0pt 0.2in;mso-list:none;tab-stops:.5in;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Why?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Well, it’ll reveal a lot of about how data is stored and how the simple test query is processed.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;If you would like to share your solution, and I hope you do, please post it here in the comment. Or if you want it better formatted, I can append it to the main text of this post.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=14209" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Disk+I_2F00_O/default.aspx">Disk I/O</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Query+Processing/default.aspx">Query Processing</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Storage/default.aspx">Storage</category></item><item><title>How does that AD user account get access to the database?</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/03/26/how-does-that-ad-user-account-get-access-to-the-database.aspx</link><pubDate>Thu, 26 Mar 2009 05:19:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:12927</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>8</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/12927.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=12927</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Granting Active Directory (AD) groups access to a database can quickly become complex when the AD groups&amp;nbsp;may nest many levels. Consider the following scenario: &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0.5in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;You are requested to give Joe the same access to a database as John has. You look up John in the database, and find no trace of John. You then find a bunch of AD groups have been granted access to the database. Obviously, John is getting his access to the database through one or more of these AD groups. But exactly how does John get his access via the AD groups? In other words, what are the AD groups through which John gets his database access?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;How would you approach this request? You can fire up the AD Users &amp;amp; Computers management console, look up the user account for John, find all the AD groups John is a member of, and then for each such group, recursively find all the groups this group is a member of. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Unfortunately, that is a labor intensive process.&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Times New Roman" size=3&gt;There is a better way. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;First, note that you can&amp;nbsp;use two AD utilities, DSquery and DSget, to recursively retrieve all the groups that John is a member of--either directly or indirectly--in a single line of command as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;FONT face="Times New Roman" size=3&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;cmd&amp;gt;dsquery user -samid John | dsget user -memberof -expand | findstr OU=Groups&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;In addition, you can run the following SQL query to find what AD groups have been granted access to the database:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;select s1.name &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;from syslogins s1 &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;join &amp;lt;your database&amp;gt;..sysusers s2 on s1.sid = s2.sid &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and s2.hasdbaccess = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;where s1.isntgroup = 1 and s1.hasaccess = 1 and s1.sysadmin = 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;order by s1.name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Now, if you compare these two&amp;nbsp;results of the AD groups, and the ones that are common in both&amp;nbsp;results are the AD groups through which John gains access to the database.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;So far, all this work is still manual and labor intensive. But it’s not difficult to automate all the steps in a script. The following is a throw-away Perl script I wrote to do precisely that:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE:11pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;use strict;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my ($user_account, $server, $database) = (shift, shift, shift);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my $domain = 'NYD';&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;# domain name hardcoded. Change it, if necessary&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @groups = `dsquery user -samid $user_account | dsget user -memberof -expand | findstr OU=Groups`;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @ADGroups;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;# Extract the AD group names and prefix them with the domain name&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;foreach my $group (@groups)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;if ($group =~ /\"CN=([^,]+)\,/)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@ADGroups = (@ADGroups, uc("$domain\\$1"));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my $sql = q/set nocount on;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;select s1.name &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;from syslogins s1 join $database..sysusers s2 &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;on s1.sid = s2.sid and s2.hasdbaccess = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;where s1.isntgroup = 1 and s1.hasaccess = 1 and s1.sysadmin = 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;order by s1.name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;/;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my $rc = `osql -S$server -E -n -h-1 -w200 -Q\"$sql\"`;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;$rc =~ s/^\s*//;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;$rc =~ s/\s*$//;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @login_nt_groups = split /\s*\n\s*/, $rc;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @LoginGroups;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;foreach my $nt_group (sort {uc($a) cmp uc($b)} @login_nt_groups)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@LoginGroups = (@LoginGroups, uc($nt_group));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;foreach my $group (getSetCommon([@ADGroups], [@LoginGroups]))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;print "** $group\n";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;sub getSetCommon {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;my($setRef1, $setRef2) = @_;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;my %temp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;my %common;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;grep($temp{$_}++, @$setRef2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;map {$temp{$_} and $common{$_}++} @$setRef1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;keys %common;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The script takes three command-line parameters: the name of the AD user account (e.g. John in our case), the SQL instance name, and the database name. It retrieves all the AD groups that the user account is in (directly or recursively), retrieves the AD groups that have been granted access to the database, and the find the AD groups that are in both.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This is a quick and dirty approach that seems to work well so far. If you have a better approach, please share with us. Powershell solutions are welcome&amp;nbsp;as well.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=12927" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Security/default.aspx">Security</category></item><item><title>Executing a large number of SQL scripts</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2008/12/04/executing-a-large-number-of-sql-scripts.aspx</link><pubDate>Fri, 05 Dec 2008 01:15:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:10280</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>18</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/10280.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=10280</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Say, you are given a large number of scripts underneath the following directory tree:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;N:\Apps\Release\PRS\PR12345\CMP1\procs&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;\views&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;\triggers&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;\CMP2\procs&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;\views&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;\scripts&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;You need to execute these scripts on a SQL Server instance. To simplify the matter a bit, let’s assume that these scripts can be executed in any order. How would you go about it?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Here’s how I would do it with the following trivial throw-away Perl script:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;# script file name: release.pl&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;$path = 'N:\Apps\Release\PRS\PR12345';&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;$server = 'SQLNYC01';&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;@scripts = `dir /B /s $path`;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;foreach $f (@scripts) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if ($f =~ /^(.+\.sql)\s*$/i) { &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;$osql = "sqlcmd.exe -S$server -E -w250 -i" . $f;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;print "$osql \n";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;#&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;$log = `$osql`;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#e0e0e0;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;I then run this little script and re-direct the result to a file:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;cmd&amp;gt;perl release.pl &amp;gt; PR12345.bat&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;PR12345.bat is the batch file that you can run to execute all the SQL scripts. Note that this Perl script assumes that all the SQL script files have the .sql file extension. That is just an example to show that you can easily filter out or filter for specific types of files, and construct the batch as you wish.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;You can also easily execute the SQL script files directly in the Perl script without using an intermediate batch file. The commented line in the script does precisely that (if uncommented).&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The assumption that the SQL scripts can be executed without any particular order can be easily removed with just a little bit of more coding as long as a way to identify the order is provided. For instance, a list of the script file names may be included in some release notes, and they must be executed in that order. It is quite easy to take that list, and help sort the SQL script files along with their complete paths so that they are listed correctly in the batch file.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=10280" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Automation/default.aspx">Automation</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Perl/default.aspx">Perl</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category></item><item><title>Microsoft 2008 Winter Scripting Games</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2008/02/19/microsoft-2008-winter-scripting-games.aspx</link><pubDate>Tue, 19 Feb 2008 16:40:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5139</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/5139.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=5139</wfw:commentRss><description>Microsoft is running its 3rd annual Winter Scripting Games. Three languages are allowed: VBScript, PowerShell, and Perl. The event sounds interesting. Check it out at:&lt;FONT size=2&gt; 
&lt;P&gt;&lt;/FONT&gt;&lt;A href="http://www.microsoft.com/technet/scriptcenter/funzone/games/default.mspx"&gt;&lt;U&gt;&lt;FONT color=#0000ff size=2&gt;http://www.microsoft.com/technet/scriptcenter/funzone/games/default.mspx&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I didn't know about&amp;nbsp;this event&amp;nbsp;until somebody emailed me this morning. You bet I'll be looking into it, if not for anything else but to find whether there are compelling reasons for PowerShell :-)&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5139" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category></item></channel></rss>