<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1434113132981005034</id><updated>2012-01-30T13:59:39.285-06:00</updated><category term='indexes'/><category term='logging'/><category term='sp_depends'/><category term='SPARSE'/><category term='undocumented changes'/><category term='sysadmin'/><category term='filegroup'/><category term='documentation'/><category term='Olga'/><category term='ssas'/><category term='bug'/><category term='profiler'/><category term='unsupported code'/><category term='temp tables'/><category term='printing'/><category term='SPs'/><category term='pound'/><category term='date'/><category term='xp_cmdshell'/><category term='SSMS'/><category term='t-sql'/><category term='partial'/><category term='restore'/><category term='borscht'/><category term='awk'/><category term='chocolate'/><category term='tips'/><category term='baking'/><category term='free space'/><category term='email'/><category term='xp'/><category term='Tiramisu'/><category term='reporting'/><category term='beets'/><category term='IO'/><category term='code page 65001'/><category term='undocumented fix'/><category term='puff-puffs'/><category term='sp_send_dbmail'/><category term='piecemeal'/><category term='lasagna'/><category term='links'/><category term='ssis'/><category term='pizza'/><category term='undocumented'/><category term='disk usage'/><category term='service pack'/><category term='sql 2005'/><category term='constraints'/><category term='I/O'/><category term='sweets'/><category term='database mail'/><category term='SQL 2000'/><category term='dessert'/><category term='foreign keys'/><category term='command-line'/><category term='sp3'/><category term='statistics'/><category term='notification'/><category term='archived'/><category term='error'/><category term='dependencies'/><category term='cooking'/><category term='setup'/><category term='PSA'/><category term='smtp'/><category term='wiki'/><category term='Powershell'/><category term='sourdough'/><category term='dirty data'/><category term='low-ascii'/><category term='Baba'/><category term='convoluted'/><category term='kill'/><category term='twit'/><category term='easy'/><category term='BCP'/><category term='compression'/><category term='Jam'/><category term='sql server 2008'/><category term='excel'/><category term='bread'/><category term='tuning'/><category term='code size'/><category term='Bake'/><category term='maintenance'/><category term='sp_msforeachdb'/><category term='code'/><category term='cake'/><category term='csv'/><category term='ddl triggers'/><category term='hack'/><category term='collation compatible'/><category term='soup'/><category term='partitioned tables'/><category term='linked servers'/><category term='convert'/><category term='latkes'/><category term='objects'/><category term='undocumented SP'/><category term='shell scripts'/><category term='Russian'/><category term='backups'/><category term='cruft'/><category term='audit'/><category term='indices'/><category term='sql server'/><category term='2005'/><category term='tip'/><category term='dumplings'/><category term='system tables'/><category term='cajun'/><category term='NoBake'/><category term='jobs'/><category term='BULK INSERT'/><category term='sql'/><category term='DMV'/><category term='unix'/><category term='gumbo'/><category term='administration'/><category term='history'/><category term='dates'/><category term='multiple machines'/><category term='publication'/><category term='DBCC'/><category term='fail'/><category term='information_schema'/><category term='switches'/><category term='litespeed'/><category term='sql 2008'/><category term='puff pastry'/><category term='pressure cooker'/><category term='replication'/><category term='openquery'/><title type='text'>The Baking DBA - select * from flour</title><subtitle type='html'>Put butter in your blender, add sugar, set on low.  Write a stored procedure to keep track of jobs that won't run.  Add flour.  Use a DMV to find unused indexes.  Add eggs.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default?start-index=101&amp;max-results=100'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>144</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4311502272450214804</id><published>2012-01-30T13:59:00.002-06:00</published><updated>2012-01-30T13:59:39.300-06:00</updated><title type='text'>[Table Partitioning] what is your lock escalation?</title><content type='html'>Bare bones query. &amp;nbsp;This will give you the lock escalation for your partitioned tables. &amp;nbsp;In our experience we've had good luck with AUTO (which is _not_ the default!), but the reason it's not the default is because some MS customers had deadlock issues with it enabled. &amp;nbsp;For us, it prevents issues with queries blocking inserts.&lt;br /&gt;&lt;br /&gt;Also, let me put a suggestion in your ear: don't go with just one table for inserts &amp;amp; queries. &amp;nbsp;Create a partitioned table to catch live data, keep a week's worth of data. &amp;nbsp;Create a mechanism to copy that into your history (what gets queried) table. &amp;nbsp;Make the history table AUTO, and experiment with your live table. &amp;nbsp;Compress the history. &amp;nbsp;Make a view between the two if you need. &amp;nbsp;Like much on this blog, let my pain be your gain.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT distinct tables.name,&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;lock_escalation_desc&lt;br /&gt;FROM sys.partitions&lt;br /&gt;inner join sys.tables&lt;br /&gt;on tables.object_id = partitions.object_id&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;and partition_number &amp;gt;1&lt;br /&gt;order by name&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4311502272450214804?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4311502272450214804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4311502272450214804' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4311502272450214804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4311502272450214804'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2012/01/table-partitioning-what-is-your-lock.html' title='[Table Partitioning] what is your lock escalation?'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6458759611830318967</id><published>2012-01-25T15:03:00.000-06:00</published><updated>2012-01-25T15:03:31.289-06:00</updated><title type='text'>[Code] Using EXECUTE AS with a trigger to capture changes when a user doesn't have permissions.</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal"&gt;Had to build this to keep track of changes on certain tables in our environment. &amp;nbsp;Due to limited permissions, we wound up with people hitting the table but the trigger not working right, because they hadn't been granted permissions. &amp;nbsp;So the obvious solution is to grant permissions to both tables to a group, then add people into that group. &amp;nbsp;Not an option for this particular scenario. &amp;nbsp;Hence, my code.&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;Note that THIS WILL NOT WORK across databases, unless it’smarked as TRUSTWORTHY.&amp;nbsp; Plannedfunctionality, not a bug.&amp;nbsp;Within a database it works.&amp;nbsp;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;New code bolded.&amp;nbsp; Icreated a user Change_User, a change-tracking table named change_mytable and gave Change_User select/insert permissions ONLY into change_mytable.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;ANSI_NULLS&lt;/span&gt; &lt;span style="color: blue;"&gt;ON&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;SET&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt; &lt;span style="color: blue;"&gt;QUOTED_IDENTIFIER&lt;/span&gt; &lt;span style="color: blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;alter&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt; &lt;span style="color: blue;"&gt;trigger&lt;/span&gt; [dbo]&lt;span style="color: grey;"&gt;.&lt;/span&gt;[mytrigger]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;on&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt; [dbo]&lt;span style="color: grey;"&gt;.&lt;/span&gt;[mytable]&lt;b&gt;&lt;span style="color: blue;"&gt;with&lt;/span&gt; &lt;span style="color: blue;"&gt;execute&lt;/span&gt; &lt;span style="color: blue;"&gt;as&lt;/span&gt; &lt;span style="color: red;"&gt;'change_user'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;after&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt; &lt;span style="color: blue;"&gt;update&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;as&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;SET&lt;/span&gt; &lt;span style="color: blue;"&gt;NOCOUNT&lt;/span&gt; &lt;span style="color: blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;declare&lt;/span&gt; @current_user &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;128&lt;span style="color: grey;"&gt;)&lt;/span&gt;&amp;nbsp; &lt;span style="color: green;"&gt;--suser_sname()is nvarchar(128)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;execute&lt;/span&gt; &lt;span style="color: blue;"&gt;as&lt;/span&gt; &lt;span style="color: blue;"&gt;caller&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: green;"&gt;--caller is the original person running code&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;set&lt;/span&gt; @current_user &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: magenta;"&gt;SUSER_SNAME&lt;/span&gt;&lt;span style="color: grey;"&gt;()&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: green;"&gt;--get the nameof the user&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp; &lt;span style="color: green;"&gt;--select @current_user&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--returnsmy name when I run it&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;revert&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;&lt;span style="color: green;"&gt;--go back to the EXECUTE AS user, ch_user&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp; &lt;span style="color: green;"&gt;--Audit capture&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; &lt;span style="color: grey;"&gt;exists&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;select&lt;/span&gt; name &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: green;"&gt;sysobjects&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'change_mytable'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;--print suser_sname()&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; --returnschange_user&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;insert&lt;/span&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; change_mytable&lt;span style="color: grey;"&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID&lt;span style="color: grey;"&gt;,&lt;/span&gt;&amp;nbsp;name&lt;span style="color: grey;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;updated_date&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;,&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;change_login&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;,&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; dml_action&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;SELECT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID&lt;span style="color: grey;"&gt;,&lt;/span&gt;NAME&lt;span style="color: grey;"&gt;,&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: magenta; font-family: 'Courier New'; font-size: 10pt;"&gt;getdate&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(),&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/span&gt;&lt;b style="font-family: 'Courier New'; font-size: 10pt;"&gt;@current_user&lt;/b&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;,&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;'Update'&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: 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 style="color: blue;"&gt;FROM&lt;/span&gt;Deleted &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;end&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;GO&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6458759611830318967?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6458759611830318967/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6458759611830318967' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6458759611830318967'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6458759611830318967'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2012/01/code-using-execute-as-with-trigger-to.html' title='[Code] Using EXECUTE AS with a trigger to capture changes when a user doesn&apos;t have permissions.'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3436248508343319502</id><published>2012-01-20T14:51:00.004-06:00</published><updated>2012-01-20T14:51:49.105-06:00</updated><title type='text'>Adding locations to SSMS "Open File"</title><content type='html'>Been looking like this for years. &amp;nbsp;Who knew, the right google and there it is. &amp;nbsp;I take no credit for this, simply sticking it in my blog so that I can find it next time.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.sqlservercentral.com/Forums/Topic907188-391-1.aspx"&gt;http://www.sqlservercentral.com/Forums/Topic907188-391-1.aspx&lt;/a&gt;&lt;br /&gt;Todd Engen&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" style="background-color: #f4f8fb; color: #1f5080; font-family: Verdana, Arial, Tahoma; font-size: 13px;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="smalltxt" style="color: #444444; font-family: Arial, sans-serif;" valign="top"&gt;&lt;span id="_ctl5_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl13_lblFullMessage"&gt;Here's where you'd find that for SSMS with 2005.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New';"&gt;\HKCU\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell\Open Find\Places\UserDefinedPlaces&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add subkeys Place0,Place1,Place(n)&lt;br /&gt;&lt;br /&gt;Under each subkey add two REG_SZ values&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New';"&gt;Name = "Shortcut Name"&lt;br /&gt;Path = "Folder location"&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3436248508343319502?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3436248508343319502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3436248508343319502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3436248508343319502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3436248508343319502'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2012/01/adding-locations-to-ssms-open-file.html' title='Adding locations to SSMS &quot;Open File&quot;'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2225245619269742650</id><published>2012-01-17T12:45:00.001-06:00</published><updated>2012-01-17T12:45:25.709-06:00</updated><title type='text'>[Network] Specified network name is no longer available</title><content type='html'>We've seen this in our environment for a while. &amp;nbsp;Tried moving backup times around, that helped some but not in every case. &amp;nbsp;TCP Chimney Offload didn't seem to be our issue either, though it has been for others.&lt;br /&gt;&lt;br /&gt;Got this nugget courtesy of kgerde, which seems to be a near-magic-bullet for us.&lt;br /&gt;&lt;a href="http://www.sqlservercentral.com/Forums/Topic768429-391-1.aspx"&gt;http://www.sqlservercentral.com/Forums/Topic768429-391-1.aspx&lt;/a&gt;&lt;br /&gt;&lt;span style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanworkstation\parameters&lt;/span&gt;&lt;br style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;" /&gt;&lt;span style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;"&gt;Create a New DWORD value with the name: SessTimeout&lt;/span&gt;&lt;br style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;" /&gt;&lt;span style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;"&gt;set the value: 360 keep it Hexadecimal&lt;/span&gt;&lt;br style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;" /&gt;&lt;span style="background-color: #f4f8fb; color: #444444; font-family: Arial, sans-serif; font-size: 13px;"&gt;(This value might not work for your backup but it was high enough for mine. If this doesn't work increase the value and try again.)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2225245619269742650?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2225245619269742650/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2225245619269742650' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2225245619269742650'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2225245619269742650'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2012/01/network-specified-network-name-is-no.html' title='[Network] Specified network name is no longer available'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3643377532176604374</id><published>2011-11-14T14:21:00.001-06:00</published><updated>2011-11-14T14:24:42.494-06:00</updated><title type='text'>Use RAISERROR to return results in SSMS immediately</title><content type='html'>This courtesy of a coworker (JS), who found the idea online somewhere, possibly from Savjani here (&lt;a href="http://blogs.msdn.com/b/sqlserverfaq/archive/2009/10/01/behavior-of-with-nowait-option-with-raiserror-in-sql-server.aspx"&gt;http://blogs.msdn.com/b/sqlserverfaq/archive/2009/10/01/behavior-of-with-nowait-option-with-raiserror-in-sql-server.aspx&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;If you run a while loop from SSMS, the results won't come back immediately, even if you're using a PRINT. &amp;nbsp;This is a clever way to return it immediately.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; @startdate &lt;span style="color: blue;"&gt;DATETIME&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @now &lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DATETIME&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;,&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@msg &lt;span style="color: blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;50&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; @now &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color: grey;"&gt;()&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; @startdate &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color: grey;"&gt;()-&lt;/span&gt; 60&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;WHILE &lt;/span&gt;&lt;span style="color: grey; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;@startdate&lt;span style="color: grey;"&gt;&amp;lt;=&lt;/span&gt; @now&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: x-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@msg &lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;select&lt;/span&gt; &lt;span style="color: magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;),&lt;/span&gt; @startdate&lt;span style="color: grey;"&gt;,&lt;/span&gt; 101&lt;span style="color: grey;"&gt;))&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: x-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;RAISERROR &lt;/span&gt;&lt;span style="color: grey; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;@msg&lt;span style="color: grey;"&gt;,&lt;/span&gt; 0&lt;span style="color: grey;"&gt;,&lt;/span&gt; 1&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;WITH&lt;/span&gt; &lt;span style="color: blue;"&gt;NOWAIT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: x-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; @startdate &lt;span style="color: grey;"&gt;=&lt;/span&gt;@startdate &lt;span style="color: grey;"&gt;+&lt;/span&gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;END&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3643377532176604374?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3643377532176604374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3643377532176604374' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3643377532176604374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3643377532176604374'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/11/use-raiserror-to-return-results-in-ssms.html' title='Use RAISERROR to return results in SSMS immediately'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2935353156955286843</id><published>2011-09-27T15:23:00.004-05:00</published><updated>2012-01-20T14:52:38.428-06:00</updated><title type='text'>Using OUTPUT to set up foreign keys' data</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-size: 12pt;"&gt;So, I was looking at a process that inserts records into table A (one at a time), then uses SCOPE_IDENTITY() from each insert to get the ID and uses that for the insert into table B, in order to provide a cross-reference tabled (foreign key). &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;Obviously, there's a better way -&amp;nbsp;&lt;span class="Apple-style-span" style="font-size: 16px;"&gt;OUTPUT,usable since SQL Server 2005.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-size: 12pt;"&gt;An example.&amp;nbsp; We populate“blah”, then use the values from that to insert into “blah2”, with a foreignkey ID of the first table. &amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; blah&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;id &lt;span style="color: blue;"&gt;INT&lt;/span&gt; &lt;span style="color: blue;"&gt;IDENTITY&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; logon_name &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;50&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; blah2&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;id &lt;span style="color: blue;"&gt;INT&lt;/span&gt; &lt;span style="color: blue;"&gt;IDENTITY&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; blahID &lt;span style="color: blue;"&gt;int&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; dn &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;200&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; blah &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;SELECT&lt;/span&gt; &lt;span style="color: blue;"&gt;TOP&lt;/span&gt; 10name&amp;nbsp;&lt;span style="color: blue;"&gt;FROM&lt;/span&gt;&amp;nbsp;sysusers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; blah &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;SELECT&lt;/span&gt; &lt;span style="color: blue;"&gt;TOP&lt;/span&gt; 10name&amp;nbsp;&lt;span style="color: blue;"&gt;FROM&lt;/span&gt;&amp;nbsp;sysusers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DELETE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; blah&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;--incrementing to show different ID values.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @insertedlist &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;id &lt;span style="color: blue;"&gt;int&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; the_logonname &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;50&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; blah &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;output&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; inserted&lt;span style="color: grey;"&gt;.&lt;/span&gt;id&lt;span style="color: grey;"&gt;,&lt;/span&gt; inserted&lt;span style="color: grey;"&gt;.&lt;/span&gt;logon_name&lt;span style="color: blue;"&gt;INTO&lt;/span&gt; @insertedlist &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TOP&lt;/span&gt; 10 name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;FROM&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;sysusers&amp;nbsp;&lt;span style="color: blue;"&gt;ORDER&lt;/span&gt; &lt;span style="color: blue;"&gt;BY&lt;/span&gt; createdate&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; blah2&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;blahid&lt;span style="color: grey;"&gt;,&lt;/span&gt; dn&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; insertedlist&lt;span style="color: grey;"&gt;.&lt;/span&gt;id&lt;span style="color: grey;"&gt;,&lt;/span&gt; sysusers&lt;span style="color: grey;"&gt;.&lt;/span&gt;uid&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;FROM&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @insertedlist insertedlist &lt;span style="color: grey;"&gt;INNER&lt;/span&gt;&lt;span style="color: grey;"&gt;JOIN&lt;/span&gt;&amp;nbsp;sysusers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;ON&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; insertedlist&lt;span style="color: grey;"&gt;.&lt;/span&gt;the_logonname&lt;span style="color: grey;"&gt;=&lt;/span&gt; sysusers&lt;span style="color: grey;"&gt;.&lt;/span&gt;name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; blah&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; blah2&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2935353156955286843?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2935353156955286843/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2935353156955286843' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2935353156955286843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2935353156955286843'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/09/so-i-was-looking-at-process-that.html' title='Using OUTPUT to set up foreign keys&apos; data'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-1837690632547635994</id><published>2011-09-08T16:44:00.002-05:00</published><updated>2011-09-08T16:46:45.654-05:00</updated><title type='text'>[Free Space] finding what filegroups your data is saved onto.</title><content type='html'>&lt;div&gt;Using this to tell me where my indexes are, but more importantly - where my data is.  What filegroup/file.  It produces multiple rows when there are multiple files for a filegroup; need to code a better way.  Note that all the WHERE clauses are optional; we couldn't figure out where our data was until we dropped them.  10 gig in a heap table, and 20gb in a service broker table.&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;SELECT&lt;/div&gt;&lt;div&gt;        o.name AS Table_Name ,&lt;/div&gt;&lt;div&gt;        i.NAME AS Index_Name ,&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;CASE i.type&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;WHEN 0 THEN 'Heap'&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;WHEN 1 THEN 'C'&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;WHEN 2 THEN 'NC'&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;ELSE '?' END AS [Type],&lt;/div&gt;&lt;div&gt;        p.rows AS [#Records] ,&lt;/div&gt;&lt;div&gt;        a.total_pages * 8 / 1024 AS [Reserved(mb)] ,&lt;/div&gt;&lt;div&gt;        a.used_pages * 8 / 1024 AS [Used(mb)] ,&lt;/div&gt;&lt;div&gt;        s.user_seeks ,&lt;/div&gt;&lt;div&gt;        s.user_scans ,&lt;/div&gt;&lt;div&gt;        s.user_lookups,&lt;/div&gt;&lt;div&gt;        fg.name, &lt;/div&gt;&lt;div&gt;        f.name,&lt;/div&gt;&lt;div&gt;        f.physical_name&lt;/div&gt;&lt;div&gt;FROM    sys.indexes AS i&lt;/div&gt;&lt;div&gt;        INNER JOIN sys.partitions AS p ON i.object_id = p.object_id&lt;/div&gt;&lt;div&gt;                                          AND i.index_id = p.index_id&lt;/div&gt;&lt;div&gt;        INNER JOIN SYS.OBJECTS O ON I.OBJECT_ID = O.OBJECT_ID&lt;/div&gt;&lt;div&gt;        INNER JOIN sys.allocation_units AS a ON ( a.type = 2&lt;/div&gt;&lt;div&gt;                                                  AND p.partition_id = a.container_id&lt;/div&gt;&lt;div&gt;                                                )&lt;/div&gt;&lt;div&gt;                                                OR ( ( a.type = 1&lt;/div&gt;&lt;div&gt;                                                       OR a.type = 3&lt;/div&gt;&lt;div&gt;                                                     )&lt;/div&gt;&lt;div&gt;                                                     AND p.hobt_id = a.container_id&lt;/div&gt;&lt;div&gt;                                                   )&lt;/div&gt;&lt;div&gt;        INNER JOIN SYS.DM_DB_INDEX_USAGE_STATS S ON S.OBJECT_ID = I.OBJECT_ID&lt;/div&gt;&lt;div&gt;                                                    AND I.INDEX_ID = S.INDEX_ID&lt;/div&gt;&lt;div&gt;                                                    AND DATABASE_ID = DB_ID(DB_NAME())&lt;/div&gt;&lt;div&gt;                                                    AND o.type_desc NOT IN ( 'SYSTEM_TABLE', 'INTERNAL_TABLE' )           -- No system tables!&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;LEFT OUTER JOIN sys.database_files f ON f.data_space_id = a.data_space_id&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;LEFT OUTER JOIN sys.filegroups fg ON fg.data_space_id = a.data_space_id&lt;/div&gt;&lt;div&gt;--AND (ISNULL(s.user_seeks, 0) + ISNULL(s.user_scans, 0) + ISNULL(s.user_lookups, 0)) &amp;lt; 100&lt;/div&gt;&lt;div&gt;WHERE   OBJECTPROPERTY(O.OBJECT_ID, 'IsUserTable') = 1&lt;/div&gt;&lt;div&gt;        --AND i.TYPE_DESC &amp;lt;&amp;gt; 'HEAP'&lt;/div&gt;&lt;div&gt;        AND i.type &amp;lt;&amp;gt; 1 -- clustered index&lt;/div&gt;&lt;div&gt;ORDER BY o.NAME ,&lt;/div&gt;&lt;div&gt;        i.name&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-1837690632547635994?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/1837690632547635994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=1837690632547635994' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1837690632547635994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1837690632547635994'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/09/free-space-finding-what-filegroups-your.html' title='[Free Space] finding what filegroups your data is saved onto.'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-202517604359236147</id><published>2011-09-01T14:01:00.006-05:00</published><updated>2011-09-29T16:03:35.699-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tuning'/><category scheme='http://www.blogger.com/atom/ns#' term='indexes'/><category scheme='http://www.blogger.com/atom/ns#' term='free space'/><title type='text'>[Index] Size, usage, and location of your indexes</title><content type='html'>Updated my old code, since we were trying to figure out what indexes needed to get moved to the secondary (index) filegroup.  You can even filter based off the usage (commented out below)&lt;br /&gt;Standard disclaimer applies.  Select the contents of the post, then copy/paste.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;SELECT&lt;br /&gt;        o.name AS Table_Name ,&lt;br /&gt;        i.NAME AS Index_Name ,&lt;br /&gt;--        i.type_desc,&lt;br /&gt;		CASE i.type&lt;br /&gt;			WHEN 0 THEN 'Heap'&lt;br /&gt;			WHEN 1 THEN 'C'&lt;br /&gt;			WHEN 2 THEN 'NC'&lt;br /&gt;			ELSE '?' END AS [Type],&lt;br /&gt;        p.rows AS [#Records] ,&lt;br /&gt;        a.total_pages * 8 / 1024 AS [Reserved(mb)] ,&lt;br /&gt;        a.used_pages * 8 / 1024 AS [Used(mb)] ,&lt;br /&gt;        s.user_seeks ,&lt;br /&gt;        s.user_scans ,&lt;br /&gt;        s.user_lookups,&lt;br /&gt;        fg.name, &lt;br /&gt;        f.name,&lt;br /&gt;        f.physical_name&lt;br /&gt;FROM    sys.indexes AS i&lt;br /&gt;        INNER JOIN sys.partitions AS p &lt;br /&gt;			ON i.object_id = p.object_id&lt;br /&gt;            AND i.index_id = p.index_id&lt;br /&gt;        INNER JOIN SYS.OBJECTS O &lt;br /&gt;			ON I.OBJECT_ID = O.OBJECT_ID&lt;br /&gt;        INNER JOIN sys.allocation_units AS a &lt;br /&gt;			ON ( a.type = 2&lt;br /&gt;				AND p.partition_id = a.container_id&lt;br /&gt;               )&lt;br /&gt;			OR &lt;br /&gt;				( ( a.type = 1 OR a.type = 3)&lt;br /&gt;				AND p.hobt_id = a.container_id)&lt;br /&gt;        INNER JOIN SYS.DM_DB_INDEX_USAGE_STATS S &lt;br /&gt;			ON S.OBJECT_ID = I.OBJECT_ID&lt;br /&gt;			AND I.INDEX_ID = S.INDEX_ID&lt;br /&gt;			AND DATABASE_ID = DB_ID(DB_NAME())&lt;br /&gt;			AND o.type_desc NOT IN ( 'SYSTEM_TABLE', 'INTERNAL_TABLE' ) -- No system tables!&lt;br /&gt;		LEFT OUTER JOIN sys.database_files f &lt;br /&gt;			ON f.data_space_id = a.data_space_id&lt;br /&gt;		LEFT OUTER JOIN sys.filegroups fg &lt;br /&gt;			ON fg.data_space_id = a.data_space_id&lt;br /&gt;--AND (ISNULL(s.user_seeks, 0) + ISNULL(s.user_scans, 0) + ISNULL(s.user_lookups, 0)) &amp;lt; 100&lt;br /&gt;WHERE   OBJECTPROPERTY(O.OBJECT_ID, 'IsUserTable') = 1&lt;br /&gt;        AND i.TYPE_DESC &amp;lt;&amp;gt; 'HEAP'&lt;br /&gt;        AND i.type &amp;lt;&amp;gt; 1 -- clustered index&lt;br /&gt;ORDER BY o.NAME ,&lt;br /&gt;        i.name&lt;br /&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-202517604359236147?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/202517604359236147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=202517604359236147' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/202517604359236147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/202517604359236147'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/09/index-size-usage-and-location-of-your.html' title='[Index] Size, usage, and location of your indexes'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7026894785383648790</id><published>2011-08-16T14:41:00.002-05:00</published><updated>2011-08-16T14:43:55.378-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='t-sql'/><category scheme='http://www.blogger.com/atom/ns#' term='ssis'/><category scheme='http://www.blogger.com/atom/ns#' term='code page 65001'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><title type='text'>[ETL] Importing UNIX files</title><content type='html'>Coworker had a problem importing a data file - one column per line, but was running into problems and had to invoke Code Page 65001 in his SSIS script.  Took forever to fix, and forever to process.  Looked at the file - UNIX.  &lt;br /&gt;&lt;br /&gt;So, the easy T-SQL way to do it:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE TABLE deleteme (resultant VARCHAR(MAX))&lt;br /&gt;&lt;br /&gt;BULK INSERT deleteme&lt;br /&gt;   FROM '\\server\path\file.rpt'&lt;br /&gt;   WITH &lt;br /&gt;      (&lt;br /&gt;         ROWTERMINATOR = '0x0a'&lt;br /&gt;      )&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7026894785383648790?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7026894785383648790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7026894785383648790' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7026894785383648790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7026894785383648790'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/08/etl-importing-unix-files.html' title='[ETL] Importing UNIX files'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8112196933805773021</id><published>2011-08-15T09:07:00.003-05:00</published><updated>2011-08-15T09:17:29.686-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tuning'/><category scheme='http://www.blogger.com/atom/ns#' term='disk usage'/><category scheme='http://www.blogger.com/atom/ns#' term='DMV'/><title type='text'>[Tuning] Disk usage over time, checking deltas</title><content type='html'>Not sure where this came from, if I wrote it or someone else did.  Practically, it looks before and after to tell you which files are getting used.  The commented out bit was because I was investigating WRITELOG delays.  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;--as always, drag-copy to get the full text.&lt;br /&gt;DECLARE @compare TABLE (NAME sysname, type_desc varchar(10), physical_name VARCHAR(200), sample_ms BIGINT, &lt;br /&gt;num_of_bytes_written BIGINT, num_of_bytes_read BIGINT, size_in_gb INT)&lt;br /&gt;DECLARE @compare2 TABLE (NAME sysname, type_desc varchar(10), physical_name VARCHAR(200), sample_ms BIGINT, &lt;br /&gt;num_of_bytes_written BIGINT, num_of_bytes_read BIGINT, size_in_gb INT)&lt;br /&gt;&lt;br /&gt;INSERT INTO @compare &lt;br /&gt;SELECT &lt;br /&gt;  master_files.NAME, &lt;br /&gt;  master_files.type_desc,&lt;br /&gt;  master_files.physical_name, &lt;br /&gt;  vfs.sample_ms,&lt;br /&gt;  vfs.num_of_bytes_written, &lt;br /&gt;  num_of_bytes_read, &lt;br /&gt;  size_on_disk_bytes/1024/1024/1024 AS Size_in_GB&lt;br /&gt;FROM sys.dm_io_virtual_file_stats(null, null) vfs&lt;br /&gt;INNER JOIN MASTER.sys.master_files &lt;br /&gt; ON vfs.[file_id] = master_files.[file_id] &lt;br /&gt; AND vfs.database_id = master_files.database_id&lt;br /&gt; --WHERE type_desc = 'log'&lt;br /&gt;ORDER BY (num_of_bytes_read + num_of_bytes_written) DESC&lt;br /&gt;&lt;br /&gt;WAITFOR DELAY '00:00:15'&lt;br /&gt;&lt;br /&gt;INSERT INTO @compare2&lt;br /&gt;SELECT &lt;br /&gt;  master_files.NAME, &lt;br /&gt;  master_files.type_desc,&lt;br /&gt;  master_files.physical_name, &lt;br /&gt;  vfs.sample_ms,&lt;br /&gt;  vfs.num_of_bytes_written, &lt;br /&gt;  num_of_bytes_read, &lt;br /&gt;  size_on_disk_bytes/1024/1024/1024 AS Size_in_GB&lt;br /&gt;FROM sys.dm_io_virtual_file_stats(null, null) vfs&lt;br /&gt;INNER JOIN MASTER.sys.master_files &lt;br /&gt; ON vfs.[file_id] = master_files.[file_id] &lt;br /&gt; AND vfs.database_id = master_files.database_id&lt;br /&gt;-- WHERE type_desc = 'log'&lt;br /&gt;ORDER BY (num_of_bytes_read + num_of_bytes_written) DESC&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT old.NAME, old.physical_name, new.sample_ms - old.sample_ms AS time_elapsed,&lt;br /&gt;new.num_of_bytes_written - old.num_of_bytes_written AS delta_num_bytes_written,&lt;br /&gt;new.num_of_bytes_read - old.num_of_bytes_read AS delta_num_bytes_read, old.size_in_gb&lt;br /&gt;FROM @compare old INNER JOIN @compare2 new ON old.physical_name = new.physical_name&lt;br /&gt;ORDER BY (new.num_of_bytes_written - old.num_of_bytes_written) DESC&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8112196933805773021?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8112196933805773021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8112196933805773021' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8112196933805773021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8112196933805773021'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/08/tuning-disk-usage-over-time-checking.html' title='[Tuning] Disk usage over time, checking deltas'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7263995268575472646</id><published>2011-08-05T09:43:00.003-05:00</published><updated>2011-08-05T09:44:34.156-05:00</updated><title type='text'>[Trick] get midnight fast</title><content type='html'>I've used this in the past, but technically it's sloppy.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select convert(char(8),getdate(),112)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So these days I'm using this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)  &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7263995268575472646?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7263995268575472646/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7263995268575472646' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7263995268575472646'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7263995268575472646'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/08/trick-get-midnight-fast.html' title='[Trick] get midnight fast'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7515443680804299269</id><published>2011-07-31T00:16:00.004-05:00</published><updated>2011-07-31T01:23:26.860-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Olga'/><category scheme='http://www.blogger.com/atom/ns#' term='Baba'/><category scheme='http://www.blogger.com/atom/ns#' term='Russian'/><title type='text'>[Russian] Meat Perushky / Perushki / Piroshki / Piroshki</title><content type='html'>The classic Russian meat pie.  Note similarities with Potato Perushki (she spells them piroshky), but definitely not the same recipes.  This will take 3-4 hours total, but with some pauses.  This version is meat, baked.  You can fry them but they are very greasy.  The potato variant excels when fried, so bake this and fry that.&lt;br /&gt;&lt;br /&gt;Dough: &lt;br /&gt;First, combine:&lt;br /&gt;2 pk dry yeast (Active Dry is fine, Rapid Rise is not)&lt;br /&gt;1.5-2.0 cups milk, at 95-100 degrees (too hot is BAD, you want roughly blood-temp)&lt;br /&gt;1 tbl sugar&lt;br /&gt;1 tbl flour&lt;br /&gt;3/4 stick of butter or 1.5 stick margarine, room temp or melted.&lt;br /&gt;Let sit 10-15 minutes, until bubbly or foamy or otherwise alive.&lt;br /&gt;&lt;br /&gt;Beat together:&lt;br /&gt;2 whole eggs&lt;br /&gt;1 egg yolk (save the white for the egg wash)&lt;br /&gt;1.5 - 2.0 teaspoon salt (sorry, last time I made it it was flat, and that was either 1 or 1.5 tsp salt)&lt;br /&gt;&lt;br /&gt;Sift 2 lb flour.&lt;br /&gt;&lt;br /&gt;Mix yeast mixture, eggs, and 1 lb 13 oz of flour in mixer.  Use the bread hook, low speed.  Once it all comes together, add flour until slightly sticky (I used 1 cup).&lt;br /&gt;&lt;br /&gt;Let rise until doubled.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Meat:&lt;br /&gt;Cut a 2-3 lb chuck roast into several hunks, trimming fat.  Cover with water.  Bring to boil then turn down to simmer for 60-90 minutes (this is to tenderize and break down).  The time depends on the quality of the meat - better takes less time.  To tell if done, poke with a knife: should fall off knife easily.&lt;br /&gt;&lt;br /&gt;Once done, we grind it.  On my kitchenaid stand mixer, I use the small grinding wheel, set the mixer on 3, and grind.  Note that you can't just buy ground meat and cook it - the texture is totally different.&lt;br /&gt;&lt;br /&gt;Onions: &lt;br /&gt;Dice 2-3 medium onions.  Simmer in 2-3 tbl oil. On our electric stove we cook on 5-6 (out of 10),  covereed, then turn down to 3.5 - 4.0.  Stir occasionally - you're trying to clarify and brown.  Cook about 60 minutes.&lt;br /&gt;&lt;br /&gt;Now, combine the meat and onions.  Add 1-2 tsp salt (very little), 1-2 tsp black pepper, and 1/2 cup (varies) of the broth from the meat.  You want it to stick together a bit - when you scoop it you want it to clump.  &lt;br /&gt;&lt;br /&gt;Making the perushky:&lt;br /&gt;For each perushky, pull off 24-26 grams of dough.  &lt;br /&gt;Two ways to make:&lt;br /&gt;1) stretch out by hand&lt;br /&gt;2) roll and cut&lt;br /&gt;My grandmother stretches it out to a 3.25" circle, thinner at the edges.  This is a little heavy on the bread for my taste, so I roll out with a rolling pin until about 3.5 - 4.0 inches around, then use the top of a 3.25" restaurant tumbler (do a Google image search - about 2.75 inches at the bottom and straight sides) to cut out a circle.  When I weight it, it comes out to about 18g.&lt;br /&gt;&lt;br /&gt;Now take this circle of dough, stretch it out a little, and immediately drop in a dollop of meat.  I use a #70 disher - Baba uses a heaping tablespoon.  Put this in the middle, then bring the sides together, forming a half-circle.  Pinch down repeatedly to seal, squeezing hard with your fingers.  Now flatten - put perpendicular to table, round side facing down, and push.  It'll wind up as a small round object.  Check for seam splits and close them.&lt;br /&gt;&lt;br /&gt;Now do this about 100 times (takes about an hour).  I wound up with extra meat &amp; onion - add rice to this and you've got the filling for cabbage rolls (see recipe on this blog).  &lt;br /&gt;&lt;br /&gt;Now take the egg white you saved, whisk for 10-20 seconds with a fork.  Using a brush, put this egg wash on the top - enhances browning.  Bake at 350 for 20-25 minutes.  Let cool and enjoy!&lt;br /&gt;&lt;br /&gt;Since I didn't have enough baking trays, I made a tray, put on egg wash (see below), put in the oven, and started the next tray.  Overall it took about an hour to make them.  Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7515443680804299269?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7515443680804299269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7515443680804299269' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7515443680804299269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7515443680804299269'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/07/russian-meat-perushky-perushki-piroshki.html' title='[Russian] Meat Perushky / Perushki / Piroshki / Piroshki'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3517092706732239149</id><published>2011-07-30T23:56:00.002-05:00</published><updated>2011-07-31T00:12:38.054-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Olga'/><category scheme='http://www.blogger.com/atom/ns#' term='Baba'/><category scheme='http://www.blogger.com/atom/ns#' term='Russian'/><title type='text'>[Russian] Olga's Pork Stew</title><content type='html'>(yes, there's a lot of commentary in this recipe.  You've never made this before, so you don't know how long or why things are done a certain way).&lt;br /&gt;&lt;br /&gt;2 lb boneless country-style pork ribs&lt;br /&gt;5-6 medium russet potatoes&lt;br /&gt;1 large onion&lt;br /&gt;2 medium carrots (can use baby carrots, though they take longer to cook than sliced carrots)&lt;br /&gt;2-3 cups frozen/fresh green beans, cut or frenched.  Or, one 1 can cut green beans&lt;br /&gt;1-2 cups water&lt;br /&gt;&lt;br /&gt;First, chop onion and simmer with 2-3 tablespoons butter.  Let simmer until golden brown or mahogany.  On my electric stove we put it on a 5 (out of 10) on a small burner and stir frequently.  You're not trying to burn or blacken them.  Let this cook while you prep everything else.  Once brown turn off, though this usually happens about the time we're ready for them below.  &lt;br /&gt;&lt;br /&gt;Cut the meat into bite sized pieces, removing the big hunks of fat.&lt;br /&gt;&lt;br /&gt;Fry the meat in a regular size pot (under 8 quarts) with 1 tablespoon oil, until light brown.  You want color and browning to add flavor.  We cook this on a 4-5 on the stove.&lt;br /&gt;&lt;br /&gt;Add water so that the meat is just barely covered (let it at least hit the halfway point on the meat, better if it's just covered) and let simmer 30 minutes.  If you're losing too much water, add some more - you're using the simmering to break down and tenderize the meat, as well as to put out flavor that'll go into the veggies.&lt;br /&gt;&lt;br /&gt;While it's simmering, peel potatoes and cut into cubes (on a good-sized russet I usually quarter and slice about .5 inches thick).  Peel &amp; slice the carrots.  Thaw the green beans.&lt;br /&gt;&lt;br /&gt;After the 30 minutes, add the potatoes, onions, carrots, and fresh/frozen beans (if from a can, add when the potatoes have finished).  Simmer and stir occasionally - the potatoes will break down, that's fine.&lt;br /&gt;&lt;br /&gt;Once the potatoes are cooked, stir in 1 8-oz can of tomato sauce.  At this point, cook 10-20 minutes further, stirring every 2-3 minutes.  The potatoes will break down, and that's fine - that's our thickener that turns this into a stew.&lt;br /&gt;&lt;br /&gt;After the 10-20 minutes, see if all the vegetables are cooked.  Once they are, serve.  If&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3517092706732239149?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3517092706732239149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3517092706732239149' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3517092706732239149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3517092706732239149'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/07/russian-olgas-pork-stew.html' title='[Russian] Olga&apos;s Pork Stew'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7618232046267253243</id><published>2011-07-30T23:30:00.005-05:00</published><updated>2011-07-30T23:55:37.953-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cajun'/><category scheme='http://www.blogger.com/atom/ns#' term='gumbo'/><title type='text'>[Cooking] Gumbo! Mama Saucier's Super Gumbo</title><content type='html'>My wife's family's recipe.  And it's pronounced Sew-shay (sew as in needle and thread).&lt;br /&gt;&lt;br /&gt;Yes, not baking.  That's coming after this one.&lt;br /&gt;&lt;br /&gt;Mama Saucier's Super Gumbo&lt;br /&gt;Bring 8 boneless, skinless chicken breasts to a boil in a fair-sized (8-quart, fill halfway with water) pot.  When done set aside.&lt;br /&gt;&lt;br /&gt;Mix in a bowl:&lt;br /&gt;1 Cup of Tony Chachere's Instant Roux Mix&lt;br /&gt;2 Cans room temperature chicken broth (not from the above pot, just normal size cans of low-sodium chicken broth)&lt;br /&gt;&lt;br /&gt;In a Very Large Stock Pot (3-4 gallons+)&lt;br /&gt;Melt 2 sticks of butter&lt;br /&gt;Saute:&lt;br /&gt;1 "head" (stalk bunch) of Celery, sliced, just the main green part of the stalk.  If you don't like the taste of celery, slice fine.&lt;br /&gt;1.5 large yellow/1015 onions (diced)&lt;br /&gt;2 Green Bell Pepper (diced)&lt;br /&gt;3-4 minced garlic pods (aka toes or cloves - not the entire head!), can use from jar.&lt;br /&gt;&lt;br /&gt;Once sauteed to softened, add &amp; stir in:&lt;br /&gt;Roux&lt;br /&gt;Chicken broth from boiled chicken&lt;br /&gt;3 cans of cut up/diced/mashed tomatoes (regular 14oz cans)&lt;br /&gt;&lt;br /&gt;Bring to a boil then add:&lt;br /&gt;Chicken breasts (don't bother cutting up)&lt;br /&gt;1 tblsp Tony Chachere's Cajun Seasoning (add more if needed in 20-30 minutes.  If too spicy-hot, add more canned tomatoes or tomato juice)&lt;br /&gt;3 16-oz packages of frozen cut okra (3 pounds total, yes)&lt;br /&gt;&lt;br /&gt;Let slowly simmer 3-4 hours (note below instructions).  Stir constantly.  &lt;br /&gt;After the first 2 hours, add:&lt;br /&gt;4-5 lbs smoked tube beef (sausage) or pork sausage cut into bite-sized pieces.  These WILL swell, so slice more thinly than you would if panfrying or whatnot - maybe .25 inches, no more than .5 inches thick.&lt;br /&gt;&lt;br /&gt;If things stick to the bottom, LEAVE THEM.  It's burned by the time you notice and scraping them off the bottom will just ruin the gumbo - it'll be a burned-tasting mess.  So leave it and you're fine (well, until cleanup).&lt;br /&gt;&lt;br /&gt;10 minutes before serving (about the time to put the bread in the oven) bring to a boil (stir constantly at this point!) and put in 3 lbs shrimp.  Turn down to slow boil, since you can easily scorch the entire pot at this point.&lt;br /&gt;&lt;br /&gt;Serve over rice.  &lt;br /&gt;&lt;br /&gt;Note that if you want recognizable meat or veggies, add additional amounts along with the shrimp.  Overall, the chicken will turn into little white strings, the veggies dissolve - basically, the only recognizable bits in the gumbo will be the sausage and shrimp, and if you added the sausage at the beginning, that's dissolved, too.&lt;br /&gt;&lt;br /&gt;Any questions?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7618232046267253243?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7618232046267253243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7618232046267253243' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7618232046267253243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7618232046267253243'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/07/cooking-gumbo-mama-sauciers-super-gumbo.html' title='[Cooking] Gumbo! Mama Saucier&apos;s Super Gumbo'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3811846769944565478</id><published>2011-06-23T10:52:00.002-05:00</published><updated>2011-06-23T11:03:17.031-05:00</updated><title type='text'>[BCP] When native isn't exactly what you put in</title><content type='html'>An oddity I wanted to mention:&lt;br /&gt;&lt;br /&gt;I BCPd out the contents of a table using QUERYOUT, in NATIVE format (/n).&lt;br /&gt;I then proceeded to import the file into an identical table using &lt;br /&gt;     BULK INSERT WITH ( DATAFILETYPE = 'native', KEEPIDENTITY )&lt;br /&gt;and used SQL Data Compare (plug!) to compare the two tables.&lt;br /&gt;&lt;br /&gt;To my surprise, out of 1.5m rows, 21 were different.  In this case, instead of a dash (0x2D), I wound up with what looks like a dash but isn't (0x96).&lt;br /&gt;&lt;br /&gt;If anybody's heard of this, please chime in.  Both were varchar(40), though the source was 2008 and the target was 2005.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3811846769944565478?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3811846769944565478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3811846769944565478' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3811846769944565478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3811846769944565478'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/06/bcp-when-native-isnt-exactly-what-you.html' title='[BCP] When native isn&apos;t exactly what you put in'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2605110100342721489</id><published>2011-05-31T15:50:00.002-05:00</published><updated>2011-05-31T15:58:25.846-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PSA'/><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><title type='text'>[Replication] PSA - when flipping IPs, STOP THE JOBS</title><content type='html'>After just going through a fire drill, let me add this handy piece of information.&lt;br /&gt;&lt;br /&gt;IF YOU ARE CHANGING THE IP ADDRESS OF A SUBSCRIBER, FOR THE LOVE OF GOD STOP THE REPLICATION JOBS TO IT FIRST.&lt;br /&gt;&lt;br /&gt;In our case, the agent (due to the magic of laggy DNS) managed to insert records before the proper subscription could - thereby forcing us to go through sp_browsereplcmds and find the new records, then delete them. &lt;br /&gt;&lt;br /&gt;You live, you learn.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2605110100342721489?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2605110100342721489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2605110100342721489' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2605110100342721489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2605110100342721489'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/05/replication-psa-when-flipping-ips-stop.html' title='[Replication] PSA - when flipping IPs, STOP THE JOBS'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5462804815088787435</id><published>2011-05-26T16:34:00.004-05:00</published><updated>2011-05-26T16:50:59.332-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='excel'/><category scheme='http://www.blogger.com/atom/ns#' term='hack'/><category scheme='http://www.blogger.com/atom/ns#' term='convert'/><title type='text'>[Excel] Converting float and dealing with leading zeros</title><content type='html'>So, for the Nth time I've received an Excel file that has a field which should have leading zeros.  And instead, I've received a file that uses the PESEL (Polish Social Security Number) formatting to make it LOOK like the data is correct.  Which SQL Server promptly ignores.  So you can fix the Excel column ( =text(B1,"00000000000")&lt;br /&gt;&lt;br /&gt;If you try a straight up conversion, it fails.&lt;br /&gt;Example:&lt;br /&gt;Should be   00123456789&lt;br /&gt;Looks like  00123456789&lt;br /&gt;Actually is 123456789&lt;br /&gt;"select convert(varchar,crap_field) from your_table" yields: 1.23456e+009&lt;br /&gt;ALTER TABLE fails because the value is too large (numeric overflow).&lt;br /&gt;&lt;br /&gt;Fix: double convert, then add leading zeros.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select convert(decimal(11,0),crap_field) from your_table --getting there&lt;br /&gt;select convert(varchar(11),convert(decimal(11,0),crap_field)) --now it's a varchar&lt;br /&gt;select right('00000000000' + --11 zeros&lt;br /&gt;  convert(varchar(11),convert(decimal(11,0),crap_field))&lt;br /&gt;  , 11) --add leading zeros. Done!&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note the table is the same, and you can't just UPDATE the table - the format is still wrong.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5462804815088787435?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5462804815088787435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5462804815088787435' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5462804815088787435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5462804815088787435'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/05/excel-converting-float-and-dealing-with.html' title='[Excel] Converting float and dealing with leading zeros'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4806449702322540012</id><published>2011-04-20T13:48:00.003-05:00</published><updated>2011-04-20T23:15:01.647-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='undocumented SP'/><category scheme='http://www.blogger.com/atom/ns#' term='jobs'/><category scheme='http://www.blogger.com/atom/ns#' term='undocumented'/><title type='text'>[Jobs] Quick &amp; Dirty - is the job running (another approach)</title><content type='html'>Cribbed from Gregory A. Larsen.  &lt;br /&gt;&lt;br /&gt;http://www.databasejournal.com/features/mssql/article.php/10894_3491201_2/Detecting-The-State-of-a-SQL-Server-Agent-Job.htm&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;create table #enum_job ( &lt;br /&gt;Job_ID uniqueidentifier, &lt;br /&gt;Last_Run_Date int, &lt;br /&gt;Last_Run_Time int, &lt;br /&gt;Next_Run_Date int, &lt;br /&gt;Next_Run_Time int, &lt;br /&gt;Next_Run_Schedule_ID int, &lt;br /&gt;Requested_To_Run int, &lt;br /&gt;Request_Source int, &lt;br /&gt;Request_Source_ID varchar(100), &lt;br /&gt;Running int, &lt;br /&gt;Current_Step int, &lt;br /&gt;Current_Retry_Attempt int, &lt;br /&gt;State int &lt;br /&gt;)       &lt;br /&gt;insert into #enum_job &lt;br /&gt;     exec master.dbo.xp_sqlagent_enum_jobs 0,sa,@job_id&lt;br /&gt;&lt;br /&gt;IF (select COUNT(*) from #enum_job WHERE running = 1) = 1&lt;br /&gt;PRINT 'running'&lt;br /&gt;drop table #enum_job&lt;br /&gt;SET NOCOUNT OFF&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4806449702322540012?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4806449702322540012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4806449702322540012' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4806449702322540012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4806449702322540012'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/04/jobs-quick-dirty-is-job-running-another.html' title='[Jobs] Quick &amp; Dirty - is the job running (another approach)'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8162944287695969755</id><published>2011-04-13T15:16:00.002-05:00</published><updated>2011-04-13T15:22:29.254-05:00</updated><title type='text'>[Code] Using INFORMATION_SCHEMA with temp tables.</title><content type='html'>Was recently trying to parse a temp table and do things based on the columns.  I'd come up with this....&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  SELECT * FROM tempdb.INFORMATION_SCHEMA.COLUMNS &lt;br /&gt;  WHERE TABLE_NAME LIKE '#yourtemptablehere%'&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But then I came across this post from Michael Valentine Jones (&lt;a href = "http://en.wikipedia.org/wiki/Stranger_in_a_Strange_Land"&gt;a pseudonym?&lt;/a&gt;), on the SQLTeam forums.  Many thanks, Michael&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select&lt;br /&gt; *&lt;br /&gt;from&lt;br /&gt; tempdb.information_schema.columns&lt;br /&gt;where&lt;br /&gt; object_id('tempdb..#yourtemptablehere') = object_id('tempdb..'+TABLE_NAME)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8162944287695969755?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8162944287695969755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8162944287695969755' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8162944287695969755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8162944287695969755'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/04/code-using-informationschema-with-temp.html' title='[Code] Using INFORMATION_SCHEMA with temp tables.'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7909336321182822907</id><published>2011-04-07T11:30:00.004-05:00</published><updated>2011-04-07T12:27:47.089-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='csv'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>[Powershell] Basic SQL query exported to CSV</title><content type='html'>&lt;pre&gt;&lt;br /&gt;Invoke-Sqlcmd -query "select getdate(), getdate()+1" -serverinstance "yourservername"|Export-Csv c:\temp\testps2.txt –notypeinformation&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;or, broken down by line so you can see all of it...&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;Invoke-Sqlcmd &lt;br /&gt; -query "select getdate(), getdate()+1" &lt;br /&gt; -serverinstance "yourservername"&lt;br /&gt; |Export-Csv &lt;br /&gt; c:\test\test.txt &lt;br /&gt; –notypeinformation&lt;br /&gt;&lt;br /&gt;-query: the query.&lt;br /&gt;-serverinstance: server name&lt;br /&gt;-notypeinformation: removes the “#TYPE System.Data.DataRow” line at the top.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And if you don't want a header row... you have to use a different export process, and then tell a different process to iterate through the array and write to disk.  Really, guys?  Too hard to add a -noheader option?&lt;br /&gt;&lt;br /&gt;(and all this is on one line; you can use a ` to split it across lines.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Invoke-Sqlcmd -query "select getdate(), getdate(); select getdate()+1, getdate()+1" -serverinstance "yourservername"|ConvertTo-Csv -notypeinformation -outvariable outdata; $outdata[1..($outdata.count-1)] |ForEach-Object {Add-Content -value $_ -path "c:\temp\test.txt"}&lt;br /&gt;&lt;br /&gt;or &lt;br /&gt;Invoke-Sqlcmd -query "select getdate(), getdate(); select getdate()+1, getdate()+1" `&lt;br /&gt;-serverinstance "ftw-sv-db-03"|ConvertTo-Csv -notypeinformation -outvariable outdata;`&lt;br /&gt; $outdata[1..($outdata.count-1)] |ForEach-Object {Add-Content -value $_ -path "c:\temp\test.txt"}&lt;br /&gt; (then hit enter again to tell it you're done for realsies)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Oh, and it for some reason outputs the full file to console, but saves what you want to a file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7909336321182822907?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7909336321182822907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7909336321182822907' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7909336321182822907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7909336321182822907'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/04/invoke-sqlcmd-query-select-getdate.html' title='[Powershell] Basic SQL query exported to CSV'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4060467127787819065</id><published>2011-04-06T16:30:00.005-05:00</published><updated>2011-04-06T17:12:53.142-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>[Powershell] Basics to run a SQL query</title><content type='html'>Putting this here for when the new guy starts.  The learning curve can suck at certain points, like the installer.  See my other post about it.  Grr.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Install Powershell 2&lt;br /&gt;&lt;li&gt;Install SQL Server 2008 Feature Pack: Powershell Extensions http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=ceb4346f-657f-4d28-83f5-aae0c5c83d52&lt;br /&gt;&lt;li&gt;Install SQL Powershell Extensions: http://sqlpsx.codeplex.com/&lt;br /&gt;&lt;li&gt;Add this line to My Documents\WindowsPowerShell\profile.ps1: "add-pssnapin SqlServerCmdletSnapin100; add-pssnapin SqlServerProviderSnapin100;" (no quotes)&lt;br /&gt;&lt;li&gt;Start Powershell and see if it works:&lt;br /&gt;Set-ExecutionPolicy RemoteSigned (or &lt;br /&gt;Invoke-Sqlcmd -query "select getdate(), @@version" -serverinstance "yourservername"|Export-Csv c:\testps.txt –notypeinformation&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4060467127787819065?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4060467127787819065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4060467127787819065' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4060467127787819065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4060467127787819065'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/04/powershell-basics-to-run-sql-query.html' title='[Powershell] Basics to run a SQL query'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8325509182754797310</id><published>2011-04-06T10:32:00.002-05:00</published><updated>2011-04-06T13:58:58.263-05:00</updated><title type='text'>[Maintenance] Checking age of statistics</title><content type='html'>Simple stuff, saved here in case anybody needs it&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT objects.name AS object_name, indexes.name AS index_name,&lt;br /&gt;STATS_DATE(indexes.OBJECT_ID, index_id) AS StatsUpdated&lt;br /&gt;FROM sys.indexes&lt;br /&gt;INNER JOIN sys.objects ON indexes.object_id = objects.object_id&lt;br /&gt;--WHERE objects.OBJECT_ID = OBJECT_ID('dbo.yourtablename')&lt;br /&gt;GO&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8325509182754797310?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8325509182754797310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8325509182754797310' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8325509182754797310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8325509182754797310'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/04/maintenance-checking-age-of-statistics.html' title='[Maintenance] Checking age of statistics'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3630386677776137918</id><published>2011-03-22T15:25:00.002-05:00</published><updated>2011-03-22T15:42:59.906-05:00</updated><title type='text'>[Replication] Nasty bug and reinitializing without a snapshot</title><content type='html'>So, there's a bug in SQL Server 2005 SP2 _and_ SQL Server 2005 SP3 (fixed in SP2 CU12 and SP3 CU3), where a commonly-used replication SP can inadvertently reset your subscription, and you get the dread "The initial snapshot for publication...is not yet available" error.  In my case I couldn't easily snapshot the data across, so a workaround is to sync the data, then recreate the subscription, specifying that it does not need to be initialized.&lt;br /&gt;&lt;br /&gt;Bug: MS KB967192&lt;br /&gt;http://support.microsoft.com/kb/967192/EN-US&lt;br /&gt;&lt;br /&gt;Fix:&lt;br /&gt;http://technet.microsoft.com/en-us/library/ms151705.aspx&lt;br /&gt;&lt;br /&gt;Essentially, what you need to do is drop the subscription, sync the data, then recreate the subscription, making sure to uncheck "Initialize" (if using SSMS).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3630386677776137918?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3630386677776137918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3630386677776137918' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3630386677776137918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3630386677776137918'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/03/replication-nasty-bug-and.html' title='[Replication] Nasty bug and reinitializing without a snapshot'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6122717179282212261</id><published>2011-03-10T15:22:00.002-06:00</published><updated>2011-03-10T15:41:23.417-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='undocumented SP'/><category scheme='http://www.blogger.com/atom/ns#' term='backups'/><title type='text'>[Backups] Verify your backups physically exist</title><content type='html'>We've been using Rodney Landrum's SSIS package to monitor our environment (As Seen In SQL Server Mag).  We're running the old version, which doesn't deal AT ALL with servers not being available.  (I assume the latest version does, but haven't had time to check.)&lt;br /&gt;&lt;br /&gt;And I came across an issue recently - missing backups.  Because of the various retentions set via our backup jobs, we would occasionally have a file vanish.  Eek!&lt;br /&gt;&lt;br /&gt;So, cue this code.  It'll grab the most-recent backup for each server/database, and make sure the file physically exists.  It doesn't check the veracity of the backup, just that there's a file there.  It also uses xp_fileexists, an undocumented (and therefore it can change - though it's been the same since SQL Server 2000) SP.&lt;br /&gt;&lt;br /&gt;If you don't use Rodney's code, you can still use this, but it'll be a _little_ more work.  Take the below code, have it run on each machine and dump into a central table (I'll leave those details up to you), then run the second set of code against it.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT server_name, &lt;br /&gt;  database_name, &lt;br /&gt;  physical_device_name, &lt;br /&gt;  backup_start_date,&lt;br /&gt;  'FULL' as backup_type &lt;br /&gt;from msdb.dbo.backupmediafamily &lt;br /&gt;inner join msdb.dbo.backupset &lt;br /&gt; on backupset.media_set_id = backupmediafamily.media_set_id&lt;br /&gt;where backup_start_date &gt; getdate()-14&lt;br /&gt;and physical_device_name NOT LIKE 'VDI_%'&lt;br /&gt;and physical_device_name like '%BAK' --or whatever your backups are named.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And here's the full code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;USE DBA_Rep&lt;br /&gt;if object_id('tempdb..#backup_list') is not null&lt;br /&gt;    drop table #backup_list;&lt;br /&gt;CREATE TABLE #backup_list (id int IDENTITY, server sysname, database_name sysname, physical_device_name VARCHAR(520), backup_start_date DATETIME, file_exists BIT)&lt;br /&gt;DECLARE @minid INT, @maxid int&lt;br /&gt;DECLARE @does_it_exist INT&lt;br /&gt;DECLARE @filename VARCHAR(500)&lt;br /&gt;&lt;br /&gt;--using dba_rep's copy that Rodney Landrum's SSIS code pulls, get a list of the most recent backup for each db in past 2 weeks&lt;br /&gt;INSERT INTO #backup_list&lt;br /&gt;        ( server ,&lt;br /&gt;          database_name ,&lt;br /&gt;          physical_device_name,&lt;br /&gt;          backup_start_date &lt;br /&gt;        )&lt;br /&gt;SELECT Backup_History.server, &lt;br /&gt;  Backup_History.database_name, &lt;br /&gt;  Backup_History.physical_device_name, &lt;br /&gt;  Backup_History.backup_start_date &lt;br /&gt;FROM Backup_History&lt;br /&gt;INNER JOIN &lt;br /&gt;(&lt;br /&gt;SELECT server, database_name, &lt;br /&gt; MAX(backup_start_date) AS max_start_date&lt;br /&gt;FROM Backup_History &lt;br /&gt;WHERE backup_type &lt;&gt;'LOG' &lt;br /&gt; AND backup_start_date &gt; GETDATE()-14&lt;br /&gt;GROUP BY server, database_name&lt;br /&gt;)most_recent&lt;br /&gt;ON most_recent.SERVER = Backup_History.Server&lt;br /&gt;AND most_recent.database_name = Backup_History.database_name&lt;br /&gt;AND most_recent.max_start_date = Backup_History.backup_start_date&lt;br /&gt;AND Backup_History.physical_device_name NOT LIKE 'SQLsafe%'&lt;br /&gt;AND Backup_History.backup_type &lt;&gt; 'LOG'&lt;br /&gt;&lt;br /&gt;--Fixing the names of local backups so that we can get them over the network.&lt;br /&gt;UPDATE #backup_list &lt;br /&gt;SET physical_device_name = REPLACE(physical_device_name,LEFT(physical_device_name,2), '\\' + LTRIM(RTRIM(server)) + '\' + LEFT(physical_device_name,1) + '$')&lt;br /&gt;WHERE physical_device_name LIKE '%:%'&lt;br /&gt;&lt;br /&gt;SELECT @minid = MIN(id) , @maxid = MAX(id) FROM #backup_list&lt;br /&gt;&lt;br /&gt;--Walk the list, checking each file and updating the table&lt;br /&gt;WHILE @minid &lt; @maxid&lt;br /&gt;BEGIN&lt;br /&gt; SET @does_it_exist = 0&lt;br /&gt;&lt;br /&gt; SELECT @filename = physical_device_name &lt;br /&gt; FROM #backup_list &lt;br /&gt; WHERE id = @minid&lt;br /&gt;&lt;br /&gt; EXEC Master.dbo.xp_fileexist @filename, @does_it_exist OUTPUT&lt;br /&gt; UPDATE #backup_list &lt;br /&gt; SET file_exists = @does_it_exist &lt;br /&gt; WHERE id = @minid&lt;br /&gt;&lt;br /&gt; IF @minid % 10 = 0 PRINT @minid&lt;br /&gt;&lt;br /&gt; SET @minid = @minid+1 &lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;SELECT * FROM #backup_list WHERE file_exists = 0            &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6122717179282212261?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6122717179282212261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6122717179282212261' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6122717179282212261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6122717179282212261'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/03/backups-verify-your-backups-physically.html' title='[Backups] Verify your backups physically exist'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6844301256096577367</id><published>2011-03-03T10:24:00.001-06:00</published><updated>2011-03-03T10:25:40.581-06:00</updated><title type='text'>[Tools] Convert PDF to text</title><content type='html'>Courtesy of the interwebs:&lt;br /&gt;&lt;br /&gt;"That depends. If it is an image in the PDF, you're out of luck.&lt;br /&gt;Otherwise (if it is a PDF containing text) you can do the following, all in one line, assuming osx has the strings command and a perl interpreter:"&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;strings filename.pdf | perl -ne '$line=$_; $s=$line; $w=""; while ($s =~ m/(\w+)(.*)/){print $line if ($w eq $1); $w=$1; $s=$2;}'&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6844301256096577367?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6844301256096577367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6844301256096577367' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6844301256096577367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6844301256096577367'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/03/tools-convert-pdf-to-text.html' title='[Tools] Convert PDF to text'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5901971791619982225</id><published>2011-02-23T17:01:00.001-06:00</published><updated>2011-02-23T17:03:03.211-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='tip'/><title type='text'>[Tips] Create a comma-separated list in one query using COALESCE</title><content type='html'>Clever, clever.  Wish I could take credit for it.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;-----------------------------------&lt;br /&gt;--Creating a comma-separated list--&lt;br /&gt;-----------------------------------&lt;br /&gt; &lt;br /&gt;DECLARE @EmployeeList varchar(100)&lt;br /&gt; &lt;br /&gt;SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') &lt;br /&gt;+ CAST(id AS varchar(15))&lt;br /&gt;FROM temp_td_200704&lt;br /&gt;&lt;br /&gt;SELECT @EmployeeList&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5901971791619982225?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5901971791619982225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5901971791619982225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5901971791619982225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5901971791619982225'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/02/tips-create-comma-separated-list-in-one.html' title='[Tips] Create a comma-separated list in one query using COALESCE'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-624472538318065333</id><published>2011-02-18T15:16:00.002-06:00</published><updated>2011-02-18T15:19:49.722-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ssas'/><category scheme='http://www.blogger.com/atom/ns#' term='logging'/><category scheme='http://www.blogger.com/atom/ns#' term='history'/><title type='text'>[SSAS] Quick notes on logging queries run against the cube</title><content type='html'>There's a lot of details out there about OlapQueryLog, but here are the 3 things I ran into setting it up:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tips and tricks from setting this up:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Do it on whatever server hosts the cube, since it will determine what version of the SQL driver it needs.&lt;br /&gt;&lt;li&gt;Event Viewer will tell you the errors you’re having, be they permissions, bad version of the SQL driver, etc.&lt;br /&gt;&lt;li&gt;The key settings: &lt;br /&gt;&lt;ul&gt;&lt;li&gt;Log\QueryLog\CreateQueryLogTable = true&lt;br /&gt;&lt;li&gt;QueryLogConnectionString (click and set it)&lt;br /&gt;&lt;li&gt;QueryLogSampling is "every X queries, save the query to table". So the default means every 10th query gets saved.&lt;br /&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-624472538318065333?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/624472538318065333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=624472538318065333' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/624472538318065333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/624472538318065333'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/02/ssas-quick-notes-on-logging-queries-run.html' title='[SSAS] Quick notes on logging queries run against the cube'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7219821004789235208</id><published>2011-02-17T15:05:00.004-06:00</published><updated>2011-02-17T17:17:19.303-06:00</updated><title type='text'>[Trick] Eliminating "arithmetic overflow error" that aren't in the result set.</title><content type='html'>Ran into a problem where the SP would always kick out the standard overflow message:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Arithmetic overflow error converting numeric to data type varchar&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As it turns out, the problem was data that exists in the data set, but not in the results set - the WHERE clause eliminated it.  What made it even harder to troubleshoot was that because that was the issue, we could duplicate it by running the SP - but not by copying and pasting the code.  No matter what options you used - ARITHABORT, ANSI_WARNINGs, etc, it would run successfully, skipping over the bad record (since it was excluded via the WHERE clause).&lt;br /&gt;&lt;br /&gt;As is pointed out in "Defensive Database Programming with SQL Server" by Alex Kuznetsov (WELL worth getting, and Red-gate offers a free PDF), you can't guarantee the order things get evaluated in.  &lt;br /&gt;&lt;br /&gt;So one way around it: take your query that is failing in the SELECT clause. Find a unique key that you can pull from your data set.  Copy/paste the entirety of the FROM/WHERE, and SELECT only this key into a temp table.  Now go to your full query and INNER JOIN this temp table.  &lt;br /&gt;&lt;br /&gt;Another potential way around it: remove everything from the where clause and keep it in the JOINs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7219821004789235208?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7219821004789235208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7219821004789235208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7219821004789235208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7219821004789235208'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/02/trick-eliminating-arithmetic-overflow.html' title='[Trick] Eliminating &quot;arithmetic overflow error&quot; that aren&apos;t in the result set.'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-641058637933876952</id><published>2011-02-17T10:53:00.005-06:00</published><updated>2011-02-17T13:07:46.829-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='dirty data'/><category scheme='http://www.blogger.com/atom/ns#' term='low-ascii'/><title type='text'>[Code] Stripping low-ascii out of a table, slow way</title><content type='html'>I'm working on a CLR to do this considerably faster, but here's what I have for now.  The purpose of this is to remove dirty data from an upstream feed.  We can't make XML with it - the code that creates the XML chokes on it.  Note that this isn't terribly fast, because we're brute-forcing it and having to loop through (31 * number-of-fields) times.  The CLR should do it in one pass per field.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;--CREATE PROCEDURE [dbo].[strip_low_ascii]  &lt;br /&gt;--as  &lt;br /&gt;DECLARE @columns TABLE (id INT IDENTITY, column_name sysname)  &lt;br /&gt;DECLARE @odd_ascii CHAR(1),&lt;br /&gt;  @ascii_value int,&lt;br /&gt;  @column_start smallint, &lt;br /&gt;  @column_end SMALLINT, &lt;br /&gt;  @sql NVARCHAR(4000), &lt;br /&gt;  @field_name sysname, --to allow us to loop through all fields  &lt;br /&gt;  @table_schema sysname, &lt;br /&gt;  @table_name sysname&lt;br /&gt;SET @ascii_value = 31   --31 aka 0x1F.  Space is 32/0x20.  0-30 is our "low-ascii" range&lt;br /&gt;SET @table_schema = 'dbo'&lt;br /&gt;SET @table_name = 'yourtablename'&lt;br /&gt;&lt;br /&gt;CREATE TABLE #list_of_id (id bigint primary key)&lt;br /&gt;  &lt;br /&gt;INSERT INTO @columns  &lt;br /&gt;      SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS   &lt;br /&gt;      WHERE TABLE_SCHEMA = @table_schema &lt;br /&gt;  AND TABLE_NAME = @table_name&lt;br /&gt;  AND DATA_TYPE IN ('char','varchar','nchar','nvarchar')  &lt;br /&gt;  &lt;br /&gt;SELECT @column_start = MIN(id), @column_end = MAX(id) FROM @columns  &lt;br /&gt;  &lt;br /&gt;WHILE @ascii_value &gt;= 0 --look for all low ascii  &lt;br /&gt;BEGIN  &lt;br /&gt;      SET @odd_ascii = NULL  &lt;br /&gt;      SET @column_start = 1  &lt;br /&gt;      SELECT @odd_ascii = CHAR(@ascii_value)  &lt;br /&gt;  &lt;br /&gt;      WHILE @column_start &lt;= @column_end  &lt;br /&gt;      BEGIN  &lt;br /&gt;   TRUNCATE TABLE #list_of_id&lt;br /&gt;            SET @field_name = NULL  &lt;br /&gt;            SET @sql = NULL   &lt;br /&gt;            SELECT @field_name = column_name FROM @columns WHERE id = @column_start  &lt;br /&gt;            SELECT @sql = 'insert into #list_of_id &lt;br /&gt;                  SELECT id FROM ' + QUOTENAME(@table_schema) + '.' + QUOTENAME(@table_name) + '&lt;br /&gt;                  WHERE insert_datetime &gt;=CONVERT(CHAR(8),GETDATE(),112)  &lt;br /&gt;                  AND ' + @field_name + ' LIKE ''%'' +  @oddascii  + ''%''  &lt;br /&gt;      IF @@rowcount &gt;0   --( select count from @list_of_id )&lt;br /&gt;            update ' + @table_name + ' set ' + @field_name + ' =  REPLACE(' + @field_name + ',  @oddascii, '''')   &lt;br /&gt;            WHERE insert_datetime &gt;=CONVERT(CHAR(8),GETDATE(),112)  &lt;br /&gt;   and id in (select id from #list_of_id)&lt;br /&gt;            AND ' + @field_name + ' LIKE ''%'' + @oddascii + ''%'''  &lt;br /&gt;            &lt;br /&gt;  &lt;br /&gt;--PRINT @sql  &lt;br /&gt;  &lt;br /&gt;            EXECUTE sp_executesql @sql, N'@oddascii char(1)', @oddascii = @odd_ascii  &lt;br /&gt;  &lt;br /&gt;            SET @column_start = @column_start + 1  &lt;br /&gt;      END  &lt;br /&gt;  &lt;br /&gt;      SET @ascii_value = @ascii_value-1  &lt;br /&gt;END  &lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-641058637933876952?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/641058637933876952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=641058637933876952' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/641058637933876952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/641058637933876952'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/02/code-stripping-low-ascii-out-of-table.html' title='[Code] Stripping low-ascii out of a table, slow way'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2439704939778201939</id><published>2011-01-27T18:31:00.006-06:00</published><updated>2011-01-27T18:38:38.838-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><title type='text'>[Replication] Orphaned distrubution agent after SQL Agent crash</title><content type='html'>I need to figure out where THIS particular error is stored in the logs, since none of my normal processes or alerts flagged this...&lt;br /&gt;&lt;br /&gt;"Error messages:&lt;br /&gt;The replication agent has not logged a progress message in 10 minutes. This might indicate an unresponsive agent or high system activity. Verify that records are being replicated to the destination and that connections to the Subscriber, Publisher, and Di"&lt;br /&gt;&lt;br /&gt;How'd I find it?  The big red X in the Replication Monitor, for the server whose SQL Agent crashed earlier today.  Nothing in the Agent Log or the SQL Server Log.  So it's buried somewhere in sysjobhistory&lt;br /&gt;&lt;br /&gt;I believe the extant process was running properly, but why chance it?&lt;br /&gt;&lt;br /&gt;Login to server, find "qrdrsvc.exe" in Task Manager.  Kill process.  Run the Queue Reader job.  On my server, it's [MYServerName].6 (?), and was Between Retries.  Also, the job category was: "REPL-QueueReader"&lt;br /&gt;&lt;br /&gt;And you didn't think you'd learn anything new today...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2439704939778201939?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2439704939778201939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2439704939778201939' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2439704939778201939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2439704939778201939'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/01/replication-orphaned-distrubution-agent.html' title='[Replication] Orphaned distrubution agent after SQL Agent crash'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-1437631934136493918</id><published>2011-01-27T18:09:00.002-06:00</published><updated>2011-01-27T18:10:50.646-06:00</updated><title type='text'>[SQL] BULK INSERT and adding an identity</title><content type='html'>So I have a file with two columns, and I need to import it into a table with an IDENTITY column.  Here's the easy way:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE TABLE blah (narf VARCHAR(4000), poit VARCHAR(4000))&lt;br /&gt;&lt;br /&gt;BULK INSERT blah&lt;br /&gt;from "c:\files\blah.txt"&lt;br /&gt;&lt;br /&gt;ALTER TABLE blah&lt;br /&gt;ADD ID int IDENTITY(1,1) NOT NULL&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-1437631934136493918?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/1437631934136493918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=1437631934136493918' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1437631934136493918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1437631934136493918'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/01/sql-bulk-insert-and-adding-identity.html' title='[SQL] BULK INSERT and adding an identity'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5323374951703439552</id><published>2011-01-27T16:56:00.003-06:00</published><updated>2011-01-27T17:09:01.356-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><title type='text'>[Replication] Orphaned agents after Agent crash.</title><content type='html'>Had SQL Server agent crash on me, and then my home-grown replication monitoring gave me the following error via email (interestingly enough, the Alerts we created didn't fire):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Agent 'MYSERVERNAME-MYDatabase-MyPublication-Servername-525' is&lt;br /&gt;retrying after an error. 14 retries attempted. See agent &lt;br /&gt;job history in the Jobs folder for more details.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Since that's the error you'd see in the Replication Monitor (start-&gt;run-&gt;"sqlmonitor"), I went and looked at the agent which showed our now-at-16 retries:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[...]&lt;br /&gt;2011-01-27 22:46:17.596 Agent message code 21036. Another distribution agent for the subscription or subscriptions is running, or the server is working on a previous request by the same agent.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Interesting.  My guess is that since the SQL Agent crashed, it left behind agents that are still running their original orders, blocking the new agents from starting.  Well, let's look at what's connected.  &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT * FROM master..sysprocesses &lt;br /&gt;WHERE program_name LIKE @@servername + '%' &lt;br /&gt;	AND login_time &lt; CONVERT(CHAR(8),GETDATE(),112)--before today&lt;br /&gt;	AND hostname = @@servername &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Bingo.  Two SPIDs, both with program names like 'MYSERVERNAME-MYDatabase-MyPublication-Servername' - and which match my original email above.  &lt;br /&gt;&lt;br /&gt;Kill the two SPIDs, and the next go-round the distribution agent spins up successfully.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5323374951703439552?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5323374951703439552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5323374951703439552' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5323374951703439552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5323374951703439552'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/01/replication-orphaned-agents-after-agent.html' title='[Replication] Orphaned agents after Agent crash.'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4034397845540928039</id><published>2011-01-11T10:54:00.001-06:00</published><updated>2011-01-11T10:55:53.454-06:00</updated><title type='text'>Rule 5</title><content type='html'>Rule 5: Software scales faster than hardware.&lt;br /&gt;&lt;br /&gt;(Case in point: had a service broker issue.  Several fixes were made, but changing the code increased performance substantially with an overall lower CPU)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4034397845540928039?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4034397845540928039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4034397845540928039' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4034397845540928039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4034397845540928039'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/01/rule-5.html' title='Rule 5'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2827742919372031355</id><published>2011-01-11T10:05:00.002-06:00</published><updated>2011-01-11T10:25:19.483-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><title type='text'>CHAR() vs CHAR()</title><content type='html'>Another of the "I forget the tool so let's put it in the blog" posts.&lt;br /&gt;&lt;br /&gt;Obviously there's the datatype.  But you can also create high-ascii &amp; low-ascii symbols that might show up as a tiny square, or (at least in SSMS) not show up at all.  &lt;br /&gt;&lt;br /&gt;A map:&lt;br /&gt;http://web.cs.mun.ca/~michael/c/ascii-table.html&lt;br /&gt;This also explains some of the other code you may have seen for BULK INSERT, such as 0x0a (which is "newline" or "linefeed", the Unix "return"; Windows uses CR/LF).  It can also be used to clean up code.  Instead of something like &lt;br /&gt;&lt;pre&gt;+ ''' +&lt;/pre&gt;&lt;br /&gt;you could use&lt;br /&gt;&lt;pre&gt;+ char(39) + &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The value in CHAR has to be a number.  Which is, naturally, both good and bad.&lt;br /&gt;&lt;br /&gt;more examples:&lt;br /&gt;select char(20) --random low-ascii&lt;br /&gt;select char(32) --space&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2827742919372031355?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2827742919372031355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2827742919372031355' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2827742919372031355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2827742919372031355'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/01/char-vs-char.html' title='CHAR() vs CHAR()'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-397263851845524038</id><published>2011-01-03T10:51:00.002-06:00</published><updated>2011-01-03T10:56:31.714-06:00</updated><title type='text'>The Rules: 0-4</title><content type='html'>Here are my current DBA rules.  Yours will differ, but these hold me in good stead.&lt;br /&gt;&lt;br /&gt;Rule 0: Verify your backups.  Obviously I assume you are making backups - you _are_, right?&lt;br /&gt;Rule 1: UPDATE STATISTICS.  That will frequently save your hide.&lt;br /&gt;Rule 2: Data/Log always on separate drives. Know what happens if your data and log are on the same drive, and it fills up?  No?  You don't want to.&lt;br /&gt;Rule 3: Complexity is the enemy.  Not quite KISS, but definitely related.&lt;br /&gt;Rule 4: SQL Sentry's "Disable Until" is a godsend.  Make sure to use that instead of simply disabling the job.  And double-check the time it restarts, since SQL Sentry adds 1 day by default - not useful if you're trying to disable something for 2-3 hours.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-397263851845524038?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/397263851845524038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=397263851845524038' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/397263851845524038'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/397263851845524038'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/01/rules-0-4.html' title='The Rules: 0-4'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6101934170239393552</id><published>2011-01-03T10:13:00.002-06:00</published><updated>2011-01-03T10:48:04.673-06:00</updated><title type='text'>Varchar(n) vs Varchar(Max)</title><content type='html'>Two questions:&lt;br /&gt;1) You have a 1tb table with 1m rows, and need to change a field from varchar(5) to varchar(10).  How long does it take, and how much log space is used?&lt;br /&gt;2) You have a 1tb table with 1m rows, and need to change a field from varchar(5) to varchar(MAX).  How long does it take, and how much log space is used?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The answer for (1) is simple: instantly, and none.  Fortunately, it's a metadata operation, and since it knows everything already in the database must be the right size, no work needs be done.&lt;br /&gt;For (2), I can't tell you - we rolled back after 90 minutes (it then took another 3+ hours to roll back), and it had consumed 200+gb of log space.  On the plus side, it's table-partitioned, so we'll upgrade it that way.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6101934170239393552?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6101934170239393552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6101934170239393552' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6101934170239393552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6101934170239393552'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2011/01/varcharn-vs-varcharmax.html' title='Varchar(n) vs Varchar(Max)'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3344057500163501291</id><published>2010-12-07T15:55:00.004-06:00</published><updated>2010-12-07T16:28:22.791-06:00</updated><title type='text'>Texas Hill Country BBQ Brisket (yes, that's redundant)</title><content type='html'>Bare bones, basic Texas BBQ.  Have done it twice so far with surprisingly good results.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;One whole brisket, in cryo-vac packaging (aka a "packer-cut brisket").  Weighs about 10 pounts.&lt;br /&gt;&lt;li&gt;One smoker.  I cheat and use an electic smoker (Brinkman, $70 at Home Depot).&lt;br /&gt;&lt;li&gt;Wired-probe thermometer.  You'll put the probe in the brisket, and the actual temperature will be shown on the other part which will be NEAR the smoker (not on).&lt;br /&gt;&lt;li&gt;One cup yellow mustard&lt;br /&gt;&lt;li&gt;Half-cup kosher salt&lt;br /&gt;&lt;li&gt;Half-cup black pepper &lt;br /&gt;&lt;li&gt;1-8 pounds Oak chunks (not chips). Can use Hickory, Mesquite, Apple, Cherry.&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Steps: &lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Soak 1 pound wood in water (I put it in a ziplock-style bag).  You want it to soak between 15 minutes and one hour.&lt;br /&gt;&lt;li&gt;Pull brisket out of bag, drain off juices, slice the "fat cap" (one side will have a substantial amount of fat) with a knife, but not all the way to the actual meat.&lt;br /&gt;&lt;li&gt;Cut brisket in half - a whole one won't fit on my smoker.  Make sure the two pieces are roughly of equal weight, since they're both going to cook the same amount of time.  As you cut it in half you'll see that there are two muscles.  And, just to make it fun, the grain on one is perpendicular to the other.&lt;br /&gt;&lt;li&gt;Coat each piece in mustard.  A quarter-cup is probably plenty for each, but you want everything coated.&lt;br /&gt;&lt;li&gt;Mix salt+pepper together. "Dalmatian Dust" or "Dalmatian Rub".  Apply liberally to both pieces of brisket.  &lt;br /&gt;&lt;li&gt;Drain wood chunks, put in smoker.  Fill water bowl with water. Put in smoker.  Put brisket on both top &amp; bottom grates.  Put thermometer in bottom piece.  Put lid on.  Plug in.  Apply roughly one pound of moist wood per hour until the meat is very dark in color.  Remove once temperature hits 185.  Wait 20 minutes.  Separate the two cuts of meat. Determine where the grain is (the way the long muscle strands run), then slice perpendicular to grain.  Eat.&lt;br /&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3344057500163501291?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3344057500163501291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3344057500163501291' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3344057500163501291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3344057500163501291'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/12/texas-hill-country-bbq-brisket-yes.html' title='Texas Hill Country BBQ Brisket (yes, that&apos;s redundant)'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-1038072862540514577</id><published>2010-11-04T14:37:00.003-05:00</published><updated>2010-11-04T14:40:49.156-05:00</updated><title type='text'>[semantics] Why I hate ISNUMERIC</title><content type='html'>So, ISNUMERIC is simple, right?  Put in numbers, and it tells you whether it is.  &lt;br /&gt;Except it has very specific exceptions you may not know about.&lt;br /&gt;&lt;br /&gt;Any of these will come back with ISNUMERIC = 1:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;0D123&lt;br /&gt;&lt;li&gt;123D50&lt;br /&gt;&lt;li&gt;123E50&lt;br /&gt;&lt;li&gt;$,,1,,.1&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Currency doesn't count (and that's ALL currency symbols), D and E don't count in certain circumstances, commas and periods don't count.  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Instead, use something like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (select PATINDEX('%[^0-9.]%','$00.01')) = 0  print 'numeric' &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-1038072862540514577?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/1038072862540514577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=1038072862540514577' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1038072862540514577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1038072862540514577'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/11/semantics-why-i-hate-isnumeric.html' title='[semantics] Why I hate ISNUMERIC'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7146454327444055213</id><published>2010-11-04T14:28:00.000-05:00</published><updated>2010-11-04T14:29:41.898-05:00</updated><title type='text'>[Replication] more replication trouble tracking</title><content type='html'>&lt;pre&gt;&lt;br /&gt;--get list of the possible databases by querying the publisher&lt;br /&gt;&lt;br /&gt;SELECT * FROM distribution.dbo.MSpublisher_databases&lt;br /&gt;&lt;br /&gt;--Now figure out what the article number is&lt;br /&gt;--the database name there is the database that the publication is in.&lt;br /&gt;Replication_Master..sp_helparticle @publication = 'User_Profiles'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Now that you have the publisher database ID (step 1) and the article id (step 2)&lt;br /&gt;--get the list of commands.&lt;br /&gt;EXEC distribution..sp_browsereplcmds @publisher_database_id = 2, @article_id = 369&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--And if you're really lucky, in sqlmonitor you'll get the following:&lt;br /&gt;--(Transaction sequence number: 0x00018A0500009072002A00000000, Command ID: 1)&lt;br /&gt;--in which case...&lt;br /&gt;&lt;br /&gt;EXEC distribution..sp_browsereplcmds @publisher_database_id = 2, @article_id = 369, &lt;br /&gt;@xact_seqno_start = '0x00018A0500009072002A00000000', @xact_seqno_end = '0x00018A0500009072002A00000000'&lt;br /&gt;--(set both start and end to the same value, the one in the error message)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7146454327444055213?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7146454327444055213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7146454327444055213' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7146454327444055213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7146454327444055213'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/11/replication-more-replication-trouble.html' title='[Replication] more replication trouble tracking'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-1798865436870659627</id><published>2010-10-28T13:11:00.002-05:00</published><updated>2010-10-28T13:18:22.293-05:00</updated><title type='text'>[Code] IF EXISTS for procedures using INFORMATION_SCHEMA</title><content type='html'>Adam Machanic's code does two things that I love, but don't think to do.&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;br /&gt;&lt;br /&gt;IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'yourprocname')&lt;br /&gt;      EXEC ('CREATE PROC dbo.yourprocname AS SELECT ''stub version, to be replaced''')&lt;br /&gt;GO&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt; It uses the INFORMATION_SCHEMA tables.  These are like the system tables, but are more portable (every database vendor has them and they all look the same), and are meant to be human-readable.  The downside is that they don't necessarily have all the details you need.  I use INFORMATION_SCHEMA.TABLES AND INFORMATION_SCHEMA.COLUMNS all the time, but forget about ROUTINES, which includes functions and stored procedures.&lt;br /&gt;&lt;li&gt; By creating a stub entry, it ensures permissions remain, as well as other things like the original creation date.  If you have an automated environment, you might do a DROP/CREATE, which would break all your explicit permissions (and reset the create_date).  By doing a stub entry then an ALTER, you ensure those remain.&lt;br /&gt;&lt;br /&gt;Highly recommended code.  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-1798865436870659627?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/1798865436870659627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=1798865436870659627' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1798865436870659627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1798865436870659627'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/10/code-if-exists-for-procedures-using.html' title='[Code] IF EXISTS for procedures using INFORMATION_SCHEMA'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-611453737374711180</id><published>2010-10-08T18:49:00.003-05:00</published><updated>2010-10-12T16:05:51.759-05:00</updated><title type='text'>[Replication] Better alternative to Replication Monitor</title><content type='html'>&lt;div&gt;(changed on 10/12 - whoever woulda thunk a UNION wouldn't work right?)&lt;/div&gt;I hate Replication Monitor.  Here are a couple of scripts that, embedded in a job, will better help you.  I need to look into adding special alerts for replication.  The main change is the addition of snapshot detection  - we have missed issues because it somehow falls offline and doesn't notify that the replication needs to be snapshotted.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;IF OBJECT_ID('tempdb.dbo.##replication_command_count') IS NOT NULL &lt;/div&gt;&lt;div&gt;    DROP TABLE ##replication_command_count&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;SELECT SUM(UndelivCmdsInDistDB) AS UndelivCmdsInDistDB,&lt;/div&gt;&lt;div&gt;  MSdistribution_agents.NAME,&lt;/div&gt;&lt;div&gt;  MSdistribution_agents.publication,&lt;/div&gt;&lt;div&gt;  subscriber_id,&lt;/div&gt;&lt;div&gt;  subscriber_db &lt;/div&gt;&lt;div&gt;INTO ##replication_command_count  &lt;/div&gt;&lt;div&gt;FROM MSDistribution_Status&lt;/div&gt;&lt;div&gt;INNER JOIN MSdistribution_agents&lt;/div&gt;&lt;div&gt;ON MSDistribution_Status.agent_id = MSdistribution_agents.id&lt;/div&gt;&lt;div&gt;WHERE UndelivCmdsInDistDB &gt; 0  --show only those that are backed up&lt;/div&gt;&lt;div&gt;AND subscriber_id &gt; 0 --negative subscriber IDs are for those that&lt;/div&gt;&lt;div&gt;   --always have a snapshot ready&lt;/div&gt;&lt;div&gt;   AND MSdistribution_agents.NAME NOT LIKE '%someserverthatthrowserrors%'&lt;/div&gt;&lt;div&gt;GROUP BY MSdistribution_agents.NAME, MSdistribution_agents.publication,&lt;/div&gt;&lt;div&gt; subscriber_id, subscriber_db&lt;/div&gt;&lt;div&gt;ORDER BY MSdistribution_agents.NAME, MSdistribution_agents.publication,&lt;/div&gt;&lt;div&gt; subscriber_id, subscriber_db&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;--delete from stuff we don't care about; refinement of the IF below.&lt;/div&gt;&lt;div&gt;delete from ##replication_command_count &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;where publication = 'a_busy_publication' &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;and UndelivCmdsInDistDB &lt;&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;IF (SELECT MAX(UndelivCmdsInDistDB) FROM ##replication_command_count WHERE publication NOT IN ('a_busy_publication', 'a_busy_publication')) &gt; 20 &lt;/div&gt;&lt;div&gt;OR (SELECT MAX(UndelivCmdsInDistDB) FROM ##replication_command_count WHERE publication = 'a_busy_publication') &gt; 20 &lt;/div&gt;&lt;div&gt;OR (SELECT MAX(UndelivCmdsInDistDB) FROM ##replication_command_count WHERE publication = 'a_busy_publication') &gt; 20 &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;EXEC msdb.dbo.sp_send_dbmail&lt;/div&gt;&lt;div&gt;    @profile_name = 'DBA',&lt;/div&gt;&lt;div&gt;    @recipients = 'dev@null.com',&lt;/div&gt;&lt;div&gt;    @subject = 'Replication is backed up on REPL server'&lt;/div&gt;&lt;div&gt;   ,@query = 'select left(publication,20), convert(varchar(9),UndelivCmdsInDistDB), left(name,90) from ##replication_command_count where UndelivCmdsInDistDB &gt;20'&lt;/div&gt;&lt;div&gt;   ,@query_result_header = 0&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;----------------------------&lt;/div&gt;&lt;div&gt;Script 2 -- looking for errors.&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;IF OBJECT_ID('tempdb.dbo.##replication_errors') IS NOT NULL &lt;/div&gt;&lt;div&gt;    DROP TABLE ##replication_errors&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; SELECT &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;errors.agent_id, &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;errors.last_time, &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;agentinfo.name, &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;agentinfo.publication, &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;agentinfo.subscriber_db,&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;error_messages.comments AS ERROR&lt;/div&gt;&lt;div&gt;INTO ##replication_errors&lt;/div&gt;&lt;div&gt;FROM &lt;/div&gt;&lt;div&gt;--find our errors; note that a runstatus 3 can be the last message, even if it's actually idle and good&lt;/div&gt;&lt;div&gt;(SELECT agent_id, MAX(TIME) AS last_time FROM distribution.dbo.MSdistribution_history with (nolock)&lt;/div&gt;&lt;div&gt;WHERE (runstatus IN (3,5,6) AND comments NOT LIKE '%were delivered.' AND comments NOT LIKE '&lt;stats%')&lt;/div&gt;&lt;div&gt;or (runstatus = 4 and comments like 'The initial snapshot%is not yet available.') GROUP BY agent_id) errors&lt;/div&gt;&lt;div&gt;FULL outer JOIN &lt;/div&gt;&lt;div&gt;(SELECT agent_id, MAX(TIME) AS last_time FROM distribution.dbo.MSdistribution_history with (nolock)&lt;/div&gt;&lt;div&gt;WHERE (runstatus IN (1,2,4) and comments not like 'The initial snapshot %is not yet available.') &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;		&lt;/span&gt;OR comments LIKE '%were delivered.' GROUP BY agent_id&lt;/div&gt;&lt;div&gt;) clean&lt;/div&gt;&lt;div&gt; ON errors.agent_id = clean.agent_id &lt;/div&gt;&lt;div&gt;--grab the agent information&lt;/div&gt;&lt;div&gt; LEFT OUTER JOIN distribution.dbo.MSdistribution_agents agentinfo&lt;/div&gt;&lt;div&gt;ON agentinfo.id = errors.agent_id&lt;/div&gt;&lt;div&gt;--and the actual message we'd see in the monitor&lt;/div&gt;&lt;div&gt;LEFT OUTER JOIN distribution.dbo.MSdistribution_history error_messages&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;ON error_messages.agent_id = errors.agent_id AND error_messages.time = errors.last_time&lt;/div&gt;&lt;div&gt;where errors.last_TIME &gt; ISNULL(clean.last_time,'20100101')&lt;/div&gt;&lt;div&gt;AND comments NOT LIKE '%TCP Provider%'&lt;/div&gt;&lt;div&gt;AND comments NOT LIKE '%Delivering replicated transactions%'&lt;/div&gt;&lt;div&gt;AND name NOT LIKE '%suckyservername%'&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;stats%'&gt;&lt;div&gt;IF (SELECT COUNT(*) FROM ##replication_errors) &gt; 0 &lt;/div&gt;&lt;div&gt;EXEC msdb.dbo.sp_send_dbmail&lt;/div&gt;&lt;div&gt;    @profile_name = 'dba',&lt;/div&gt;&lt;div&gt;    @recipients = 'dev@null.com',&lt;/div&gt;&lt;div&gt;    @subject = 'Replication errors on REPL server'&lt;/div&gt;&lt;div&gt;   ,@query = 'select * from ##replication_errors'&lt;/div&gt;&lt;div&gt;   ,@query_result_header = 0&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;DROP TABLE ##replication_errors&lt;/div&gt;&lt;/stats%'&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-611453737374711180?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/611453737374711180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=611453737374711180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/611453737374711180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/611453737374711180'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/10/replication-better-alternative-to.html' title='[Replication] Better alternative to Replication Monitor'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5631982379978536238</id><published>2010-10-08T16:58:00.002-05:00</published><updated>2010-10-08T16:59:31.819-05:00</updated><title type='text'>[Replication] Simple replication to find an issue</title><content type='html'>&lt;div&gt;Say you get a message like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Cannot insert duplicate key row in object 'dbo.yourtable' with unique index 'yourtable_Index'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Run this:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;/div&gt;&lt;div&gt;--run from wherever the table exists&lt;/div&gt;&lt;div&gt;DECLARE @publisher_database_id INT, @article_id int&lt;/div&gt;&lt;div&gt;SELECT @publisher_database_id = id FROM distribution.dbo.MSpublisher_databases where publisher_db = DB_NAME()&lt;/div&gt;&lt;div&gt;SELECT @article_id = artid FROM dbo.sysarticles WHERE dest_table = 'yourtable'&lt;/div&gt;&lt;div&gt;EXEC distribution..sp_browsereplcmds @publisher_database_id = @publisher_database_id, @article_id = @article_id&lt;/div&gt;&lt;div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5631982379978536238?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5631982379978536238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5631982379978536238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5631982379978536238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5631982379978536238'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/10/replication-simple-replication-to-find.html' title='[Replication] Simple replication to find an issue'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6843733230256975093</id><published>2010-08-17T15:19:00.003-05:00</published><updated>2010-08-17T15:21:44.109-05:00</updated><title type='text'>[QA] Linked server for QA - faking a prod server</title><content type='html'>In case you use linked server a lot.  This creates a linked server named ServerB that actually connects to the local server.  I needed it for testing, as a lot of code references linked servers (no comments on _that_, please)&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;EXEC sp_addlinkedserver &lt;/div&gt;&lt;div&gt;   @server = 'ServerB', &lt;/div&gt;&lt;div&gt;   @srvproduct = '',&lt;/div&gt;&lt;div&gt;   @provider = 'MSDASQL',&lt;/div&gt;&lt;div&gt;   @provstr = 'DRIVER={SQL Server};SERVER=(local);Trusted_Connection=True;'&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6843733230256975093?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6843733230256975093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6843733230256975093' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6843733230256975093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6843733230256975093'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/08/qa-linked-server-for-qa-faking-prod.html' title='[QA] Linked server for QA - faking a prod server'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4997678497802313338</id><published>2010-08-13T10:25:00.003-05:00</published><updated>2010-08-13T10:28:36.669-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='command-line'/><category scheme='http://www.blogger.com/atom/ns#' term='administration'/><category scheme='http://www.blogger.com/atom/ns#' term='switches'/><title type='text'>[Tricks] Single-user-mode with a twist</title><content type='html'>Had to restart a SQL Server in single-user mode.  Two problems.  One, the configuration was preventing it from starting properly, and there were automatic processes connecting to that single user. &lt;br /&gt;&lt;br /&gt;The normal way to do it is:&lt;br /&gt;sqlservr -m   &lt;br /&gt;(that's single user mode)&lt;br /&gt;but for this we needed the configurations to not screw us up.&lt;br /&gt;sqlservr -f&lt;br /&gt;and we needed to make sure that it was only us connecting.&lt;br /&gt;sqlservr -f"sqlcmd"&lt;br /&gt;(Yes, you could also do sql server management studio)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4997678497802313338?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4997678497802313338/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4997678497802313338' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4997678497802313338'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4997678497802313338'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/08/tricks-single-user-mode-with-twist.html' title='[Tricks] Single-user-mode with a twist'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4740175836491356745</id><published>2010-06-28T08:38:00.001-05:00</published><updated>2010-06-28T08:38:46.997-05:00</updated><title type='text'>[Code] Xtype definitions</title><content type='html'>&lt;pre&gt;&lt;div&gt;&lt;div&gt;'C' =  CHECK constraint &lt;/div&gt;&lt;div&gt;'D' =  Default or DEFAULT constraint  &lt;/div&gt;&lt;div&gt;'F' =  FOREIGN KEY constraint  &lt;/div&gt;&lt;div&gt;'L' =  Log  &lt;/div&gt;&lt;div&gt;'FN' =  Scalar function  &lt;/div&gt;&lt;div&gt;'IF' =  In-lined table-function  &lt;/div&gt;&lt;div&gt;'P' =  Stored procedure  &lt;/div&gt;&lt;div&gt;'PK' =  PRIMARY KEY constraint (type is K)  &lt;/div&gt;&lt;div&gt;'RF' =  Replication filter stored procedure &lt;/div&gt;&lt;div&gt;'S' =  System table  &lt;/div&gt;&lt;div&gt;'TF' =  Table function  &lt;/div&gt;&lt;div&gt;'TR' =  Trigger  &lt;/div&gt;&lt;div&gt;'U' =  User table  &lt;/div&gt;&lt;div&gt;'UQ' =  UNIQUE constraint (type is K)  &lt;/div&gt;&lt;div&gt;'V' =  View  &lt;/div&gt;&lt;div&gt;'X' =  Extended stored procedure &lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4740175836491356745?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4740175836491356745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4740175836491356745' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4740175836491356745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4740175836491356745'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/06/code-xtype-definitions.html' title='[Code] Xtype definitions'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-9117503541985950772</id><published>2010-06-07T14:30:00.004-05:00</published><updated>2010-06-07T14:44:46.088-05:00</updated><title type='text'>[Ugly] Drop a view using Dynamic SQL</title><content type='html'>There's a time and a place for Dynamic SQL.  This is, as far as I know, one of them.&lt;br /&gt;&lt;br /&gt;I need to ensure a view (standard_view) is dropped in a particular database (My2008DB).  That database is named for the year, so it's different each year.  I can't use sp_msforeachdb for a particular (&lt;b&gt;REDACTED&lt;/b&gt;) reason.  You probably don't have that problem, I do. &lt;br /&gt;&lt;br /&gt;So, best I can tell, the way to do it is to call sp_executesql from within the context of that other database.  And since I have to execute the code to verify the drop before doing it, we wind up with this particularly ugly piece of code.  Yes, we're 3 layers deep.  sp_executesql calls My2008DB.dbo.sp_executesql, which calls the actual drop code.  And yes, it works, at least on SQL Server 2005.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;DECLARE @date SMALLDATETIME, @drop_view VARCHAR(8000) ,@SQLString nvarchar(500), @ParmDefinition nvarchar(500)&lt;br /&gt;select @date = '5/15/2008'&lt;br /&gt;&lt;br /&gt;--DROP VIEW.  Need to look in the DB, determined dynamically via the @date&lt;br /&gt;SELECT @drop_view = 'if object_id(''My' + CONVERT(CHAR(4),@date, 112) + 'DB..standard_view'') is not null&lt;br /&gt;    drop view standard_view'&lt;br /&gt;&lt;br /&gt;--now we create a "wrapper" to run in the correct database context.&lt;br /&gt;SELECT @sqlstring = N'execute My' + CONVERT(CHAR(4),@date,112) + 'DB.dbo.sp_executesql @mysql', @ParmDefinition = N'@mysql nvarchar(max)'&lt;br /&gt;&lt;br /&gt;--execute in our dynamic db&lt;br /&gt;EXECUTE sp_executesql @SQLString, @ParmDefinition,&lt;br /&gt;@mysql = @drop_view&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-9117503541985950772?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/9117503541985950772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=9117503541985950772' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9117503541985950772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9117503541985950772'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/06/ugly-drop-view-using-dynamic-sql.html' title='[Ugly] Drop a view using Dynamic SQL'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3090737701790539736</id><published>2010-05-25T16:46:00.001-05:00</published><updated>2010-05-25T16:48:04.370-05:00</updated><title type='text'>[Tips] HOW TO find page splits by reading the transaction log</title><content type='html'>http://strictlysql.blogspot.com/2009/10/identifying-page-splits.html&lt;br /&gt;&lt;br /&gt;There are two tricks in here.  The first is using ::fn_dblog (undocumented function) to read the transaction log for a database.&lt;br /&gt;The second is pulling out the delete messages involved in a page split and using that to determine where the splits are occurring.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select AllocUnitName, count([AllocUnitName]) [Splits]&lt;br /&gt;from ::fn_dblog(null, null)&lt;br /&gt;where Operation = N'LOP_DELETE_SPLIT'&lt;br /&gt;    and parsename(AllocUnitName,3) &lt;&gt; 'sys'&lt;br /&gt;group by AllocUnitName&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3090737701790539736?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://strictlysql.blogspot.com/2009/10/identifying-page-splits.html' title='[Tips] HOW TO find page splits by reading the transaction log'/><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3090737701790539736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3090737701790539736' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3090737701790539736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3090737701790539736'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/05/tips-how-to-find-page-splits-by-reading.html' title='[Tips] HOW TO find page splits by reading the transaction log'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-9203274353141275167</id><published>2010-05-25T16:29:00.004-05:00</published><updated>2010-06-15T14:47:30.869-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dates'/><category scheme='http://www.blogger.com/atom/ns#' term='tuning'/><category scheme='http://www.blogger.com/atom/ns#' term='date'/><title type='text'>[Tuning] Getting only the DATE from a datetime</title><content type='html'>Many ways to handle dates, and most time I don't think about it - then came across a gigantic thread over two years that discussed it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Comparing dates. Traditionally, for simplicity, to mark particular dates, I've used convert(char(8),a_date_field,12), but it’s non-SARGable, and not terribly efficient.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Looking online I found a couple alternatives, though they’re mostly useful when having to deal with large tables.&lt;br /&gt;&lt;br /&gt;http://blog.sqlauthority.com/2008/10/18/sql-server-retrieve-select-only-date-part-from-datetime-best-practice-part-2/&lt;br /&gt;&lt;br /&gt;For SQL Server 2008 it's pretty simple:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT  cast(GETDATE() as date)&lt;br /&gt;or&lt;br /&gt;SELECT CONVERT(date,GETDATE())&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;(date is a new datatype that only stores the date, and is 3 bytes in size)&lt;br /&gt;&lt;br /&gt;For SQL Server 2005, there seem to be two options. Naturally, neither is SARGable from what I’ve seen.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT CONVERT (datetime, FLOOR(CONVERT (float, a_field_name)))&lt;br /&gt;and&lt;br /&gt;SELECT DATEADD ( DAY, DATEDIFF(DAY, 0, a_field_name), 0)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The first one performs math on the internally-stored FLOAT value of the datetime - right now, for instance, is 40315.37003125, where the whole number is the day and the fraction is the time. (Note that you can’t cheat and use INT; it can round up during the conversion).&lt;br /&gt;&lt;br /&gt;The second one does date manipulation - there's a whole article online about using datediff and dateadd and the like to get the first day of the month, the first day of last month, etc, etc.&lt;br /&gt;&lt;br /&gt;From what I’ve seen online, the FLOOR option can be slightly faster than the DATEADD, but either is considerably faster than CONVERT(char(8)).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-9203274353141275167?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/9203274353141275167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=9203274353141275167' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9203274353141275167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9203274353141275167'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/05/tuning-getting-onlyt-date-from-datetime.html' title='[Tuning] Getting only the DATE from a datetime'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7929289761926354141</id><published>2010-05-24T15:11:00.002-05:00</published><updated>2010-05-24T15:14:33.334-05:00</updated><title type='text'>[Tuning] Disk usage, redux</title><content type='html'>Here's a slightly different version of an earlier query, that tells you how much IO each database is getting.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This one is by database, not by file - did this since it makes dealing with TEMPDB easier.  So  you can't use it for physical file IO - that's the other version.  And it's in GB, since that's our issue.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;SELECT &lt;/div&gt;&lt;div&gt;  sysdb.name AS name, &lt;/div&gt;&lt;div&gt;  master_files.type_desc,&lt;/div&gt;&lt;div&gt;  vfs.sample_ms,&lt;/div&gt;&lt;div&gt;  SUM(vfs.num_of_bytes_written)/1024/1024/1024 AS GB_written, &lt;/div&gt;&lt;div&gt;  SUM(num_of_bytes_read)/1024/1024/1024 AS GB_read, &lt;/div&gt;&lt;div&gt;  SUM((num_of_bytes_read + num_of_bytes_written))/1024/1024/1024 AS GB_total_IO,&lt;/div&gt;&lt;div&gt;  SUM(size_on_disk_bytes)/1024/1024/1024 AS Size_in_GB&lt;/div&gt;&lt;div&gt;FROM sys.dm_io_virtual_file_stats(null, null) vfs&lt;/div&gt;&lt;div&gt;INNER JOIN MASTER.sys.master_files &lt;/div&gt;&lt;div&gt; ON vfs.[file_id] = master_files.[file_id] &lt;/div&gt;&lt;div&gt; AND vfs.database_id = master_files.database_id&lt;/div&gt;&lt;div&gt;INNER JOIN master..sysdatabases sysdb ON vfs.database_id = sysdb.dbid&lt;/div&gt;&lt;div&gt;GROUP BY &lt;/div&gt;&lt;div&gt;  sysdb.name, master_files.type_desc,&lt;/div&gt;&lt;div&gt;--  master_files.physical_name, &lt;/div&gt;&lt;div&gt;  vfs.sample_ms&lt;/div&gt;&lt;div&gt;ORDER BY  SUM((num_of_bytes_read + num_of_bytes_written))/1024/1024/1024 desc&lt;/div&gt;&lt;div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7929289761926354141?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7929289761926354141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7929289761926354141' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7929289761926354141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7929289761926354141'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/05/tuning-disk-usage-redux.html' title='[Tuning] Disk usage, redux'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6996195763058745975</id><published>2010-05-13T16:29:00.003-05:00</published><updated>2010-05-13T16:35:49.346-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql 2008'/><title type='text'>[Tuning] Filtered indexes...and filtered statistics.</title><content type='html'>So, SQL Server (starting with 2008) now has Filtered Indexes.  Which are great - since an index is basically just a copy of the data, why copy particular fields for the entire table when you only query particular subsets of data?  Add a WHERE clause to your index, and now you're querying subsets of data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However, while reading up on it I came across this:&lt;br /&gt;http://msdn.microsoft.com/en-us/library/ms190397.aspx&lt;br /&gt;which introduces filtered statistics(!).&lt;br /&gt;&lt;br /&gt;Instead of &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE STATISTICS BikeWeights&lt;br /&gt;    ON Production.Product (Weight)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;which would give you stats for the entire range, do this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE STATISTICS BikeWeights&lt;br /&gt;    ON Production.Product (Weight)&lt;br /&gt;WHERE ProductSubcategoryID IN (1,2,3)&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;which will only compute statistics for that subset of data.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6996195763058745975?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6996195763058745975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6996195763058745975' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6996195763058745975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6996195763058745975'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/05/tuning-filtered-indexesand-filtered.html' title='[Tuning] Filtered indexes...and filtered statistics.'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3752714170079862038</id><published>2010-05-07T15:03:00.004-05:00</published><updated>2010-05-07T15:37:21.665-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='database mail'/><category scheme='http://www.blogger.com/atom/ns#' term='sp_send_dbmail'/><title type='text'>[Files] Tricking Excel with SP_SEND_DBMAIL</title><content type='html'>My pain = your gain.  I needed to automate a process to send a file to an end user.  They would just double-click it and have it open in Excel.  The problem was due to a field with a leading zero, which Excel will simply lop off.  One way around is to create an XML file.  I've done that before, but this is simpler and ideal for this situation.  The syntax and parameters are important.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;EXEC msdb.dbo.sp_send_dbmail @profile_name = 'youremailprofile', &lt;br /&gt;    @recipients = 'dev@null.com', &lt;br /&gt;    @subject = 'Here is your file pull done',&lt;br /&gt;    @query = 'SELECT a, b, convert(varchar(12),c) as C, char(61) + char(34) + leadingzerossuck + char(34) as leadingzerossuck FROM mytemptable', &lt;br /&gt;    @attach_query_result_as_file = 1, &lt;br /&gt;    @query_attachment_filename = 'yourfilename.csv', &lt;br /&gt;    @query_result_separator = ' ', -- tab&lt;br /&gt;    @exclude_query_output = 1, &lt;br /&gt;    @append_query_error = 1&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3752714170079862038?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3752714170079862038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3752714170079862038' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3752714170079862038'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3752714170079862038'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/05/files-tricking-excel-with-spsenddbmail.html' title='[Files] Tricking Excel with SP_SEND_DBMAIL'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5016065010713122212</id><published>2010-04-28T10:58:00.004-05:00</published><updated>2010-05-05T17:30:15.176-05:00</updated><title type='text'>Table Partitioning</title><content type='html'>Working on learning partitioned tables.  We've done it, and it works really well for us, but it's time to start getting clever.&lt;br /&gt;&lt;br /&gt;Was reading this, which is an excellent primer:&lt;br /&gt;http://www.simple-talk.com/sql/database-administration/partitioned-tables-in-sql-server-2005/&lt;br /&gt;&lt;br /&gt;A few rules I learned the hard way.  I deliberately did it from scratch in hopes that I'd remember it better - what to do, what not to do.  In particular, working on switching tables &lt;span style="font-weight:bold;"&gt;into&lt;/span&gt; partitions (our current stuff switches out, not in)&lt;br /&gt;&lt;br /&gt;* clustered key of the table you're switching in has to be on the same filegroup as the partitioned table.&lt;br /&gt;* indexes have to match.  ALL of them.&lt;br /&gt;* indexes are NOT on the partition scheme&lt;br /&gt;* only one constraint (below)&lt;br /&gt;* Add a constraint to make sure the partitioned key is within the partition range (order_date &gt;='20100428' and order_date &lt;'20100429' and order_date is not null)&lt;br /&gt;* Then, SPLIT the range (code below), and SWITCH the table in.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;    ALTER PARTITION SCHEME ps_daily NEXT USED your_partitioned_fg&lt;br /&gt;    &lt;br /&gt;    ALTER PARTITION FUNCTION pf_daily() SPLIT RANGE ( @Day) --@day is one day larger than current max date&lt;br /&gt;&lt;br /&gt;    ALTER TABLE orders_stg SWITCH TO dbo.orders PARTITION 200&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now, what if you need to add an old day in?  You have up to 5/4/2010, but need 5/3?&lt;br /&gt;&lt;pre&gt;ALTER PARTITION SCHEME [ps_daily] NEXT USED your_partitioned_fg&lt;br /&gt;ALTER PARTITION FUNCTION [pf_daily] () SPLIT RANGE (N'2010-05-03')&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5016065010713122212?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5016065010713122212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5016065010713122212' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5016065010713122212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5016065010713122212'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/table-partitioning.html' title='Table Partitioning'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6521932336269135723</id><published>2010-04-21T21:03:00.003-05:00</published><updated>2010-05-29T23:40:12.921-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xp'/><category scheme='http://www.blogger.com/atom/ns#' term='printing'/><title type='text'>[Offtopic] How to print to a networked Laserwriter (XP)</title><content type='html'>Needed this desperately, so posting it here.  Worked like a charm for me.  Thanks to this Anthony Duplessis chap, whomever he is.  Thanks! &lt;br /&gt;&lt;br /&gt;Note that once you get to the test page print the first time, you're NOT DONE, so uncheck it.  Follow the directions, step by step.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;(found some screenshots at: http://blog.eppesconsulting.com/2009/05/05/AppleLaserWriter16600PSOnWindowsVista.aspx)&lt;br /&gt;&lt;/h3&gt;&lt;h3&gt;Printing to an Apple Laserwriter 16/600 using IP from a Win 2K and Win XP&lt;br /&gt;client.&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;The following procedure explains how to configure desktop clients,&lt;br /&gt;running Windows 2000 or Windows XP, without installing the appletalk&lt;br /&gt;protocol.&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Select Start/Settings/Printers.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Double-click 'Add Printer' icon. Click the 'Next' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select 'Local printer' bullet.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Uncheck 'Automatically detect and install my Plug and Play printer' box.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Click the 'Next' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select 'Create a new port' bullet.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select 'Standard TCP/IP Port' from the drop-down arrow list.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Click the 'Next' button. Click the 'Next' button again.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Enter the appropriate IP address of the printer. Click the 'Next' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select 'Apple Network Printer' from the drop-down arrow list in the 'device&lt;br /&gt;type' field.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Click the 'Next' button. Click the 'Finish' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select the appropriate printer driver. Click the 'Next' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Accept or modifiy the suggested printer name. Click the 'Next' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select the 'Yes' bullet if you want to make this printer the default, or&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select the 'No' bullet if you do not want to make this printer the default. &lt;/li&gt;&lt;li&gt;Click the 'Next' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select the 'Do not share this printer' bullet. Click the 'Next' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select the 'No' bullet so that a test page is not printed.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Click the 'Finish' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Open the Printers folder.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select and Right-click the apple printer. Select 'properties' from the&lt;br /&gt;context menu.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select the ‘Ports’ tab and then the ‘Configure Ports’ button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Verify that the 'LPR' bullet is selected in the Protocol section.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Enter ‘lp’ in the 'Queue Name' field.  [Note: that's LP, lowercase, not IP]&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Click to select the 'LPR Byte Count Enabled' box.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Click the 'OK' button.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Select the ‘General’ tab and then Click the 'Print Test Page' button.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Anthony Duplessis.&lt;br /&gt;LIFE is the toughest teacher of all.&lt;br /&gt;First, you get the test.&lt;br /&gt;Then, you're taught the lesson.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6521932336269135723?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://lyra2.concordia.ca/docushare/dsweb/Get/Document-276/FYI__Printing_to_Apple_Laserwriter.html' title='[Offtopic] How to print to a networked Laserwriter (XP)'/><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6521932336269135723/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6521932336269135723' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6521932336269135723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6521932336269135723'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/offtopic-how-to-print-to-networked.html' title='[Offtopic] How to print to a networked Laserwriter (XP)'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5349448180553066399</id><published>2010-04-21T10:18:00.003-05:00</published><updated>2010-04-21T10:32:41.289-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fail'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>[Powershell] What a piece of $#!+</title><content type='html'>Wow.  So, Powershell is Microsoft's idea of UNIX: a command-line shell.  Unfortunately, more than a bit half-assed, even with version 2.0.&lt;br /&gt;&lt;br /&gt;I grabbed a module to allow UI scripting.  Here's what I have to do in order to run a simple Hello World with it:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;download Powershell&lt;br /&gt;&lt;li&gt;download PowerShellPack&lt;br /&gt;&lt;li&gt;install both&lt;br /&gt;&lt;li&gt;start Powershell&lt;br /&gt;&lt;li&gt;Set-ExecutionPolicy Unrestricted (so I can run scripts)&lt;br /&gt;&lt;li&gt;Import-Module PowerShellPack (needs to be done each time)&lt;br /&gt;&lt;li&gt;Hit ctrl+c because it's going to ask me once per script, and there are about 50. And, each time I run powershell.&lt;br /&gt;&lt;li&gt;Set-ExecutionPolicy Bypass (hello, usefulness, goodbye protection. Grrrr)&lt;br /&gt;&lt;li&gt;Import-Module PowerShellPack  &lt;br /&gt;&lt;li&gt;Import-Module WPK&lt;br /&gt;&lt;li&gt;New-Label "Hello, World" -Show&lt;br /&gt;&lt;li&gt;get odd error: Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI components require this."&lt;br /&gt;&lt;li&gt;read blog&lt;br /&gt;&lt;li&gt;change shortcut to Powershell to add -STA&lt;br /&gt;&lt;li&gt;restart Powershell&lt;br /&gt;&lt;li&gt;Import-Module PowerShellPack  &lt;br /&gt;&lt;li&gt;Import-Module WPK&lt;br /&gt;&lt;li&gt;New-Label "Hello, World" -Show&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;Success!&lt;br /&gt;&lt;br /&gt;WTF.  Am I a bad person if I wonder why the hell I have to jump through all these hoops?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5349448180553066399?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5349448180553066399/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5349448180553066399' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5349448180553066399'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5349448180553066399'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/powershell-what-piece-of-1.html' title='[Powershell] What a piece of $#!+'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-9207780833092730079</id><published>2010-04-19T17:03:00.004-05:00</published><updated>2010-04-19T17:19:08.636-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='free space'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2008'/><category scheme='http://www.blogger.com/atom/ns#' term='partitioned tables'/><title type='text'>[Partitioned Tables] Does the clustered index take up space if referenced?</title><content type='html'>Setting up a new partitioned table with associated indexes.  I was curious whether the adding the partitioning key to any index would cause the index to grow - I expected not, but you never know.&lt;br /&gt;&lt;br /&gt;Our clustered index:&lt;br /&gt;&lt;pre&gt;create unique clustered index clustind_pk on ourtable (id, partitionedkey)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Our test indexes:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;create nonclustered index A on ourtable (partitionedkey, fielda)&lt;br /&gt;on ps_daily (partitionedkey)&lt;br /&gt;&lt;br /&gt;create nonclustered index B on ourtable (fielda)&lt;br /&gt;on ps_daily (partitionedkey)&lt;br /&gt;&lt;br /&gt;create nonclustered index C on ourtable (fielda) include (partitionedkey)&lt;br /&gt;on ps_daily (partitionedkey)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then used this query to check a particular partition for all 3 indexes (thanks to Simon Sabin).  Each was within 1 page of the others.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select OBJECT_NAME(p.object_id ), i.name,p.*&lt;br /&gt;from sys.dm_db_partition_stats p&lt;br /&gt;join sys.indexes i on i.object_id = p.object_id and i.index_id = p.index_id&lt;br /&gt;WHERE p.object_id = 2071234567&lt;br /&gt;AND partition_number = 28 &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-9207780833092730079?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/9207780833092730079/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=9207780833092730079' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9207780833092730079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9207780833092730079'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/partitioned-tables-does-clustered-index.html' title='[Partitioned Tables] Does the clustered index take up space if referenced?'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5811616482222493771</id><published>2010-04-16T16:49:00.006-05:00</published><updated>2010-05-20T15:07:17.292-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xp_cmdshell'/><category scheme='http://www.blogger.com/atom/ns#' term='setup'/><title type='text'>[Install] Restarting your SQL service within SQL</title><content type='html'>DOES NOT WORK.  Not deleting the post below in case someone comes across this.  We wound up using powershell instead.  WMI-process.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;We're building a Powershell script to automatically build out our machines.  Not just the install, but the full config: backup jobs, maintenance, tempdb files, model, etc, etc.&lt;br /&gt;&lt;br /&gt;So, we need to bounce the service so that all the tempdb files get created, the agent knows the database config, etc.&lt;br /&gt;&lt;br /&gt;The trick isn't stopping the server: "net stop mssqlserver" will do that.  The real trick is starting it back up, once you've shut down the SQL server.  Since our solution is all done via SQLCMD we needed a way, within SQL itself, to start back up.&lt;br /&gt;&lt;br /&gt;Our secret is the ampersand; when the command line interpreter catches it, it views it as you hitting the "Enter" key. So, even though the SQL service is off, the job continues.&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;pre&gt;&lt;i&gt;&lt;br /&gt;declare @sql varchar(8000)&lt;br /&gt;select @sql = 'net stop SQLSERVERAGENT &amp;amp; ping -n 15 127.0.0.1 &amp;amp; '&lt;br /&gt;+ 'net stop MSSQLSERVER &amp;amp; ping -n 15 127.0.0.1 &amp;amp; '&lt;br /&gt;+ 'net start MSSQLSERVER &amp;amp; ping -n 15 127.0.0.1 &amp;amp; '&lt;br /&gt;+ 'net start SQLSERVERAGENT'&lt;br /&gt;EXEC xp_cmdshell (@sql)&lt;/i&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5811616482222493771?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5811616482222493771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5811616482222493771' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5811616482222493771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5811616482222493771'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/install-restarting-your-sql-service.html' title='[Install] Restarting your SQL service within SQL'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-518625434510203135</id><published>2010-04-13T14:46:00.004-05:00</published><updated>2010-04-13T15:04:13.108-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><title type='text'>[Replication] Finding the commands that are breaking</title><content type='html'>Here's a simple one I had to do today.  Documenting since I hate having to dig through the help files.&lt;br /&gt;&lt;br /&gt;On your distributor:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT * FROM distribution.dbo.MSpublisher_databases&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That gives you a list of the source databases from the publishers.  You want the ID field.&lt;br /&gt;&lt;br /&gt;Now, &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;use distribution&lt;br /&gt;go&lt;br /&gt;sp_browsereplcmds @publisher_database_id = 13&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;will list all the waiting commands.  The command field is the actual command, while the article_id can be gotten from running the following on the publisher:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sp_helparticle @publication = 'your_publication_name'&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-518625434510203135?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/518625434510203135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=518625434510203135' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/518625434510203135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/518625434510203135'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/replication-finding-commands-that-are.html' title='[Replication] Finding the commands that are breaking'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5883496043191581422</id><published>2010-04-12T08:48:00.003-05:00</published><updated>2010-04-12T09:00:14.229-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sp3'/><category scheme='http://www.blogger.com/atom/ns#' term='ddl triggers'/><category scheme='http://www.blogger.com/atom/ns#' term='service pack'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Sp3] Another reason not to use DDL Triggers</title><content type='html'>So, I've already posted about my issues using DDL triggers with Replication (http://thebakingdba.blogspot.com/2009/12/replication-and-ddl-triggers-do-not-mix.html). Well, it looks like it may have contributed to issues with an active/active cluster upgrade (2005 SP3).&lt;br /&gt;&lt;br /&gt;Installing the patch on the first active node, we got a failure on the upgrade.  The error message?  "Target string size is too small to represent the XML instance".  But, oddly enough, the passive (which is upgraded first) worked and was on SP3.  &lt;br /&gt;&lt;br /&gt;So we deleted the trigger (which, interestingly enough, showed that replication uses DDL triggers - which makes sense but I hadn't thought about), and ran it again. &lt;br /&gt;&lt;br /&gt;It failed again, but this time because the passive node wasn't upgraded.  Check both - and yes, SP3.  Roll back and forth, everything looks good.  A sucky upgrade, but we got through it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5883496043191581422?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5883496043191581422/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5883496043191581422' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5883496043191581422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5883496043191581422'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/sp3-another-reason-not-to-use-ddl.html' title='[Sp3] Another reason not to use DDL Triggers'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5760055636992032070</id><published>2010-04-09T04:10:00.004-05:00</published><updated>2010-04-09T04:16:21.540-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='free space'/><category scheme='http://www.blogger.com/atom/ns#' term='SPARSE'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2008'/><title type='text'>[Tuning] SPARSE varchar calculation</title><content type='html'>Since it doesn't appear that anybody has done this before, here you go.  I've been comparing SPARSE to COMPRESSION, and for my particular tables, I got 25% space savings via parse.  However, I got 40% savings from ROW compression, and 50% savings from PAGE.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Standard&lt;br /&gt;=(Number_Of_Rows*(Average_Varchar_Length+2)&lt;br /&gt;*((100-Percent_Null)/100))&lt;br /&gt;+(Number_Of_Rows*(Percent_Null/100*2))&lt;br /&gt;&lt;br /&gt;Sparse:&lt;br /&gt;=(Number_Of_Rows*(Average_Varchar_Length+4))*((100-Percent_Null)/100)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next up is comparing the CPU for each option.  Nobody's really talked about whether the compression is symmetric or asymmetric, though I'd hope it's asymmetric (aka easier to decompress than compress, in this case)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5760055636992032070?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5760055636992032070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5760055636992032070' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5760055636992032070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5760055636992032070'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/04/tuning-sparse-varchar-calculation.html' title='[Tuning] SPARSE varchar calculation'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7948903799225522070</id><published>2010-03-29T17:20:00.003-05:00</published><updated>2010-03-29T17:23:41.478-05:00</updated><title type='text'>[Jobs] Quick &amp; Dirty - is the job running?</title><content type='html'>Needed a simple piece of code to tell me if a job was running or not.  Several ways to do it, but this is the simplest and probably dirtiest.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;EXECUTE sp_get_composite_job_info @job_id = 'B74856BF-3326-4B9F-B3A6-B1D182E1F300', @execution_status = 1&lt;br /&gt;&lt;br /&gt;IF @@rowcount = 1&lt;br /&gt;PRINT 'job running'&lt;br /&gt;else print 'nope, not'&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7948903799225522070?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7948903799225522070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7948903799225522070' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7948903799225522070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7948903799225522070'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/03/jobs-quick-dirty-is-job-running.html' title='[Jobs] Quick &amp; Dirty - is the job running?'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6519686171349120370</id><published>2010-03-26T14:04:00.001-05:00</published><updated>2010-03-26T14:06:19.163-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='undocumented'/><title type='text'>sp_MSforeachDB - skipping databases</title><content type='html'>SP_MSforeachDB is awesome - an easy way to walk through every database and run some code.&lt;br /&gt;&lt;br /&gt;But what about databases you don't _want_ to touch?&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sp_MSforeachdb 'if ''?'' NOT IN (''tempdb'',''model'',''a'',''b'',''c'') &lt;br /&gt;--sp_updatestats required after reorg, but not after rebuild&lt;br /&gt;begin &lt;br /&gt;use ?&lt;br /&gt;exec sp_updatestats &lt;br /&gt;end' &lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6519686171349120370?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6519686171349120370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6519686171349120370' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6519686171349120370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6519686171349120370'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/03/spmsforeachdb-skipping-databases.html' title='sp_MSforeachDB - skipping databases'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7899769960152851614</id><published>2010-03-26T13:54:00.004-05:00</published><updated>2010-03-26T14:00:54.971-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Baba'/><category scheme='http://www.blogger.com/atom/ns#' term='Russian'/><category scheme='http://www.blogger.com/atom/ns#' term='baking'/><category scheme='http://www.blogger.com/atom/ns#' term='cake'/><title type='text'>Kulich - Russian Easter Bread</title><content type='html'>FINALLY, something baking related!  It's been too long, I've been resting on my laurels.&lt;br /&gt;&lt;br /&gt;I'll update this once I've made it myself.  One other way to make it is inside a coffee can - I need to get details on that, since that's how I always had it - bullet-shaped, funnily enough, with a sprinkle-laden glaze on top.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;6 cups sifted flour&lt;br /&gt;3 egg yolks&lt;br /&gt;1 whole egg&lt;br /&gt;3/4 cups sugar&lt;br /&gt;1 teaspoon salt&lt;br /&gt;1 and a 1/2 packages yeast (come in a pack of 3)&lt;br /&gt;1 and 1/4 cups WARM (not hot) milk&lt;br /&gt;1 stick (1/4 pound) melted butter. &lt;br /&gt; (Let cool off so it's not hot.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Put yeast and milk in bowl and mix.&lt;br /&gt;put eggs, sugar and salt in another bowl and mix on low speed.&lt;br /&gt;Put milk and yeast together with the flour.&lt;br /&gt;Add the eggs,sugar, salt mixture in.&lt;br /&gt;Add melted butter.&lt;br /&gt;Mix well with a wooden spoon.&lt;br /&gt;Knead the dough mixture about 10 minutes (maybe more).&lt;br /&gt;Dough needs to be soft.&lt;br /&gt;Put a cover over the bowl so it can rise.&lt;br /&gt;Dough needs to rise for an hour or more.&lt;br /&gt;Needs to become twice its size.&lt;br /&gt;Separate into 2 loaves.&lt;br /&gt;Put 1 cup raisens for each loaf&lt;br /&gt;Preheat oven to 350.&lt;br /&gt;Use loaf pan sprayed with PAM or greased with butter.&lt;br /&gt;Let dough rise again for 40-60 minutes.&lt;br /&gt;If you want a shiny crust, use the whites from the 3 eggs.&lt;br /&gt;Beat the whites for just a minute with a fork and brush the mixture&lt;br /&gt;over the crust before you put in oven.&lt;br /&gt;Bake 45-60 minutes.&lt;br /&gt;Check dough with toothpick at 45 minutes to see if ready.&lt;br /&gt;Pull the bread out and put on a towel.&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7899769960152851614?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7899769960152851614/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7899769960152851614' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7899769960152851614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7899769960152851614'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/03/kulich-russian-easter-bread.html' title='Kulich - Russian Easter Bread'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7252770878801149569</id><published>2010-03-05T14:38:00.002-06:00</published><updated>2010-03-05T14:42:32.224-06:00</updated><title type='text'>[Code] IF EXISTS table check</title><content type='html'>Because I keep coming over here to find the snippet...&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if object_id('tempdb..##temptablename') is not null&lt;br /&gt;    drop table ##temptablename&lt;br /&gt;CREATE TABLE ##temptablename (id INT IDENTITY, filelist VARCHAR(255))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; SELECT * FROM tablename.dbo.sysobjects &lt;br /&gt; WHERE id = OBJECT_ID(N'tablename_goes_here') &lt;br /&gt; AND OBJECTPROPERTY(id, N'IsUserTable') = 1&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7252770878801149569?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7252770878801149569/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7252770878801149569' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7252770878801149569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7252770878801149569'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/03/code-if-exists-table-check.html' title='[Code] IF EXISTS table check'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4890624119802760234</id><published>2010-02-01T16:00:00.004-06:00</published><updated>2010-03-24T09:20:02.723-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><title type='text'>[Replication] Alternative to SQLMonitor (Replication Monitor)</title><content type='html'>SQL Server's Replication Monitor is great except for a few major issues&lt;br /&gt;1) It has to be running all the time, and it consumes a large number of window resources.&lt;br /&gt;2) Due to the way SQL reports issues in replication, it can show a publication as good, even if it's been erroring for 2 days.&lt;br /&gt;3) It's active, not passive - I have to go look at it.  It can't warn me via email or whatnot.&lt;br /&gt;&lt;br /&gt;So, half a day digging through code and error messages, and I've come up with this.  This is not fullproof by any stretch - I don't deal with Merge Replication, for instance.  But in MY environment, it seems to work pretty well.&lt;br /&gt;&lt;br /&gt;I'll see about adding a couple more fields, but I want to get this on paper. &lt;br /&gt;(And yes, this is a request: if there's a better way than this, let me know)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;--Courtesy of The Baking DBA&lt;br /&gt;--Replication query that shows what's currently in error.&lt;br /&gt;--1.01 added "delivering" exclusion, email, fixed &lt;br /&gt;--   line-too-long-breaks-blogspot formatting&lt;br /&gt;IF OBJECT_ID('tempdb.dbo.##replication_errors') IS NOT NULL &lt;br /&gt;    DROP TABLE ##replication_errors&lt;br /&gt;&lt;br /&gt;SELECT &lt;br /&gt; errors.agent_id, &lt;br /&gt; errors.last_time, &lt;br /&gt; agentinfo.name, &lt;br /&gt; agentinfo.publication, &lt;br /&gt; agentinfo.subscriber_db,&lt;br /&gt; error_messages.comments AS ERROR&lt;br /&gt;INTO ##replication_errors&lt;br /&gt;FROM &lt;br /&gt;--find our errors; note that a runstatus 3 &lt;br /&gt;--can be the last message, even if it's actually idle and good&lt;br /&gt;(SELECT agent_id, MAX(TIME) AS last_time &lt;br /&gt; FROM distribution.dbo.MSdistribution_history with (nolock)&lt;br /&gt; WHERE runstatus IN (3,5,6) &lt;br /&gt; AND comments NOT LIKE '%were delivered.' &lt;br /&gt; AND comments NOT LIKE '&lt;stats%' &lt;br /&gt; GROUP BY agent_id) errors&lt;br /&gt;INNER JOIN &lt;br /&gt;(SELECT agent_id, MAX(TIME) AS last_time &lt;br /&gt; FROM distribution.dbo.MSdistribution_history with (nolock)&lt;br /&gt; WHERE runstatus IN (1,2,4) &lt;br /&gt; OR comments LIKE '%were delivered.'&lt;br /&gt; GROUP BY agent_id) clean&lt;br /&gt; ON errors.agent_id = clean.agent_id &lt;br /&gt; AND errors.last_TIME &gt; clean.last_time&lt;br /&gt;--grab the agent information&lt;br /&gt;INNER JOIN distribution.dbo.MSdistribution_agents agentinfo&lt;br /&gt;ON agentinfo.id = errors.agent_id&lt;br /&gt;--and the actual message we'd see in the monitor&lt;br /&gt;inner JOIN distribution.dbo.MSdistribution_history error_messages&lt;br /&gt;ON error_messages.agent_id = errors.agent_id &lt;br /&gt;AND error_messages.time = errors.last_time&lt;br /&gt;AND comments NOT LIKE '%TCP Provider%'&lt;br /&gt;AND comments NOT LIKE '%Delivering replicated transactions%'&lt;br /&gt;&lt;br /&gt;IF (SELECT COUNT(*) FROM ##replication_errors) &gt; 0 &lt;br /&gt;EXEC msdb.dbo.sp_send_dbmail&lt;br /&gt;    @profile_name = 'email_profile',&lt;br /&gt;    @recipients = 'blah@tbd.com',&lt;br /&gt;    @subject = 'Replication errors'&lt;br /&gt;   ,@query = 'select * from ##replication_errors'&lt;br /&gt;   ,@query_result_header = 0&lt;br /&gt;&lt;br /&gt;DROP TABLE ##replication_errors&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4890624119802760234?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4890624119802760234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4890624119802760234' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4890624119802760234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4890624119802760234'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/02/replication-alternative-to-sqlmonitor.html' title='[Replication] Alternative to SQLMonitor (Replication Monitor)'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8878637662387510832</id><published>2010-01-29T13:40:00.001-06:00</published><updated>2010-01-29T13:41:42.659-06:00</updated><title type='text'>IF EXISTS for tables</title><content type='html'>I know - I should have this memorized. And it doesn't deal with schemas.&lt;br /&gt;&lt;br /&gt;IF EXISTS &lt;br /&gt; (&lt;br /&gt; SELECT * FROM databasename.dbo.sysobjects &lt;br /&gt; WHERE id = OBJECT_ID(N'tablename') &lt;br /&gt; AND OBJECTPROPERTY(id, N'IsUserTable') = 1&lt;br /&gt; )&lt;br /&gt;DROP TABLE databasename.dbo.tablename&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8878637662387510832?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8878637662387510832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8878637662387510832' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8878637662387510832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8878637662387510832'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/01/if-exists-for-tables.html' title='IF EXISTS for tables'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-1409384666057765817</id><published>2010-01-25T16:32:00.002-06:00</published><updated>2011-10-19T14:47:59.666-05:00</updated><title type='text'>[Setup] Making sure your disks are optimized</title><content type='html'>At this point, probably everyone knows that you need to make sure to format your drives properly to take full advantage of them.  There's two different issues: the cluster size, and the offset.  Practically, you want for each of them to be 64k.  &lt;br /&gt;&lt;br /&gt;Here's how to make sure.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Block size.&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&amp;gt; fsutil fsinfo ntfsinfo d:&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That will give you a bunch of info.  What you care about is the Bytes Per Cluster, which should be 65536 (aka 64k)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Cluster offset:&lt;/span&gt;&lt;br /&gt;Using DISKPART:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;gt; diskpart&lt;/pre&gt;&lt;pre&gt;&amp;gt; list disk&lt;/pre&gt;&lt;pre&gt;&amp;gt; select disk 1 (or whichever disk you want to look at)&lt;/pre&gt;&lt;pre&gt;&amp;gt; list partition&lt;/pre&gt;&lt;br /&gt;Look for the "offset" column&lt;br /&gt;&lt;br /&gt;Powershell: See&lt;br /&gt;http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!291.entry&lt;br /&gt;for a powershell script.&lt;br /&gt;&lt;br /&gt;To format a drive properly:&lt;br /&gt;diskpart&lt;br /&gt;list disk&lt;br /&gt;select disk 2&lt;br /&gt;create partition primary align=1024&lt;br /&gt;format fs=ntfs unit=64K label="yourdrivenamehere" nowait&lt;br /&gt;exit&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-1409384666057765817?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/1409384666057765817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=1409384666057765817' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1409384666057765817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1409384666057765817'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/01/setup-making-sure-your-disks-are.html' title='[Setup] Making sure your disks are optimized'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5259432850008046939</id><published>2010-01-05T10:05:00.003-06:00</published><updated>2010-01-05T10:50:40.404-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='awk'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><title type='text'>[Text] Counts of a word within a file.  Not by line, total.</title><content type='html'>Came across this (courtesy of Franklin52 in the unix.com forums).&lt;br /&gt;http://www.unix.com/shell-programming-scripting/63576-how-find-count-word-within-file.html&lt;br /&gt;&lt;br /&gt;Say you need a count of a particular word in a file.  For example, in an XML file where the word can repeat within a line.  Can't use WC or GREP or FIND, but AWK will do the job.  (You &lt;strong&gt;do&lt;/strong&gt; have these tools on your Windows box, right? [if you have a UNIX box, it's assumed you do])&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;awk 'BEGIN{RS=" "}/WORDTOCOUNT/{h++}END{print h}' blah.txt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;One note: this assumes that there will be a space somewhere between the occurrence of the words.  TESTTEST and &lt;br /&gt;TEST&lt;br /&gt;TEST &lt;br /&gt;would each only count as 1, since there's no space to "reset" the find. (It's a stream function - search for the word.  If you find it, increment by one and skip forward to the next space.  When you hit a space, start searching again.)  For our XML, there are spaces after the tag we searched for, so the counts work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5259432850008046939?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5259432850008046939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5259432850008046939' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5259432850008046939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5259432850008046939'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2010/01/text-counts-of-word-within-file-not-by.html' title='[Text] Counts of a word within a file.  Not by line, total.'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4268417472133045518</id><published>2009-12-04T15:13:00.002-06:00</published><updated>2009-12-04T15:20:09.787-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ddl triggers'/><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><title type='text'>Replication and DDL Triggers - DO NOT MIX</title><content type='html'>So, we had started rolling out DDL Triggers, and then today replication broke.  &lt;br /&gt;&lt;br /&gt;How? A weird ARITHABORT error trying to add a table via the GUI. Weird.  So I disable the trigger and add it - at which point replication itself starts throwing the error :&lt;br /&gt;&lt;br /&gt;Target string size is too small to represent the XML instance (Source: MSSQLServer, Error number: 6354)&lt;br /&gt;Get help: http://help/6354&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Well, it turns out I have an XML trigger on the TARGET database, and it can't deal with the large commands involved in transactions.  &lt;br /&gt;&lt;br /&gt;How to diagnose and find the exact commands causing problems?&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;use [replicated_table]&lt;br /&gt;go&lt;br /&gt;sp_helparticle @publication = N'publication_name', @article = 'article_name'&lt;br /&gt;go&lt;br /&gt;use distribution&lt;br /&gt;go&lt;br /&gt;sp_browsereplcmds @article_id = 77 --where 77 is the article_id from above&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4268417472133045518?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4268417472133045518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4268417472133045518' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4268417472133045518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4268417472133045518'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/12/replication-and-ddl-triggers-do-not-mix.html' title='Replication and DDL Triggers - DO NOT MIX'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6415130160943572002</id><published>2009-11-18T17:26:00.003-06:00</published><updated>2009-11-18T17:28:16.181-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ddl triggers'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2008'/><category scheme='http://www.blogger.com/atom/ns#' term='audit'/><title type='text'>DDL Triggers</title><content type='html'>We're slowly starting to roll this out, based on the below code.  A very well written article; our concern is on performance.  &lt;br /&gt;&lt;br /&gt;http://www.sql-server-performance.com/articles/audit/ddl_triggers_p1.aspx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6415130160943572002?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6415130160943572002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6415130160943572002' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6415130160943572002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6415130160943572002'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/11/ddl-triggers.html' title='DDL Triggers'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5271384318696306486</id><published>2009-10-28T10:18:00.002-05:00</published><updated>2009-10-28T10:29:46.928-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='partial'/><category scheme='http://www.blogger.com/atom/ns#' term='filegroup'/><category scheme='http://www.blogger.com/atom/ns#' term='restore'/><category scheme='http://www.blogger.com/atom/ns#' term='piecemeal'/><category scheme='http://www.blogger.com/atom/ns#' term='litespeed'/><title type='text'>Piecemeal (aka Partial) filegroup restores from litespeed (sorta)</title><content type='html'>Okay, I wanted to write this down while I'm thinking about it.&lt;br /&gt;&lt;br /&gt;I use filegroups and do filegroup backups.  Extensively.  Gives you more control and power, since you can backup each one individually, put it in its own location, give it its own schedule, etc, etc.  Litespeed helps with this, obviously, since it'll shrink each file. &lt;br /&gt;&lt;br /&gt;The downside is that restoring with Litespeed is an all-or-nothing ordeal.  You can't restore just the primary, or just one of the filegroups, or just a table (no, object-level restore doesn't work on filegroup backups).  Fortunately, SQL 2005 has a new "PARTIAL" option that allows you to restore just the primary filegroup, and then restore others in addition, so I'm using that.&lt;br /&gt;&lt;br /&gt;I've already requested this feature for Litespeed, as well as the PARTIAL option, but here's what I had to do to restore some tables from my filegroup backup&lt;br /&gt;&lt;br /&gt;0.  Take filegroup backups.  Take a TLOG backup if needed.&lt;br /&gt;&lt;br /&gt;1. Decompress the files I need.  Litespeed _does_ offer an "extractor" utility.  This will turn your Litespeed BKP into an uncompressed SQL backup.  One note: it creates 7 files, and the total will be the same as the uncompressed backup.  So make sure you have room.  I barely did - thank god for filegroups (or maybe not, since the whole purpose of this post is working around it).  So, extract the primary and whichever filegroup you need.&lt;br /&gt;Here's the code to restore a file:&lt;br /&gt;&lt;pre&gt;extractor.exe -Fc:\temp\Northwind.bak -Ec:\temp\NorthwindNative.bak&lt;/pre&gt; On my system it converts to native at about .75gb per minute (uncompressed size).  It's extremely disk-bound.  You need to extract the log file too, if you're compressing it (you might not be!  Check and see....).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Restore the primary filegroup WITH PARTIAL.   Make sure to keep your Primary filegroup small.  Mine isn't - I need to fix that.  Here's the command I used:&lt;br /&gt;    RESTORE DATABASE main&lt;br /&gt;    FILE = 'main_system_01'&lt;br /&gt;    FROM DISK = 'K:\primary.bak0',&lt;br /&gt;        DISK = 'K:\primary.bak1',&lt;br /&gt;        DISK = 'K:\primary.bak2',&lt;br /&gt;        DISK = 'K:\primary.bak3',&lt;br /&gt;        DISK = 'K:\primary.bak4',&lt;br /&gt;        DISK = 'K:\primary.bak5',&lt;br /&gt;        DISK = 'K:\primary.bak6'&lt;br /&gt;    WITH partial, move 'main_system_01' TO 'E:\MSSQL_Data\main.mdf' ,&lt;br /&gt;    move 'main_log_01' to 'F:\MSSQL_Log\main_log.ldf', --without this, it will fail&lt;br /&gt;    FILE = 1, norecovery, nounload, stats = 10&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. Wait a couple hours for the primary to restore.  (See?  This is why you have a small primary filegroup.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4. Restore the additional filegroup.  You do _not_ use the PARTIAL keyword here. Why?  Don't know - using PARTIAL caused it to fail, though my lab notes say to use it.  My bet is that you don't need PARTIAL if you're restoring the only filegroup within a backup.&lt;br /&gt;RESTORE DATABASE Main&lt;br /&gt;FILE = 'Main_Secondary_01'&lt;br /&gt;FROM DISK = 'K:\FG_Main_Secondary.bak0',&lt;br /&gt;     DISK = 'K:\FG_Main_Secondary.bak1',&lt;br /&gt;     DISK = 'K:\FG_Main_Secondary.bak2',&lt;br /&gt;     DISK = 'K:\FG_Main_Secondary.bak3',&lt;br /&gt;     DISK = 'K:\FG_Main_Secondary.bak4',&lt;br /&gt;     DISK = 'K:\FG_Main_Secondary.bak5',&lt;br /&gt;     DISK = 'K:\FG_Main_Secondary.bak6'&lt;br /&gt;WITH --partial,&lt;br /&gt;move 'Main_Secondary_01' TO 'E:\MSSQL_Data\Secondary.ndf' ,&lt;br /&gt;FILE = 1, norecovery, nounload, stats = 10&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5.  Restore the log.  I'd say to use use STOPAT so you don't have to keep restoring TLOGs, but I can't find anywhere how to get that to work with Litespeed's restore - I tried adding it to the @with, but then it just failed.  Odd.  Also, if I extract and restore a log, I get error messages about having to roll the LSN forward to a certain point, whereas I don't get that when running the below command. &lt;br /&gt;&lt;br /&gt;EXEC master.dbo.xp_restore_log&lt;br /&gt;     @database = 'Main'&lt;br /&gt;   , @filename = '\\myserver\SQL_Backups\Main\Main_tlog_200802041030.TRN'&lt;br /&gt;  , @filenumber = 1&lt;br /&gt;,@WITH ='RECOVERY'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6. Keep running restores until you get current.  The way I did it, I kept running TLOG restores until I got an error message telling me the database is offline.  It does this once you hit the last log file prior to the last database backup finishing.&lt;br /&gt;&lt;br /&gt;7.  Bring database ONLINE.  I do it via the GUI.&lt;br /&gt;&lt;br /&gt;8.  Bring database from SINGLE-USER to MULTI-USER.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5271384318696306486?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5271384318696306486/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5271384318696306486' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5271384318696306486'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5271384318696306486'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/10/piecemeal-aka-partial-filegroup.html' title='Piecemeal (aka Partial) filegroup restores from litespeed (sorta)'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-1901916192945317845</id><published>2009-10-28T09:57:00.006-05:00</published><updated>2010-02-25T07:36:34.720-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tuning'/><category scheme='http://www.blogger.com/atom/ns#' term='I/O'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2008'/><category scheme='http://www.blogger.com/atom/ns#' term='DMV'/><category scheme='http://www.blogger.com/atom/ns#' term='IO'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Tuning] Getting file disk usage</title><content type='html'>Short and simple.  Uses the DMV to tell you how much IO each file is using.  What you think may be the case is not necessarily the case.  And remember that backups count.  I'd recommend doing 2+ samples during the day, and comparing.  That'll help remove the backups from the end totals.  Sample_MS is the number of milliseconds the computer has been up.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT &lt;br /&gt;  master_files.NAME, &lt;br /&gt;  master_files.type_desc,&lt;br /&gt;  master_files.physical_name, &lt;br /&gt;  vfs.sample_ms,&lt;br /&gt;  vfs.num_of_bytes_written, &lt;br /&gt;  num_of_bytes_read, &lt;br /&gt;  size_on_disk_bytes/1024/1024/1024 AS Size_in_GB&lt;br /&gt;FROM sys.dm_io_virtual_file_stats(null, null) vfs&lt;br /&gt;INNER JOIN MASTER.sys.master_files &lt;br /&gt; ON vfs.[file_id] = master_files.[file_id] &lt;br /&gt; AND vfs.database_id = master_files.database_id&lt;br /&gt;ORDER BY (num_of_bytes_read + num_of_bytes_written) desc&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-1901916192945317845?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/1901916192945317845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=1901916192945317845' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1901916192945317845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1901916192945317845'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/10/tuning-getting-file-disk-usage.html' title='[Tuning] Getting file disk usage'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6735004507219868848</id><published>2009-08-20T16:22:00.003-05:00</published><updated>2009-08-20T16:32:32.666-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2008'/><category scheme='http://www.blogger.com/atom/ns#' term='compression'/><title type='text'>[Compression] Seeing how much savings you'll get</title><content type='html'>If you meet all sorts of criteria (SQL Server 2008, Enterprise Edition) then you can use row or page level compression on your tables.  But, you ask: will it make a difference in space used? &lt;br /&gt;&lt;br /&gt;Fortunately, and a bit surprisingly, Microsoft came up with a way to do so.&lt;br /&gt;sp_estimate_data_compression_savings&lt;br /&gt;&lt;br /&gt;Sample usage:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sp_estimate_data_compression_savings &lt;br /&gt;       @schema_name =  'dbo'  &lt;br /&gt;     , @object_name =  '20090820__abc' &lt;br /&gt;     , @index_id = NULL             --NULL does all.&lt;br /&gt;     , @partition_number = null     --if you use partitioned tables&lt;br /&gt;     , @data_compression = 'PAGE'   --can also use ROW or NONE&lt;br /&gt;go&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It looks like it takes roughly 40mb of data, copies it to TEMPDB, and compresses that.  It then returns the results, including comparing the size to what the current compression is.&lt;br /&gt;&lt;br /&gt;For us, mixed results.  One set of EDI data, which uses certain characters to split out values, gets roughly 25% compression.  A different set of EDI data that uses XML (with huge swathes of repeating data) get a whopping 1% savings.&lt;br /&gt;&lt;br /&gt;I love the idea.  I want to use it everywhere - since most systems are IO bound (not CPU bound) it seems a home run.  But the requirement of Enterprise Edition lessens its usefulness by a _lot_.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6735004507219868848?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6735004507219868848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6735004507219868848' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6735004507219868848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6735004507219868848'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/08/compression-seeing-how-much-savings.html' title='[Compression] Seeing how much savings you&apos;ll get'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8899234444374289355</id><published>2009-07-27T10:04:00.001-05:00</published><updated>2009-07-27T10:05:35.161-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jobs'/><category scheme='http://www.blogger.com/atom/ns#' term='history'/><category scheme='http://www.blogger.com/atom/ns#' term='system tables'/><title type='text'>[Jobs] Search job history for a particular date range</title><content type='html'>Pieces cribbed off several people.  Enjoy.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select job_name, run_datetime, run_duration from (&lt;br /&gt;    select job_name, run_datetime,&lt;br /&gt;        SUBSTRING(run_duration, 1, 2) + ':' + SUBSTRING(run_duration, 3, 2) + ':' +&lt;br /&gt;        SUBSTRING(run_duration, 5, 2) AS run_duration&lt;br /&gt;    from&lt;br /&gt;    (&lt;br /&gt;        select DISTINCT&lt;br /&gt;            j.name as job_name, &lt;br /&gt;            run_datetime = CONVERT(DATETIME, RTRIM(run_date)) +  &lt;br /&gt;                (run_time * 9 + run_time % 10000 * 6 + run_time % 100 * 10) / 216e4,&lt;br /&gt;            run_duration = RIGHT('000000' + CONVERT(varchar(6), run_duration), 6)&lt;br /&gt;        from msdb..sysjobhistory h&lt;br /&gt;        inner join msdb..sysjobs j&lt;br /&gt;        on h.job_id = j.job_id&lt;br /&gt;    ) t&lt;br /&gt;) t&lt;br /&gt;WHERE run_datetime between '2009/07/24 01:00' AND '2009/07/24 01:59'&lt;br /&gt;order by job_name, run_datetime&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8899234444374289355?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8899234444374289355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8899234444374289355' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8899234444374289355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8899234444374289355'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/07/jobs-search-job-history-for-particular.html' title='[Jobs] Search job history for a particular date range'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2074114781829689920</id><published>2009-07-27T09:50:00.003-05:00</published><updated>2009-07-27T09:54:29.886-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linked servers'/><category scheme='http://www.blogger.com/atom/ns#' term='openquery'/><title type='text'>[Servers] No linked server? Need inserts? No problem!</title><content type='html'>Linked servers can be handy.  But, also occasionally annoying, and not necessarily where you need them.  Fortunately, OPENQUERY to the rescue.  Yes, you can use it to do an adhoc query from another server.  But, you can also use it to do an insert into another server. &lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;INSERT INTO OPENROWSET('SQLNCLI', 'Server=yourserversname;Trusted_Connection=yes',&lt;br /&gt; 'SELECT * FROM northwind.dbo.targettable') SELECT FieldA, FieldB, FieldC&lt;br /&gt;FROM sourcetable &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2074114781829689920?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2074114781829689920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2074114781829689920' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2074114781829689920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2074114781829689920'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/07/servers-no-linked-server-need-inserts.html' title='[Servers] No linked server? Need inserts? No problem!'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3914772749934378125</id><published>2009-06-29T16:30:00.002-05:00</published><updated>2009-06-29T16:34:51.132-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='undocumented fix'/><category scheme='http://www.blogger.com/atom/ns#' term='unsupported code'/><category scheme='http://www.blogger.com/atom/ns#' term='undocumented changes'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Tip] getting local context from sp_ in master</title><content type='html'>In SQL 2005, if you create an SP in master that queries from system tables (or the INFORMATION_SCHEMA views), it'll return the details from the Master database - regardless of where you're running it.  In SQL 2000, it worked.  &lt;br /&gt;&lt;br /&gt;So, an unsupported workaround, pointed out to me by Erland Sommarskog, SQL MVP &amp; SQL God:&lt;br /&gt;&lt;pre&gt;EXEC sp_MS_marksystemobject [your_sp_name]&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3914772749934378125?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3914772749934378125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3914772749934378125' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3914772749934378125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3914772749934378125'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/06/tip-getting-local-context-from-sp-in.html' title='[Tip] getting local context from sp_ in master'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5303443376143036672</id><published>2009-06-12T16:01:00.002-05:00</published><updated>2009-06-12T16:06:32.523-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql 2008'/><category scheme='http://www.blogger.com/atom/ns#' term='DMV'/><category scheme='http://www.blogger.com/atom/ns#' term='cruft'/><title type='text'>[Cruft] New DMV in 2008 - SP details</title><content type='html'>One of the things I've been hoping/waiting/praying for, in SQL 2008, is the ability to see when an SP was last run.  In 2000 and 2005 you can do it, so long as it's still in the cache.  Which means that things only run sporadically won't occur.&lt;br /&gt;&lt;br /&gt;Imagine my happiness:&lt;br /&gt;&lt;pre&gt;SELECT * FROM sys.dm_exec_procedure_stats&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Extra credit: join to sys.procedures (also new) to get the object.&lt;br /&gt;&lt;br /&gt;So, now you can see, since the server was started, what runs.  And since your server stays up for several months at a time, you have a good "hit list" of procs that can be scripted out and removed.  &lt;br /&gt;&lt;br /&gt;I'll update this post when we get a good working version.&lt;br /&gt;(Thanks to Hammer for his help)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5303443376143036672?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5303443376143036672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5303443376143036672' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5303443376143036672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5303443376143036672'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/06/cruft-new-dmv-in-2008-sp-details.html' title='[Cruft] New DMV in 2008 - SP details'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5080492050567035840</id><published>2009-06-11T10:54:00.005-05:00</published><updated>2009-06-11T11:07:14.128-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sp_depends'/><category scheme='http://www.blogger.com/atom/ns#' term='dependencies'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Cruft] Fixing dependencies</title><content type='html'>&lt;pre&gt;EXEC sys.sp_refreshsqlmodule 'dbo.MyProcFnOrView'&lt;/pre&gt;&lt;br /&gt;That will update your dependencies table, allowing you to use sp_depends even if the objects weren't inserted in order.  New to 2005, thankfully someone at MS realized and fixed sp_depends' weakness.&lt;br /&gt;&lt;br /&gt;When objects are added, rows are added to the internal dependency table. However, it's very easy to get out of sync - say if you add SP A that calls SP B, but add them in the reverse order.  Which _never_ happens.  Sure.&lt;br /&gt;&lt;br /&gt;So, anyhow.  Use that, then use one of the handy pieces of code online that assume that the dependency table always works.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5080492050567035840?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5080492050567035840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5080492050567035840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5080492050567035840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5080492050567035840'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/06/cruft-fixing-dependencies.html' title='[Cruft] Fixing dependencies'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7958003234947285446</id><published>2009-04-23T08:43:00.003-05:00</published><updated>2009-04-23T08:52:00.100-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='code'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>[Code] Powershell - a basic script for all servers</title><content type='html'>Just acquainting myself with Powershell - I've known about it, but have preferred using Cygwin's shell.  However, I wanted to run some code against all servers, and this seemed a good time to try with Powershell.&lt;br /&gt;&lt;br /&gt;I found this original script, which would run the same code against all servers in a list. (&lt;a href="http://www.quicksqlserver.com/2009/01/powershell-sqlcmd-and-invoke-expression.html"&gt;http://www.quicksqlserver.com/2009/01/powershell-sqlcmd-and-invoke-expression.html&lt;/a&gt;)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;foreach ($svr in get-content "C:\MyInstances.txt"){&lt;br /&gt;    $svr&lt;br /&gt;    invoke-expression "SQLCMD -E -S $svr -i createMyuser.sql"&lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So then I adapted it - using SQLCMD /Lc to get a list of servers on the network, print the server name, then run SQLCMD against each server, running the c:\simplemodel.sql script (while you can run SQL inline, it kept parsing the @@ and choking on it).  Not foolproof, mind you, but a good starting point.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;foreach ($svr in (sqlcmd /Lc))&lt;br /&gt;{&lt;br /&gt;        $svr&lt;br /&gt;        invoke-expression "SQLCMD -E -S $svr -i c:\simplemodel.sql"&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7958003234947285446?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7958003234947285446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7958003234947285446' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7958003234947285446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7958003234947285446'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/04/code-powershell-basic-script-for-all.html' title='[Code] Powershell - a basic script for all servers'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8937753474714415892</id><published>2009-04-21T17:02:00.003-05:00</published><updated>2009-04-21T17:12:28.735-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='indexes'/><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL 2000'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Maint] Quick and Dirty maintenance</title><content type='html'>Is this suitable most places?  No.  Is it fast and easy?  Yes.&lt;br /&gt;&lt;br /&gt;Reindex all tables in a database (2000 &amp; 2005)&lt;br /&gt;&lt;pre&gt;exec sp_MSforeachtable "DBCC DBREINDEX ('?')"&lt;/pre&gt;&lt;br /&gt;or&lt;br /&gt;&lt;pre&gt;EXEC sp_MSforeachtable "print '?' DBCC DBREINDEX ('?', ' ', 85)"&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Update statistics in a database&lt;br /&gt;For 2000 (since sp_updatestats can break certain things)&lt;br /&gt;&lt;pre&gt;EXEC sp_MSforeachtable "update STATISTICS ?"&lt;/pre&gt;&lt;br /&gt;For 2005:&lt;br /&gt;&lt;pre&gt;sp_updatestats&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8937753474714415892?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8937753474714415892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8937753474714415892' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8937753474714415892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8937753474714415892'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/04/maint-quick-and-dirty-maintenance.html' title='[Maint] Quick and Dirty maintenance'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3517434219876359371</id><published>2009-04-13T09:32:00.003-05:00</published><updated>2009-04-13T09:45:12.043-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='twit'/><category scheme='http://www.blogger.com/atom/ns#' term='links'/><category scheme='http://www.blogger.com/atom/ns#' term='cooking'/><title type='text'>[Cooking] Marathon weekend</title><content type='html'>So, overall a good weekend.  If ever there was a post of mine that qualified as "useless twitter feed", this would be it.&lt;br /&gt;&lt;br /&gt;I made the following this Sunday:&lt;br /&gt;&lt;a href="http://susiebright.blogs.com/susie_brights_journal_/2006/12/the_leauge_of_a.html"&gt;Latkes&lt;/a&gt; for breakfast - a bit salty when I doubled the recipe.  Maybe I subbed Tbsp for Tsp?  &lt;br /&gt;&lt;br /&gt;Dinner:&lt;br /&gt;Ham (prefab from Sam's), Mixed veggies (prefab steamer bag), Prefab bread (I know, I know - just didn't have time or forethought to do something special), and I made:&lt;br /&gt;&lt;a href="http://www.foodnetwork.com/recipes/alton-brown/glazed-carrots-recipe/index.html"&gt;Glazed Carrots&lt;/a&gt; - worked well, but for some reason I needed to cook them for longer than stated in the recipe.  It took a while, and while the glaze wasn't perfect (next time try 1.5 cups of Ginger Ale), it was passable. &lt;br /&gt;&lt;a href="http://www.recipelink.com/cookbooks/2002/0743224841_1.html"&gt;Bag Lady's Favorite Chocolate Pound Cake&lt;/a&gt;. Don't make this in a Bundt pan - it'll overflow.  I used an Angel food pan, and it worked perfectly.  Pulled it out after 85 minutes and it was done and came out moist.  I used the Hershey's Perfectly Chocolate Icing (recipe below) and that worked wonderfully with it.  &lt;br /&gt;&lt;br /&gt;I do need to see if there's some sort of liquid-center bundt-cake recipe, where when it bakes enough it's cake, and where it's not it's pudding-like.  That would be yummy.&lt;br /&gt;&lt;br /&gt;Here's the recipe - I didn't make the cake, just the icing.&lt;br /&gt;http://www.hersheys.com/recipes/recipes/detail.asp?id=184&lt;br /&gt;"PERFECTLY CHOCOLATE" CHOCOLATE FROSTING&lt;br /&gt;&lt;br /&gt;1/2 cup (1 stick) butter or margarine&lt;br /&gt;2/3 cup HERSHEY'S Cocoa&lt;br /&gt;3 cups powdered sugar&lt;br /&gt;1/3 cup milk&lt;br /&gt;1 teaspoon vanilla extract&lt;br /&gt;&lt;br /&gt;Melt butter. Stir in cocoa. Alternately add powdered sugar and milk, beating to spreading consistency. Add small amount additional milk, if needed. Stir in vanilla. About 2 cups frosting.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3517434219876359371?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3517434219876359371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3517434219876359371' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3517434219876359371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3517434219876359371'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/04/cooking-marathon-weekend.html' title='[Cooking] Marathon weekend'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7558764267642627373</id><published>2009-04-10T14:58:00.002-05:00</published><updated>2009-04-10T15:01:25.022-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='restore'/><category scheme='http://www.blogger.com/atom/ns#' term='archived'/><category scheme='http://www.blogger.com/atom/ns#' term='litespeed'/><category scheme='http://www.blogger.com/atom/ns#' term='backups'/><title type='text'>[Backups]  Restoring Litespeed archival backups to secondary server</title><content type='html'>After a year or so, databases on my primary server get moved to a secondary server.  I wrote the below script to look in a particular for 1 backup, then it determines where to restore it based off the database name.  Hopefully someone else can use this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;DECLARE @backup_directory VARCHAR(500), @Verified VARCHAR(100), @full_backup_name VARCHAR(600),&lt;br /&gt;  @database_name sysname, @restore_directory VARCHAR(500), &lt;br /&gt;  @logical_name_log  VARCHAR(50), @physical_name_log  VARCHAR(50),&lt;br /&gt;  @logical_name_data VARCHAR(50), @physical_name_data VARCHAR(50)&lt;br /&gt;  ,@with_data VARCHAR(200), @with_log VARCHAR(200)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------&lt;br /&gt;--put the name of the folder with the backup you want restored here--&lt;br /&gt;---------------------------------------------------------------------&lt;br /&gt;SET @backup_directory = '\\servername\share\databasefolderbackup'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;IF RIGHT(@backup_directory, 1) &lt;&gt; '\'&lt;br /&gt; SET @backup_directory = @backup_directory + '\'&lt;br /&gt;&lt;br /&gt;IF EXISTS &lt;br /&gt; (&lt;br /&gt; SELECT * FROM dbo.sysobjects &lt;br /&gt; WHERE id = OBJECT_ID(N'tempdb.[dbo].[#listing]') &lt;br /&gt; AND OBJECTPROPERTY(id, N'IsUserTable') = 1&lt;br /&gt; )&lt;br /&gt;DROP TABLE #Listing&lt;br /&gt;create table #Listing&lt;br /&gt;(resultant nvarchar (255))&lt;br /&gt;&lt;br /&gt;--Find the backups in the given folder&lt;br /&gt;declare @dirlist varchar(500)&lt;br /&gt;select @dirlist = 'exec master..xp_cmdshell ''dir /b "'+  @backup_directory + '*"'''&lt;br /&gt;insert #Listing exec (@dirlist)&lt;br /&gt;&lt;br /&gt;--get the most recent &lt;br /&gt;select @Verified = MAX(resultant) from #listing WHERE resultant LIKE '%.bak'&lt;br /&gt;DROP TABLE #Listing&lt;br /&gt;&lt;br /&gt;--get a list of all logical files within the backup so we can restore with the right data&lt;br /&gt;SELECT @full_backup_name = @backup_directory + @Verified&lt;br /&gt;&lt;br /&gt;if object_id('tempdb..#database_details') is not null&lt;br /&gt;    DROP TABLE #database_details&lt;br /&gt;&lt;br /&gt;CREATE TABLE #database_details &lt;br /&gt; (&lt;br /&gt;  LogicalName sysname, &lt;br /&gt;  PhysicalName varchar(500), &lt;br /&gt;  [TYPE] VARCHAR(2),&lt;br /&gt;  FileGroupName varchar(50),&lt;br /&gt;  [Size] VARCHAR(50),&lt;br /&gt;  [MaxSize] VARCHAR(50))&lt;br /&gt;INSERT INTO #database_details&lt;br /&gt; EXEC MASTER..xp_restore_filelistonly @filename = @full_backup_name&lt;br /&gt; &lt;br /&gt;--get the names of everything.&lt;br /&gt;SELECT @logical_name_data = LogicalName, @physical_name_data = PhysicalName&lt;br /&gt; FROM #database_details WHERE [TYPE] = 'D'&lt;br /&gt;SELECT @logical_name_log = LogicalName, @physical_name_log = PhysicalName &lt;br /&gt; FROM #database_details WHERE [TYPE] = 'L'&lt;br /&gt;&lt;br /&gt;SELECT @database_name = @logical_name_data&lt;br /&gt;&lt;br /&gt;--set up the folders where the restore will automatically go. &lt;br /&gt;SELECT @physical_name_data = CASE &lt;br /&gt; WHEN @logical_name_data LIKE '2009%' THEN 'L:\2009\'&lt;br /&gt; WHEN @logical_name_data LIKE '2008%' THEN 'M:\2008\' &lt;br /&gt; ELSE 'not known'&lt;br /&gt; END &lt;br /&gt; + right(@physical_name_data, CHARINDEX('\', reverse(@physical_name_data))-1)&lt;br /&gt;&lt;br /&gt;SELECT @physical_name_log = CASE &lt;br /&gt; WHEN @logical_name_data LIKE '2009%' THEN 'L:\2009_Logs\'&lt;br /&gt; WHEN @logical_name_data LIKE '2008%' THEN 'M:\2008_Logs\' &lt;br /&gt; ELSE 'not known'&lt;br /&gt; END &lt;br /&gt; + right(@physical_name_log, CHARINDEX('\', reverse(@physical_name_log))-1)&lt;br /&gt;&lt;br /&gt;--need to set these separately since you can't call within the SP&lt;br /&gt;SELECT @with_data = 'MOVE "' + @logical_name_data + '" TO "' + @physical_name_data + '"'&lt;br /&gt;SELECT @with_log = 'MOVE "' + @logical_name_log  + '" TO "' + @physical_name_log  + '"'&lt;br /&gt;&lt;br /&gt;--Now do a restore with MOVE.  &lt;br /&gt;exec master..xp_restore_database @database=@database_name&lt;br /&gt;  , @filename= @full_backup_name&lt;br /&gt;  , @with = @with_data&lt;br /&gt;  , @with = @with_log &lt;br /&gt;&lt;/pre&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7558764267642627373?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7558764267642627373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7558764267642627373' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7558764267642627373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7558764267642627373'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/04/backups-restoring-litespeed-archival.html' title='[Backups]  Restoring Litespeed archival backups to secondary server'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3467614933509329894</id><published>2009-04-10T09:10:00.003-05:00</published><updated>2009-04-10T09:47:23.278-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='objects'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL 2000'/><category scheme='http://www.blogger.com/atom/ns#' term='information_schema'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Objects] dropping objects via code</title><content type='html'>The following code works in both SQL 2000 and SQL 2005.  &lt;br /&gt;&lt;br /&gt;Tables&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if object_id('tempdb..#database_details') is not null&lt;br /&gt;    DROP TABLE #database_details&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Stored Procedures&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;IF EXISTS &lt;br /&gt; (&lt;br /&gt; SELECT * FROM dbo.sysobjects &lt;br /&gt; WHERE id = OBJECT_ID(N'[dbo].[the_procedure_name]') &lt;br /&gt; AND OBJECTPROPERTY(id, N'IsProcedure') = 1&lt;br /&gt; )&lt;br /&gt;DROP PROCEDURE the_procedure_name&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Alternatively, the following code will CREATE a dummy SP if it doesn't exist, then ALTER it. This way you will only CREATE, not DROP, which can come in handy in certain circumstances, since it will save permissions. Note that this uses INFORMATION_SCHEMA, which is more portable than sysobjects.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;IF NOT EXISTS &lt;br /&gt; (&lt;br /&gt; SELECT * FROM INFORMATION_SCHEMA.ROUTINES &lt;br /&gt; WHERE ROUTINE_NAME = 'the_routine_name' &lt;br /&gt; and routine_type = 'PROCEDURE' --could also be 'FUNCTION' for a function&lt;br /&gt; )&lt;br /&gt;        EXEC ('CREATE PROC dbo.the_procedure_name AS SELECT 1')&lt;br /&gt;GO&lt;br /&gt;ALTER PROCEDURE dbo.the_procedure_name&lt;br /&gt;AS&lt;br /&gt;SELECT  *&lt;br /&gt;FROM    myTable&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3467614933509329894?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3467614933509329894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3467614933509329894' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3467614933509329894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3467614933509329894'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/04/objects-dropping-objects-via-code.html' title='[Objects] dropping objects via code'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-6636045113467826221</id><published>2009-04-08T09:30:00.004-05:00</published><updated>2009-04-08T09:36:52.914-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='free space'/><category scheme='http://www.blogger.com/atom/ns#' term='backups'/><title type='text'>[Backups] Determine your database growth via backup history</title><content type='html'>One thing about backups in SQL Server is that the history is kept forever, unless you clean it up using a maintenance plan, or one of the not-very-well-documented SPs.&lt;br /&gt;&lt;br /&gt;But we can have it work for us.&lt;br /&gt;Case in point - database growth estimations.  This is a basic view that will show what your database growth has been like for the past 60 days.  Turn it into a chart with reporting services, and you can see what's growing, at what rate, and what you need to be concerned with.&lt;br /&gt;&lt;br /&gt;Yes, this is pretty basic code, but I hadn't seen anybody do this before.&lt;br /&gt;And obviously, if you're cleaning up your backup history this won't necessarily do much.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE VIEW [dbo].[backup_history]&lt;br /&gt;as&lt;br /&gt;SELECT &lt;br /&gt; server_name,&lt;br /&gt; DATABASE_name,&lt;br /&gt;-- catalog_family_number,  --not sure what this does; unclear in BOL&lt;br /&gt; backup_size/1000000 AS backup_size,&lt;br /&gt; CONVERT(CHAR(12),backup_start_date,101) AS backup_date--, &lt;br /&gt;-- in case you want to look at a particular type of backup&lt;br /&gt;-- CASE [type]&lt;br /&gt;--  WHEN 'D' then 'Database'&lt;br /&gt;--  WHEN 'I' then 'Differential database'&lt;br /&gt;--  WHEN 'L' then 'Log'&lt;br /&gt;--  WHEN 'F' then 'File or filegroup'&lt;br /&gt;--  WHEN 'G' then 'Differential file'&lt;br /&gt;--  WHEN 'P' then 'Partial'&lt;br /&gt;--  WHEN 'Q' then 'Differential partial'&lt;br /&gt;--  END AS Backup_Type,&lt;br /&gt;-- [NAME], &lt;br /&gt;-- [description] &lt;br /&gt;FROM msdb.dbo.backupset &lt;br /&gt;WHERE [TYPE] IN ('D','F') --full backups, though tlogs could be interesting&lt;br /&gt;AND server_name = @@SERVERNAME&lt;br /&gt;AND database_name NOT IN ('msdb', 'MASTER', 'model')&lt;br /&gt;AND backup_start_date &gt; GETDATE()-60&lt;br /&gt;--ORDER BY SERVER_name, DATABASE_name, backup_start_date, catalog_family_number&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-6636045113467826221?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/6636045113467826221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=6636045113467826221' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6636045113467826221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/6636045113467826221'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/04/backups-determine-your-database-growth.html' title='[Backups] Determine your database growth via backup history'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-1091395059330500216</id><published>2009-03-04T18:37:00.004-06:00</published><updated>2011-01-03T18:17:19.893-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='baking'/><category scheme='http://www.blogger.com/atom/ns#' term='lasagna'/><title type='text'>[Entree] Gordon Ramsey Cookalong Lasagna, Take 2</title><content type='html'>&lt;p class="mobile-photo"&gt;&lt;a href="http://3.bp.blogspot.com/_bWjdmMMojdk/SZOLl_lG3PI/AAAAAAAAAlk/gXfkat0KdZU/s1600-h/IMG00073-20090211-2035-795039.jpg"&gt;&lt;img src="http://3.bp.blogspot.com/_bWjdmMMojdk/SZOLl_lG3PI/AAAAAAAAAlk/gXfkat0KdZU/s400/IMG00073-20090211-2035-795039.jpg" alt="" id="BLOGGER_PHOTO_ID_5301734671183699186" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;I've been following Gordon Ramsey's "Cookalong Live", albeit a bit delayed.  However, I have to share and show off my attempt at his Lasagna Al Forno.  The first time I did full mise en place, and it took about 75 minutes to put together.  The second time it took about 45 minutes, and is utterly fantastic.  Only takes a few ingredients that you might not have, nothing really too special (except for the pre-cooked lasagna sheets), and comes together VERY easily.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Highly &lt;/span&gt;recommended.  There's even videos on how to make it.&lt;br /&gt;Two hints&lt;br /&gt;1) Tomato paste, not puree - the brits apparently name things differently.&lt;br /&gt;2) Mince - ground beef, about 2/3 - 3/4 of a pound.  I use 85/15 ground beef and it comes out wonderfully.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;http://www.channel4.com/food/recipes/chefs/gordon-ramsay/gordon-s-lasagne-recipe_p_1.html&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And since they can't be arsed to keep the recipe in one place (or even searchable on their own site...)&lt;br /&gt;&lt;br /&gt;2 tbsp olive oil&lt;br /&gt;½ large onion, peeled&lt;br /&gt;1 large carrot, peeled&lt;br /&gt;2 cloves garlic, peeled&lt;br /&gt;2 pinches dried oregano&lt;br /&gt;300g minced beef&lt;br /&gt;1 tbsp tomato pur&amp;eacute;e&lt;br /&gt;1 tbsp Worcestershire sauce&lt;br /&gt;1 bay leaf&lt;br /&gt;30ml (2 tbsp) red wine&lt;br /&gt;1 x 400g tin chopped tomatoes&lt;br /&gt;50ml milk&lt;br /&gt;Salt and freshly ground black pepper&lt;br /&gt;For the sauce&lt;br /&gt;25g butter&lt;br /&gt;25g flour&lt;br /&gt;300ml milk&lt;br /&gt;Pinch of ground nutmeg&lt;br /&gt;60g Cheddar cheese, grated&lt;br /&gt;30g Parmesan cheese, grated&lt;br /&gt;6 sheets of 'non-cook' lasagne sheets&lt;br /&gt;For the salad&lt;br /&gt;1 tsp Dijon mustard&lt;br /&gt;1 tbsp white wine vinegar&lt;br /&gt;2-3 tbsp olive oil&lt;br /&gt;Salt and pepper&lt;br /&gt;1 x round lettuce head, rinsed and dried&lt;br /&gt;METHOD&lt;br /&gt;&lt;br /&gt;How to make Gordon's classic lasagne al forno&lt;br /&gt;1. Pre-heat the oven to 220C/ gas mark 7.&lt;br /&gt;&lt;br /&gt;2. Heat the olive oil in a hot pan. Grate the onion and carrot and crush the garlic before frying together. Season with the bay leaf, a pinch of oregano, Worcestershire sauce and a little salt and pepper. Allow the onion to soften before making a well in the centre of the pan. Place the mince in the middle of the pan and stir to break it up. Add the tomato puree and allow to cook out for 30 seconds. Continue until all the meat has browned nicely. Add the wine and cook off the alcohol before adding the tomatoes. Leave to simmer for a further 2-3 minutes. Finally add the milk, turn off the heat and set aside (watch Gordon's video on how to prepare bolognaise).&lt;br /&gt;&lt;br /&gt;3. To make the cheese sauce, first melt the butter in a saucepan. Add the flour and using a wooden spoon, stir to form a paste. Over a gentle heat add a third of the milk, whisking to prevent any lumps forming. Add the rest of the milk a third at a time, whisking as you go. Season with salt and pepper and a pinch of ground nutmeg. Allow the sauce to cook out for another minute before adding the Cheddar cheese. Stir and remove from the heat (watch Gordon's video on how to make the best white sauce).&lt;br /&gt;&lt;br /&gt;4. Spoon half of the meat sauce into the bottom of the baking dish and place pasta sheets on top (break the sheets if necessary to avoid any overlapping). Next, pour in just under half of the cheese sauce, and spread evenly using a spatula before spooning the remaining meat on top. Add the final layer of pasta and use the spatula to pour over the remaining cheese sauce.&lt;br /&gt;&lt;br /&gt;5. Finish with the grated Parmesan and sprinkle with another pinch of oregano. Add a light seasoning of salt and pepper before cleaning the edges of the dish and placing in the oven to bake for 20-25 minutes, or until golden brown.&lt;br /&gt;&lt;br /&gt;6. In the bottom of your salad bowl use a fork to whisk together the mustard, vinegar and olive oil. Season with salt and pepper. Carefully open the head of lettuce, season inside with salt and pepper. Upend the lettuce headfirst into the salad bowl. Holding the root, wipe the leaves around the bowl to coat in the vinaigrette. Twist the root and pull it out. Turn the dressed head of lettuce onto a large plate and gently open out.&lt;br /&gt;&lt;br /&gt;7. Portion out the lasagne and serve alongside the salad.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-1091395059330500216?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/1091395059330500216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=1091395059330500216' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1091395059330500216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/1091395059330500216'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/03/entree-gordon-ramsey-cookalong-lasagna.html' title='[Entree] Gordon Ramsey Cookalong Lasagna, Take 2'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_bWjdmMMojdk/SZOLl_lG3PI/AAAAAAAAAlk/gXfkat0KdZU/s72-c/IMG00073-20090211-2035-795039.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-802982347649666134</id><published>2009-03-02T17:26:00.002-06:00</published><updated>2009-04-23T08:57:30.910-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Baba'/><category scheme='http://www.blogger.com/atom/ns#' term='dumplings'/><category scheme='http://www.blogger.com/atom/ns#' term='Russian'/><title type='text'>[Russian] Olga's Haluski</title><content type='html'>No baking on this one, but a really good Russian version of dumplings. This recipe includes all the stuff we serve it with; potatoes, kielbasa, onions.  It's very simple, tastes really good, is very filling, and cheap.  Russian poverty food, with some meat added.&lt;br /&gt;&lt;br /&gt;Ingredients:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Heluski&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;4 Cups AP flour&lt;br /&gt;&lt;/li&gt;&lt;li&gt;1.25 cup warm water&lt;br /&gt;&lt;/li&gt;&lt;li&gt;1 teaspoon salt&lt;br /&gt;&lt;/li&gt;&lt;li&gt;1 tablespoon oil&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;3 medium potatoes&lt;/li&gt;&lt;li&gt;Vinegar (serve with food)&lt;/li&gt;&lt;li&gt;1-2 pounds of kielbasa/sausage&lt;br /&gt;&lt;/li&gt;&lt;li&gt;3 medium onions&lt;ul&gt;&lt;li&gt;1 stick of butter&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;Onions:&lt;br /&gt;First, we need to cook the onions down, since this takes longer than the other steps.  Peel and slice 3 medium onions into rings.  Put in a pan, add one stick butter, cover, and cook on medium until clarified.  Once this occurs, turn it to medium-high (not high but close to it) and let them fry and caramellize.  You want to fry the onions.  Once you get them nice and brown, turn to low.  Yes, there will be an oil slick of butter; that's fine&lt;br /&gt;&lt;br /&gt;Meat:&lt;br /&gt;In another pan, cook kielbasa or a sausage.  Cut into whatever size you desire (4-5 inch-long pieces work best).  Cook and brown to taste, and once cooked set on low.  This step can be done at the same time as the boiling, but doing it ahead of time will make it easier if you're not a whiz in the kitchen.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Haluski:&lt;br /&gt;To make the Haluski itself, mix all 4 ingredients together and knead on a floured board. When I did it, it initially was very dry, but as it was kneaded it came together and absorbed all the flour. The consistency when done was not sticky, and texture was almost plasticine. Now, take a hunk of the dough and roll it with your hand into what looks like a snake - a round, long strip of dough about 1 inch thick. Once you have that, take a butter knife or regular non-sharp knife and cut off slices about 1/4-1/2 inch thick. It will deform as you do it; that's fine. The end result looks like this:&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_bWjdmMMojdk/SatzcIdfTqI/AAAAAAAAAl8/e_9eUGI9q2Y/s1600-h/IMG00115-20090228-1912.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_bWjdmMMojdk/SatzcIdfTqI/AAAAAAAAAl8/e_9eUGI9q2Y/s320/IMG00115-20090228-1912.jpg" alt="" id="BLOGGER_PHOTO_ID_5308463512930963106" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Potatoes:&lt;br /&gt;Peel 2-3 Medium potatoes.  Add to pot of water, with about 2tbl salt, and boil until about mostly done. At this point, add haluski, all at once (yes, this'll drop the temperature) and boil approximately 4-5 minutes.  The haluski will float to the top when done; you can either fish out the potatoes &amp; haluski, or drain.&lt;br /&gt;&lt;br /&gt;Serving:&lt;br /&gt;Get a large serving bowl.  Pour the haluski and potatoes into it, pour the onions &amp;amp; butter over them, then take the sausage and place it on top.&lt;br /&gt;&lt;br /&gt;Eating:&lt;br /&gt;In our family, we use a serving spoon to grab mass quantities of potatoes/heluski, and a piece or two of kielbasa.  Pour a splash of vinegar over the potatoes/onions/heluski - even my wife the Southerner agrees on that.  Eat.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-802982347649666134?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/802982347649666134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=802982347649666134' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/802982347649666134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/802982347649666134'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/03/russian-olgas-haluski.html' title='[Russian] Olga&apos;s Haluski'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_bWjdmMMojdk/SatzcIdfTqI/AAAAAAAAAl8/e_9eUGI9q2Y/s72-c/IMG00115-20090228-1912.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-5644295154771203392</id><published>2009-03-02T14:23:00.002-06:00</published><updated>2009-03-02T14:30:05.372-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='indexes'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Index] Find duplicate indexes</title><content type='html'>I've been working on indexes lately, if it's not been obvious.  I went looking for code to detect identical indexes, and this one seems the best.&lt;br /&gt;&lt;br /&gt;http://sqlblog.com/blogs/paul_nielsen/archive/2008/06/25/find-duplicate-indexes.aspx&lt;br /&gt;&lt;br /&gt;Here's the top one, which looks for identical indexes.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;-- exact duplicates&lt;br /&gt;with indexcols as&lt;br /&gt;(&lt;br /&gt;select object_id as id, index_id as indid, name,&lt;br /&gt;(select case keyno when 0 then NULL else colid end as [data()]&lt;br /&gt;from sys.sysindexkeys as k&lt;br /&gt;where k.id = i.object_id&lt;br /&gt;and k.indid = i.index_id&lt;br /&gt;order by keyno, colid&lt;br /&gt;for xml path('')) as cols,&lt;br /&gt;(select case keyno when 0 then colid else NULL end as [data()]&lt;br /&gt;from sys.sysindexkeys as k&lt;br /&gt;where k.id = i.object_id&lt;br /&gt;and k.indid = i.index_id&lt;br /&gt;order by colid&lt;br /&gt;for xml path('')) as inc&lt;br /&gt;from sys.indexes as i&lt;br /&gt;)&lt;br /&gt;select&lt;br /&gt;object_schema_name(c1.id) + '.' + object_name(c1.id) as 'table',&lt;br /&gt;c1.name as 'index',&lt;br /&gt;c2.name as 'exactduplicate'&lt;br /&gt;from indexcols as c1&lt;br /&gt;join indexcols as c2&lt;br /&gt;on c1.id = c2.id&lt;br /&gt;and c1.indid &lt; c2.indid&lt;br /&gt;and c1.cols = c2.cols&lt;br /&gt;and c1.inc = c2.inc;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-5644295154771203392?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/5644295154771203392/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=5644295154771203392' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5644295154771203392'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/5644295154771203392'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/03/index-find-duplicate-indexes.html' title='[Index] Find duplicate indexes'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4961718869801839161</id><published>2009-02-12T15:05:00.008-06:00</published><updated>2009-02-26T13:38:32.684-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='convoluted'/><category scheme='http://www.blogger.com/atom/ns#' term='publication'/><title type='text'>[Replication] List your subscriptions, including articles, from the subscriber machine</title><content type='html'>Sometimes you need to know what articles you've received via a subscription.  From Computer B (which is a subscriber), you can run this against Computer a (the publisher or distributor) and get a list of articles (tables) that are being replicated.  A rare thing to need, but durn handy.   You will need a linked server on Computer A that can read from Computer B, and you need to run it against each replicated database.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;(remember that are you need to copy even though you can't see the whole line&lt;br /&gt;DECLARE @sqlstatement VARCHAR(1000)&lt;br /&gt;SELECT @sqlstatement = 'SELECT identity(int, 1,1) as ID,&lt;br /&gt;* INTO ##Publications FROM OPENQUERY([computera],&lt;br /&gt;''SET FMTONLY OFF {call replicated_db..sp_helpsubscription}'')'&lt;br /&gt;&lt;br /&gt;EXEC(@sqlstatement)&lt;br /&gt;SELECT * FROM ##publications where subscriber = @@servername&lt;br /&gt;DROP TABLE ##publications&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4961718869801839161?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4961718869801839161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4961718869801839161' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4961718869801839161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4961718869801839161'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/02/replication-list-your-subscriptions.html' title='[Replication] List your subscriptions, including articles, from the subscriber machine'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2717523954910115576</id><published>2009-02-11T09:39:00.003-06:00</published><updated>2009-02-11T09:41:41.065-06:00</updated><title type='text'>[Query] Case-sensitive query on a case-insensitive server</title><content type='html'>SQL Collations play an important role in queries - if you're lucky enough to have a case-insensitive server (which many are; it's the default), then you are saved from having to make sure EveryThing Is Capitalized just Right.&lt;br /&gt;&lt;br /&gt;However, there are times when you need it.&lt;br /&gt;http://www.mssqltips.com/tip.asp?tip=1032&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;span style="font-family:Arial;"&gt;SELECT&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;*&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;FROM&lt;/span&gt;&lt;span style="font-size:85%;"&gt; dbo&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;.&lt;/span&gt;&lt;span style="font-size:85%;"&gt;CaseSensitiveTest&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;WHERE&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Value1 &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;LIKE&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#ff0000;"&gt;'%Test%'&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;Collate&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Arial;"&gt; SQL_Latin1_General_CP1_CI_AS&lt;br /&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That will give you only the values that are capitalized like "Test" is.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2717523954910115576?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2717523954910115576/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2717523954910115576' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2717523954910115576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2717523954910115576'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/02/query-case-sensitive-query-on-case.html' title='[Query] Case-sensitive query on a case-insensitive server'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-3421274445531884680</id><published>2009-02-10T12:38:00.002-06:00</published><updated>2009-02-10T12:42:32.721-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='BCP'/><category scheme='http://www.blogger.com/atom/ns#' term='BULK INSERT'/><title type='text'>[SQL] BULK INSERT and BCP -n</title><content type='html'>I came across this while rereading the man pages for BCP and BULK INSERT:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;http://msdn.microsoft.com/en-us/library/ms188365.aspx&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;DATAFILETYPE value                 &lt;/th&gt;&lt;th&gt;                   All data represented in:                 &lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;strong&gt;native&lt;/strong&gt;                 &lt;/p&gt;               &lt;/td&gt;&lt;td&gt;                 &lt;p&gt;Native (database) data types. Create the native data file by bulk importing data from SQL Server using the &lt;strong&gt;bcp&lt;/strong&gt; utility.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;I like BULK INSERT more than BCP, but you need BCP to export data.  I was unaware that you could BCP a file out in Native format, and use BULK INSERT to import it.  Doh!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-3421274445531884680?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/3421274445531884680/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=3421274445531884680' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3421274445531884680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/3421274445531884680'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/02/sql-bulk-insert-and-bcp-n.html' title='[SQL] BULK INSERT and BCP -n'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8059961320951509978</id><published>2009-02-04T23:02:00.002-06:00</published><updated>2009-02-04T23:18:58.215-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='latkes'/><title type='text'>Latkes!</title><content type='html'>&lt;p class="mobile-photo"&gt;&lt;a href="http://3.bp.blogspot.com/_bWjdmMMojdk/SYpzD6IXAWI/AAAAAAAAAlc/ZuMeYhMVqeo/s1600-h/photo-791151.jpg"&gt;&lt;img src="http://3.bp.blogspot.com/_bWjdmMMojdk/SYpzD6IXAWI/AAAAAAAAAlc/ZuMeYhMVqeo/s400/photo-791151.jpg" alt="" id="BLOGGER_PHOTO_ID_5299174422535930210" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="mobile-photo"&gt;This picture does not do them justice.    They were awesome.   Took about 20 minutes to make, another 20 to cook.  Came out really well, considering I've never made latkes (potato pancakes) before.  Only change I made was to add more oil in the pan - 2 tbl of oil isn't enough.  And since I hadn't made them before, I decided to skip the ricer - layer paper towels and potatoes in a bowl, then push down with all your might and get as much water out as possible.&lt;br /&gt;&lt;/p&gt;The below link is safe, but the page with the recipe does have some... interesting pictures.&lt;br /&gt;&lt;p class="mobile-photo"&gt;http://www.boingboing.net/2008/12/29/susie-bright-the-lea.html&lt;br /&gt;&lt;/p&gt;&lt;p class="mobile-photo"&gt;Why is this baking?  Easy - store them in a warm oven while you make them.  And this way you're not worrying about the others getting cold.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8059961320951509978?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8059961320951509978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8059961320951509978' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8059961320951509978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8059961320951509978'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/02/latkes.html' title='Latkes!'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_bWjdmMMojdk/SYpzD6IXAWI/AAAAAAAAAlc/ZuMeYhMVqeo/s72-c/photo-791151.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8519010808366209425</id><published>2009-02-04T22:49:00.003-06:00</published><updated>2009-02-04T22:54:41.763-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sweets'/><category scheme='http://www.blogger.com/atom/ns#' term='baking'/><category scheme='http://www.blogger.com/atom/ns#' term='dessert'/><title type='text'>[Sweets] Nutella Biscotti</title><content type='html'>&lt;p class="mobile-photo"&gt;&lt;a href="http://2.bp.blogspot.com/_bWjdmMMojdk/SYpwJl4rGxI/AAAAAAAAAlU/hCIkO6pxxn0/s1600-h/photo-746420.jpg"&gt;&lt;img src="http://2.bp.blogspot.com/_bWjdmMMojdk/SYpwJl4rGxI/AAAAAAAAAlU/hCIkO6pxxn0/s400/photo-746420.jpg" alt="" id="BLOGGER_PHOTO_ID_5299171221645761298" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;And now for something actually baked.&lt;br /&gt;&lt;br /&gt;Recipe from here: http://bakingbites.com/2005/06/nutella-biscotti/  Note that my picture doesn't look as good as their picture.  But I will say, it came out quite well following the recipe as written.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8519010808366209425?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8519010808366209425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8519010808366209425' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8519010808366209425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8519010808366209425'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/02/sweets-nutella-biscotti.html' title='[Sweets] Nutella Biscotti'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_bWjdmMMojdk/SYpwJl4rGxI/AAAAAAAAAlU/hCIkO6pxxn0/s72-c/photo-746420.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4778526710324091119</id><published>2009-01-29T13:29:00.003-06:00</published><updated>2009-01-29T13:33:13.723-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xp_cmdshell'/><category scheme='http://www.blogger.com/atom/ns#' term='temp tables'/><category scheme='http://www.blogger.com/atom/ns#' term='profiler'/><category scheme='http://www.blogger.com/atom/ns#' term='error'/><title type='text'>[Profiler] Found: "Error: 208, Severity: 16, State: 0"</title><content type='html'>So, while running some code, trying to figure out why it's failing, I see this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Error: 208, Severity: 16, State: 0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;What is it, you ask?  Some sort of weird bug, maybe, involving temp tables.&lt;br /&gt;&lt;br /&gt;Run this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;exec ('exec master..xp_cmdshell ''dir c:\''')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;No problems.&lt;br /&gt;&lt;br /&gt;Run this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;create table #Listing (results varchar (255))&lt;br /&gt;insert #Listing (results) &lt;br /&gt;exec ('exec master..xp_cmdshell ''dir c:\''')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Bingo.  &lt;br /&gt;&lt;br /&gt;Why is this the case?  I wish I knew.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4778526710324091119?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4778526710324091119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4778526710324091119' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4778526710324091119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4778526710324091119'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/01/profiler-found-error-208-severity-16.html' title='[Profiler] Found: &quot;Error: 208, Severity: 16, State: 0&quot;'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4901334572003213111</id><published>2009-01-23T08:41:00.004-06:00</published><updated>2009-01-23T08:51:38.777-06:00</updated><title type='text'>[Tuning] Getting rid of Dynamic SQL</title><content type='html'>We've all done it.  There's times when you just need to write something quick and dirty that deals with a simple problem.  And there doesn't seem to be an easy way to make it proper SQL, so you write some dynamic SQL instead.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE PROCEDURE cases_select_dynamic&lt;br /&gt;@sortBy varchar(100),&lt;br /&gt;  @status Int&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;IF len(@sortBy)&gt;0&lt;br /&gt;BEGIN&lt;br /&gt; DECLARE @sql varchar(max)&lt;br /&gt; SET @sql='SELECT * FROM cases WHERE &lt;br /&gt;    status = ''' + CONVERT(VARCHAR(100),@status) + '''&lt;br /&gt; order by ' + @sortBy&lt;br /&gt; EXEC (@sql)&lt;br /&gt;END&lt;br /&gt;ELSE&lt;br /&gt;BEGIN&lt;br /&gt; SELECT * FROM cases WHERE &lt;br /&gt;    status = @status&lt;br /&gt;END&lt;br /&gt;END&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Fortunately, there are people out there who don't particularly like dynamic SQL.  Fortunately for us, because they've found ways around it.  Instead of the above, do something like &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE PROCEDURE cases_select_nondynamic&lt;br /&gt;  @sortBy varchar(100),&lt;br /&gt;  @status Int&lt;br /&gt;as &lt;br /&gt;BEGIN&lt;br /&gt; SELECT * &lt;br /&gt; FROM cases&lt;br /&gt; WHERE  status = @status&lt;br /&gt; order by CASE @sortBy WHEN 'finished' THEN finished ELSE NULL END, &lt;br /&gt;   CASE @sortBy WHEN 'name' THEN name ELSE NULL END, &lt;br /&gt;   CASE @sortBy WHEN 'lead' THEN lead ELSE NULL END&lt;br /&gt;END&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Which does the same thing.  A little more work, but you gain several benefits.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Dynamic SQL runs under the users context, so they need perms to the tables. Nondynamic means you just grant normal SP rights.&lt;br /&gt;&lt;li&gt;Cached plans.  2000/2005 are good about reusing the cached plan - if it's IDENTICAL.  Unless people are always running the exact same query, parameters and all, it won't cache.  Nondynamic gets cached once and used for all parameters.&lt;br /&gt;&lt;li&gt;Faster.  In my case, running the exact same parameters for both versions resulted in the dynamic version having a 89% Query cost (relative to the batch), while the nondynamic version was a mere 11%.  &lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;So go out there and convert 1 SP today to be nondynamic.  Read Erland's page, he's got a lot of examples and a lot of thought in there.  &lt;br /&gt;&lt;br /&gt;http://www.sommarskog.se/dynamic_sql.html .  Erland is a SQL god.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4901334572003213111?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4901334572003213111/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4901334572003213111' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4901334572003213111'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4901334572003213111'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/01/tuning-getting-rid-of-dynamic-sql.html' title='[Tuning] Getting rid of Dynamic SQL'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-362713693553251492</id><published>2009-01-15T17:41:00.003-06:00</published><updated>2009-01-15T17:45:14.782-06:00</updated><title type='text'>[SQL] A very easy way to convert tinyint to hex</title><content type='html'>&lt;pre&gt;&lt;br /&gt;SELECT CONVERT(VARBINARY(1), 254)&lt;br /&gt;0xFE&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you need more leading zeroes, raise the size of the Varbinary.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT CONVERT(VARBINARY(8), 254)&lt;br /&gt;0x000000FE&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-362713693553251492?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/362713693553251492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=362713693553251492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/362713693553251492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/362713693553251492'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/01/sql-very-easy-way-to-convert-tinyint-to.html' title='[SQL] A very easy way to convert tinyint to hex'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-9155921259665885113</id><published>2009-01-12T11:06:00.003-06:00</published><updated>2009-01-12T11:09:26.353-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='sp_msforeachdb'/><title type='text'>[SQL] Running code on most databases on a server</title><content type='html'>Everybody should already be using sp_MSforeachDB to do things in all databases.  &lt;br /&gt;&lt;br /&gt;This is a really cheap way of only doing it to some databases; just add the list in two single-quotes (since you're running it within sp_MSforeachDB)&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sp_MSforeachdb 'if ''?'' NOT IN (''tempdb'')&lt;br /&gt;begin &lt;br /&gt; use ?&lt;br /&gt; exec sp_updatestats &lt;br /&gt;end' &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-9155921259665885113?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/9155921259665885113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=9155921259665885113' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9155921259665885113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9155921259665885113'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/01/sql-running-code-on-most-databases-on.html' title='[SQL] Running code on most databases on a server'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-8667163281948700652</id><published>2009-01-08T15:15:00.002-06:00</published><updated>2009-01-08T22:46:19.536-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notification'/><category scheme='http://www.blogger.com/atom/ns#' term='email'/><title type='text'>[Notification] and a version to watch a SPID</title><content type='html'>&lt;pre&gt;&lt;br /&gt;WHILE (SELECT    COUNT(*)&lt;br /&gt;FROM     sysprocesses WHERE spid = 230 AND cmd IN ('ALTER table','CREATE index')&lt;br /&gt;)&gt;=1&lt;br /&gt;BEGIN &lt;br /&gt;  PRINT 'waiting'&lt;br /&gt;        WAITFOR DELAY '00:01:00'&lt;br /&gt;END         &lt;br /&gt;&lt;br /&gt;EXEC msdb.dbo.sp_send_dbmail&lt;br /&gt;    @profile_name = 'DBA',&lt;br /&gt;    @recipients = 'dba@thebakingdba.com',&lt;br /&gt;    @subject = 'index creation done'&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-8667163281948700652?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/8667163281948700652/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=8667163281948700652' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8667163281948700652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/8667163281948700652'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/01/notification-and-version-to-watch-spid.html' title='[Notification] and a version to watch a SPID'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-7909002734245412767</id><published>2009-01-07T16:44:00.003-06:00</published><updated>2009-01-08T22:46:37.024-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notification'/><category scheme='http://www.blogger.com/atom/ns#' term='email'/><category scheme='http://www.blogger.com/atom/ns#' term='jobs'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>[Jobs] Code to email when job finishes</title><content type='html'>If you have to run a job outside its normal time, and didn't remember to change the notification before you ran it, fret not.  By hitting the system tables, you can have it notify you when the job finishes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;WHILE (SELECT    COUNT(*) &lt;br /&gt;FROM     msdb.dbo.sysjobhistory h&lt;br /&gt;         INNER JOIN msdb.dbo.sysjobs j&lt;br /&gt;           ON h.job_id = j.job_id&lt;br /&gt;         INNER JOIN msdb.dbo.sysjobsteps s&lt;br /&gt;           ON j.job_id = s.job_id&lt;br /&gt;           AND h.step_id = s.step_id&lt;br /&gt;WHERE    h.run_date &gt;= '20090107' and --today's date&lt;br /&gt;         j.NAME = 'your_job_name' AND &lt;br /&gt;--max step for the job, so you don't get emailed when step 1 of 5 finishes&lt;br /&gt;         h.step_id = 3 &lt;br /&gt;         )=0&lt;br /&gt;BEGIN &lt;br /&gt;  PRINT 'waiting'&lt;br /&gt;        WAITFOR DELAY '00:01:00'&lt;br /&gt;END         &lt;br /&gt;&lt;br /&gt;EXEC msdb.dbo.sp_send_dbmail&lt;br /&gt;    @profile_name = 'DBAs',&lt;br /&gt;    @recipients = 'thebakingdba@yourcompanyname.com',&lt;br /&gt;    @query = 'SELECT    j.[name],&lt;br /&gt;         s.step_name,&lt;br /&gt;         h.step_id,&lt;br /&gt;         h.step_name,&lt;br /&gt;         h.run_date,&lt;br /&gt;         h.run_time,&lt;br /&gt;         h.sql_severity,&lt;br /&gt;         h.SERVER,&lt;br /&gt;         h.run_status&lt;br /&gt;FROM     msdb.dbo.sysjobhistory h&lt;br /&gt;         INNER JOIN msdb.dbo.sysjobs j&lt;br /&gt;           ON h.job_id = j.job_id&lt;br /&gt;         INNER JOIN msdb.dbo.sysjobsteps s&lt;br /&gt;           ON j.job_id = s.job_id&lt;br /&gt;           AND h.step_id = s.step_id&lt;br /&gt;WHERE    h.run_date &gt;= ''20090107'' and &lt;br /&gt;         j.NAME = ''your_job_name'' AND &lt;br /&gt;         h.step_id = 3&lt;br /&gt;' ,&lt;br /&gt;    @subject = 'Your Job Finished',&lt;br /&gt;    @query_result_separator =  ' ',&lt;br /&gt;    @query_result_width = 750,&lt;br /&gt;    @attach_query_result_as_file = 0 ;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-7909002734245412767?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/7909002734245412767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=7909002734245412767' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7909002734245412767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/7909002734245412767'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2009/01/jobs-code-to-email-when-job-finishes.html' title='[Jobs] Code to email when job finishes'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-4226653027617881352</id><published>2008-12-30T13:54:00.002-06:00</published><updated>2009-04-30T00:14:08.699-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Baba'/><category scheme='http://www.blogger.com/atom/ns#' term='Russian'/><title type='text'>[Russian] Olga's Cabbage Rolls (Holubtsi/Helutsi)</title><content type='html'>(apparently my original posting showed up with the original date I started - reposting so that it's at the top)&lt;br /&gt;&lt;br /&gt;Let's see, we've done my Baba's borscht (which, honestly, you should make - calling it "beet soup" does it a disservice, especially when the beet slivers are white when done), but we still have several left to do:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Piroshki (meat pies, baked)&lt;br /&gt;&lt;li&gt;Piroshki (potato pies, fried)&lt;br /&gt;&lt;li&gt;Vareniki&lt;br /&gt;&lt;li&gt;Haluski (helushki?)&lt;br /&gt;&lt;li&gt;Pork Stew (Goulash)&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;...and Cabbage Rolls (aka "pigs in a blanket", aka "heh-lute-see", which according to Wikipedia is probably spelled Holubtsi but I'm not positive of.) &lt;br /&gt;&lt;br /&gt;Basically it's just beef, rice &amp;amp; onions wrapped in a cabbage leaf, fried in a tiny bit of oil, then baked with a sour cream &amp;amp; tomato sauce.  So, it &lt;span style="font-style: italic;"&gt;does &lt;/span&gt;count as baking!  *laugh*  I spent the better half of a day working with Baba on this, taking her recipe and adding footnotes.&lt;br /&gt;&lt;br /&gt;And yes, it tastes much better than that description.  Think spiced meat served with a pink sauce, and you're not far off.&lt;br /&gt;&lt;br /&gt;Ingredients for the Cabbage Rolls themselves:&lt;br /&gt;3 lb chuck meat (lean), &lt;span style="font-weight: bold;"&gt;OR &lt;/span&gt;2 lb chuck meat (lean) and 1 pound boneless country ribs&lt;br /&gt;1 1/2 cup rice, cooked as it directs&lt;br /&gt;3 medium onions, diced and chopped&lt;br /&gt;6+ tbl corn oil&lt;br /&gt;5 tbl dried parsley&lt;br /&gt;salt &amp;amp; pepper to taste&lt;br /&gt;2-3 heads cabbage&lt;br /&gt;&lt;br /&gt;Ingredients for the sauce:&lt;br /&gt;15 oz can tomato sauce&lt;br /&gt;8 oz can tomato sauce&lt;br /&gt;10.5 oz beef buillion (we use the Campbell's double strength, but you can also use regular beef broth)&lt;br /&gt;8 oz sour cream&lt;br /&gt;&lt;br /&gt;Equipment needed:&lt;br /&gt;Grinder (coarse blade)&lt;br /&gt;&lt;br /&gt;Prepping the filling:&lt;br /&gt;Take your meat and boil it in water, at least enough to cover.  Save 1/2 cup broth.  You can do either all beef, or beef and pork - she normally does beef &amp;amp; pork, but not everybody likes pork.&lt;br /&gt;Take the cooked meat and grind on the coarse setting.  Yes, you need to cook it &lt;span style="font-style: italic;"&gt;then &lt;/span&gt;grind it - the texture is totally different if you do it the other way around.&lt;br /&gt;Prepare the 1.5 cups rice as per package directions.&lt;br /&gt;Take the 3 onions, dice and simmer over medium heat with 2-3 tbl oil until clarified.&lt;br /&gt;Now, mix all together - the ground-up &amp;amp; cooked meat, rice, 1/2 cup broth, dried parsley, onions, and salt &amp;amp; pepper to taste.  You definitely want this to taste good on its own, so don't be stingy with the pepper.&lt;br /&gt;&lt;br /&gt;Prepping the rolls:&lt;br /&gt;Take head of cabbage, score the base so that the leaves will be able to come off.  Put in a pot bigger than needed to boil the cabbage.  Add water, then heat to boiling.  Turn off heat after it boils 30 seconds - we are trying to wilt the leaves and make them pliable.  Don't use the whole cabbage - the inner leaves are just too small to hold enough meat.&lt;br /&gt;&lt;br /&gt;Making the rolls:&lt;br /&gt;Pull off the outer-most leaves and throw away.&lt;br /&gt;Remove one leaf at a time.  Cut away as much of the "vein" as possible on the leaves, so that they can be easily folded.  Put 1-2 heaping serving spoon (1.25-2 oz total) of meat in the middle, then fold the sides in, overlapping, then fold over the "top" of the leaf, then fold over the base of the leaf.  You now should have a small package.  Cook this in 2-3 tbl oil on both sides until GBD (golden-brown and delicious), then set aside.  At this point you can freeze them.&lt;br /&gt;&lt;br /&gt;Making the sauce:&lt;br /&gt;In a pot, add the tomato sauce, sour cream, beef bullion, 1-2 tsp black pepper and a SMALL pinch of salt (the beef bullion is a salt lick; if you go the low sodium route, you'll wind up having to add salt at the end.  Sorry, this isn't healthy.)  Heat on medium high heat, stirring frequently, until it comes to a boil.  Boil for 30 seconds then take off heat.&lt;br /&gt;&lt;br /&gt;Putting it all together:&lt;br /&gt;Take a casserole dish (the deeper the better - we use an old corningware dish about 8 inches deep), and layer the rolls inside, open-side up.  You want room between them for the sauce - don't just cram them together.  I say open-side up because it's more forgiving when you're pulling them out, but be careful when pouring the sauce lest they open.  Pour the sauce over until they're almost completely covered.  Bake in a 350-degree oven for 30 minutes - you want it to be bubbly.  Use a cooking spoon to pull out 2-3 rolls per person, pouring over sauce as desired.  You can either cut it up and eat it, or (for those that don't like cabbage) remove the leaves and pour the sauce over the meat.  Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-4226653027617881352?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/4226653027617881352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=4226653027617881352' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4226653027617881352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/4226653027617881352'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2008/12/russian-olgas-cabbage-rolls.html' title='[Russian] Olga&apos;s Cabbage Rolls (Holubtsi/Helutsi)'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-2124091277726569826</id><published>2008-12-30T10:25:00.006-06:00</published><updated>2011-08-25T09:52:30.442-05:00</updated><title type='text'>[Indexes] Size of unused indexes</title><content type='html'>Was reading an old post of mine, and wanted to revisit it and add the ability to check the sizes of unused indexes.  Pretty easy.&lt;br /&gt;&lt;br /&gt;Updated this from a subquery to an inner join, which gives you the usage stats as well.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select&lt;br /&gt;-- i.[object_id],&lt;br /&gt;-- i.index_id,&lt;br /&gt; o.name as Table_Name,&lt;br /&gt; i.NAME AS Index_Name,&lt;br /&gt; i.type_desc,&lt;br /&gt;-- p.partition_number,&lt;br /&gt; p.rows as [#Records],&lt;br /&gt; a.total_pages * 8 as [Reserved(kb)],&lt;br /&gt; a.used_pages * 8 as [Used(kb)],&lt;br /&gt; s.user_seeks,&lt;br /&gt; s.user_scans,&lt;br /&gt; s.user_lookups&lt;br /&gt;from &lt;br /&gt; sys.indexes as i&lt;br /&gt;inner join&lt;br /&gt; sys.partitions as p&lt;br /&gt;on i.object_id = p.object_id&lt;br /&gt; and i.index_id = p.index_id&lt;br /&gt;inner join SYS.OBJECTS O&lt;br /&gt; ON I.OBJECT_ID = O.OBJECT_ID&lt;br /&gt;INNER JOIN sys.allocation_units AS a&lt;br /&gt;on (a.type = 2 AND p.partition_id = a.container_id)&lt;br /&gt;OR ((a.type = 1 OR a.type = 3) AND p.hobt_id = a.container_id)&lt;br /&gt;INNER JOIN SYS.DM_DB_INDEX_USAGE_STATS S&lt;br /&gt;  ON S.OBJECT_ID = I.OBJECT_ID&lt;br /&gt;  AND I.INDEX_ID = S.INDEX_ID&lt;br /&gt;  AND DATABASE_ID = DB_ID(DB_NAME())&lt;br /&gt;and o.type_desc NOT IN ('SYSTEM_TABLE', 'INTERNAL_TABLE')           -- No system tables!&lt;br /&gt;AND (ISNULL(s.user_seeks, 0) + ISNULL(s.user_scans, 0) + ISNULL(s.user_lookups, 0)) &lt; 100&lt;br /&gt;WHERE    &lt;br /&gt; OBJECTPROPERTY(O.OBJECT_ID,'IsUserTable') = 1&lt;br /&gt; AND i.TYPE_DESC &lt;&gt; 'HEAP'&lt;br /&gt; and i.type &lt;&gt; 1 -- clustered index&lt;br /&gt;order by&lt;br /&gt;o.NAME, i.name&lt;br /&gt;GO&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-2124091277726569826?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/2124091277726569826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=2124091277726569826' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2124091277726569826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/2124091277726569826'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2008/12/indexes-size-of-unused-indexes.html' title='[Indexes] Size of unused indexes'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1434113132981005034.post-9067508491061955859</id><published>2008-12-08T11:11:00.003-06:00</published><updated>2008-12-08T11:15:42.115-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell scripts'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><title type='text'>[Unix] File management</title><content type='html'>Yes, I know - it's neither Baking nor DBA.  But still relevant.&lt;br /&gt;&lt;br /&gt;I had a set of files named &lt;filename&gt;.Z.aa that I needed to decompress.  GUNZIP doesn't like those extensions, so it ignores it.  Here's a basic hack using Cygwin.  (You &lt;span style="font-weight: bold;"&gt;are &lt;/span&gt;using Cygwin, right?)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;for i in *.Z.aa;&lt;br /&gt;do&lt;br /&gt;&lt;/span&gt;    &lt;span style="font-size:100%;"&gt;j=`basename $i .aa`;&lt;br /&gt;   echo &lt;/span&gt;&lt;span style="font-size:100%;"&gt;mv $i $j;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;    mv $i $j;&lt;br /&gt;   echo &lt;/span&gt;&lt;span style="font-size:100%;"&gt;gunzip $j;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;    gunzip $j;&lt;br /&gt;done&lt;br /&gt;&lt;/span&gt;&lt;/filename&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1434113132981005034-9067508491061955859?l=thebakingdba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thebakingdba.blogspot.com/feeds/9067508491061955859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1434113132981005034&amp;postID=9067508491061955859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9067508491061955859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1434113132981005034/posts/default/9067508491061955859'/><link rel='alternate' type='text/html' href='http://thebakingdba.blogspot.com/2008/12/unix-file-management.html' title='[Unix] File management'/><author><name>bourgon</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
