<?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:blogger='http://schemas.google.com/blogger/2008' 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-2453693540149032389</id><updated>2025-04-07T02:43:30.413+01:00</updated><category term="bookmark"/><category term="tsql"/><category term="sql 2008"/><category term="ssis"/><category term="performance"/><category term="systems"/><category term="windows 2008"/><category term="security"/><category term="indexes"/><category term="career"/><category term="hyper-v"/><category term="sysadmin"/><category term="tools"/><category term="networking"/><category term="compression"/><category term="sql 2005"/><category term="permissions"/><category term="backups"/><category term="configuration"/><category term="active directory"/><category term="dmv"/><category term="group policy"/><category term="101"/><category term="email"/><category term="linked servers"/><category term="sql agent"/><category term="system objects"/><category term="vista"/><category term="Windows 7"/><category term="datetime"/><category term="scripts"/><category term="searching"/><category term="service broker"/><category term="constraints"/><category term="sqlservercentral"/><category term="xml"/><category term="blogging"/><category term="clr"/><category term="ssrs"/><category term="BI"/><category term="ole"/><category term="partitioning"/><category term="reporting services"/><category term="restore"/><category term="sqlbits"/><category term="virtualbox"/><category term="pbm"/><category term="replication"/><category term="schema"/><category term="shrink"/><category term="table compression"/><category term="wsus"/><category term="xp"/><category term="Agile / Scrum"/><category term="admin"/><category term="annoyances"/><category term="blocking"/><category term="cdc"/><category term="code"/><category term="community"/><category term="connectivity"/><category term="crosstab"/><category term="datawarehouse"/><category term="design"/><category term="diagramming"/><category term="function"/><category term="iis"/><category term="jdbc"/><category term="mysql"/><category term="nulls"/><category term="openrowset"/><category term="pivot"/><category term="recovery mode"/><category term="resource governor"/><category term="sql 2000"/><category term="sql 2008 r2"/><category term="testing"/><category term="video notes"/><category term="asp"/><category term="caching"/><category term="collation"/><category term="compatibility"/><category term="dynamic sql"/><category term="event forwarding"/><category term="excel"/><category term="mac"/><category term="memory"/><category term="news"/><category term="opendatasource"/><category term="powershell"/><category term="schemas"/><category term="sql 2011"/><category term="sql 2012"/><category term="ssc"/><category term="storage"/><category term="synonyms"/><category term="tds"/><category term="vba"/><category term="video"/><category term="view"/><category term="virtual pc 2007"/><category term="web"/><category term="windows 2000"/><category term="windows 2008 R2"/><title type='text'>sql solace</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/09999231147372917249</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBEy_w40HAzDnQTAFOQXhQcKBHGkD_HykVp0fxuslYTTzpAw60hZo_tM6DklabneJ5ZPeTe343qb7h-k0R5f_xiN8IvXpYgHKMGcFYZv51Gc_72Db2djQXqHOr8B_1M44/s220/r5d4-2.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1043</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-6806421678778302319</id><published>2020-03-01T18:04:00.000+00:00</published><updated>2020-03-01T18:04:40.346+00:00</updated><title type='text'>NSSM : Starting applications on startup</title><content type='html'>Great tool to start applications on startup.

&lt;a href=&quot;https://nssm.cc/download&quot;&gt;NSSM : The Non sucking service manager.&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/6806421678778302319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/6806421678778302319?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/6806421678778302319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/6806421678778302319'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2020/03/nssm-starting-applications-on-startup.html' title='NSSM : Starting applications on startup'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-3790465278279628377</id><published>2019-10-23T21:05:00.001+01:00</published><updated>2019-10-23T21:05:11.093+01:00</updated><title type='text'>Cursor : Loop Tables</title><content type='html'>Cursor to loop tables.
&lt;br /&gt;
&lt;br /&gt;
I use this pattern a lot in DBA&amp;nbsp; scripts...&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;DECLARE @SQL NVARCHAR(1000)
DECLARE @input_schema VARCHAR(100)
DECLARE @input_table VARCHAR(100)
DECLARE @current_schema VARCHAR(100)
DECLARE @current_table VARCHAR(100)

SET @input_schema = null
SET @input_table = null

DECLARE tablecursor CURSOR FOR
  SELECT table_schema, table_name
  FROM   information_schema.TABLES
  WHERE  TABLE_TYPE = &#39;BASE TABLE&#39;
    AND  (TABLE_SCHEMA = @input_schema OR (@input_schema = &#39;&#39; OR @input_schema is null))
    AND  (TABLE_NAME = @input_table OR (@input_table = &#39;&#39; OR @input_table is null))

OPEN tablecursor

FETCH NEXT FROM tablecursor INTO @current_schema, @current_table

WHILE @@FETCH_STATUS = 0
  BEGIN
      SET @SQL = &#39;EXEC add_to_table_queue &#39;+ @current_schema + &#39; , &#39; + @current_table

      PRINT @SQL
      --EXEC Sp_executesql @SQL

      FETCH NEXT FROM tablecursor INTO @current_schema, @current_table
  END

CLOSE tablecursor
DEALLOCATE tablecursor 

&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/3790465278279628377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/3790465278279628377?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3790465278279628377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3790465278279628377'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2019/10/cursor-loop-tables.html' title='Cursor : Loop Tables'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-1934666290890022591</id><published>2019-03-19T14:38:00.001+00:00</published><updated>2019-03-19T14:38:06.030+00:00</updated><title type='text'>SQL 2000 : Online &amp; Offline databases</title><content type='html'>I can&#39;t believe I still need these in 2019...

&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;-- SQL 2000 : Offline databases
select * from master..sysdatabases
where status &amp;amp; 512 = 512
and dbid &amp;gt; 4

-- SQL 2000 : Online databases
select * from master..sysdatabases
where status &amp;amp; 512 &amp;lt;&amp;gt; 512
and dbid &amp;gt; 4
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/1934666290890022591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/1934666290890022591?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/1934666290890022591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/1934666290890022591'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2019/03/sql-2000-online-offline-databases.html' title='SQL 2000 : Online &amp; Offline databases'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-8308633459853911640</id><published>2019-01-10T23:27:00.001+00:00</published><updated>2019-11-08T16:13:05.442+00:00</updated><title type='text'>TSQL : Loop a date range</title><content type='html'>Useful for Incremental processing...

&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;DECLARE @minDate DATE
SET @minDate = &#39;1997-02-13&#39;
DECLARE @maxDate DATE
SET @maxDate = GETDATE()
 
DECLARE @Counter INT
DECLARE @CounterText VARCHAR(30)
DECLARE @counterDate DATE
DECLARE @counterDateText VARCHAR(30)
DECLARE @MinCount INT
DECLARE @Stepsize INT
 
DECLARE @stepstart DATETIME
DECLARE @stepend DATETIME
DECLARE @duration bigint
DECLARE @message varchar(200)

SELECT @Counter = DATEDIFF(dd,@minDate,@maxDate)
SELECT @MinCount = 0
SELECT @Stepsize = 1
 
WHILE @Counter &gt;= @MinCount 
 
BEGIN
SET @CounterText = CONVERT(VARCHAR(30),@Counter,23)
--RAISERROR (@CounterText, 10, 1) WITH NOWAIT  
 
SET @counterDate = DATEADD(dd,-@counter,@maxDate)
SET @counterDateText = CONVERT(VARCHAR(30),@counterDate,120)

RAISERROR (@counterDateText, 10, 1) WITH NOWAIT  

SET @stepstart = GETDATE()


-- do useful stuff here
-- WAITFOR DELAY &#39;00:00:01&#39;

SET @stepend = GETDATE()

SET @duration = DATEDIFF(ss,@stepstart,@stepend)
SET @message = &#39;Took &#39; + CONVERT(varchar(20),@duration) + &#39; seconds&#39;
RAISERROR (@message, 10, 1) WITH NOWAIT  

 
SELECT @Counter = @Counter - @Stepsize 
END

&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/8308633459853911640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/8308633459853911640?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8308633459853911640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8308633459853911640'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2019/01/tsql-loop-date-range.html' title='TSQL : Loop a date range'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-8998269546820716207</id><published>2018-12-17T22:48:00.000+00:00</published><updated>2019-05-15T22:49:21.019+01:00</updated><title type='text'>TED Talk : Forget the pecking order at work</title><content type='html'>&lt;br /&gt;
This TED talk feels rather relevant right now&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
Link :&amp;nbsp;&lt;a href=&quot;https://www.ted.com/talks/margaret_heffernan_why_it_s_time_to_forget_the_pecking_order_at_work/up-next&quot;&gt;Forget the pecking order at work&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/8998269546820716207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/8998269546820716207?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8998269546820716207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8998269546820716207'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/12/ted-talk-forget-pecking-order-at-work.html' title='TED Talk : Forget the pecking order at work'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-6786792569968898169</id><published>2018-08-03T23:48:00.001+01:00</published><updated>2018-08-03T23:48:19.666+01:00</updated><title type='text'>Manually Checking Table Statistics</title><content type='html'>How to examine table statistics and update them if necessary

&lt;pre class=&quot;brush: sql&quot;&gt;
UPDATE STATISTICS  dbo.Study WITH FULLSCAN

DBCC SHOW_STATISTICS (&#39;dbo.study&#39;,&#39;pk_study&#39;)

SELECT COUNT(*) AS [RowsInTable] FROM dbo.study
&lt;/pre&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_trXVVYeEbLtvKsihI2V4pPfB8riA16fPzVaRnneX2GTXCp0sLzyCx-dqTP-WlF2hp52K3cPMc-0w7ugkbCVtn8BUo6lhXoSzlFodxyYmNolSo0hxJb5tZc25D1I-xgFVGNnpb2tsRlQ/s1600/statistics_post.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;543&quot; data-original-width=&quot;594&quot; height=&quot;584&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_trXVVYeEbLtvKsihI2V4pPfB8riA16fPzVaRnneX2GTXCp0sLzyCx-dqTP-WlF2hp52K3cPMc-0w7ugkbCVtn8BUo6lhXoSzlFodxyYmNolSo0hxJb5tZc25D1I-xgFVGNnpb2tsRlQ/s640/statistics_post.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/6786792569968898169/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/6786792569968898169?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/6786792569968898169'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/6786792569968898169'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/08/manually-checking-table-statistics.html' title='Manually Checking Table Statistics'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_trXVVYeEbLtvKsihI2V4pPfB8riA16fPzVaRnneX2GTXCp0sLzyCx-dqTP-WlF2hp52K3cPMc-0w7ugkbCVtn8BUo6lhXoSzlFodxyYmNolSo0hxJb5tZc25D1I-xgFVGNnpb2tsRlQ/s72-c/statistics_post.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-3166770687849296394</id><published>2018-07-31T00:40:00.002+01:00</published><updated>2018-07-31T00:40:31.683+01:00</updated><title type='text'>findInName - Stored Procedure to search all object names</title><content type='html'>&lt;pre class=&quot;brush: sql&quot;&gt;
-search all databases
CREATE OR ALTER PROC tools.findInName
(@searchstring VARCHAR(200))
AS
BEGIN
SET NOCOUNT ON
DECLARE @results TABLE (
    [search_term] VARCHAR(255),
    [database_name] VARCHAR(255),
    [schema_name] VARCHAR(255),
    [object_Name] VARCHAR(255),
 [type_desc] VARCHAR(255) )

DECLARE @dbname sysname;
DECLARE @actualsearchstring VARCHAR(200);

SET @actualsearchstring = REPLACE(@searchstring,&#39;_&#39;,&#39;/_&#39;)

DECLARE @dsql nvarchar(max) = &#39;
SELECT  &#39;&#39;&#39; +@searchstring + &#39;&#39;&#39;  AS [search_term]
     ,DB_NAME() AS [database_name]
  ,TABLE_SCHEMA
  ,TABLE_NAME
  ,TABLE_TYPE 
 FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE &#39;&#39;%&#39;+@actualsearchstring+&#39;%&#39;&#39; ESCAPE &#39;&#39;/&#39;&#39;

UNION ALL

SELECT   &#39;&#39;&#39; +@searchstring + &#39;&#39;&#39;  AS [search_term]
     ,DB_NAME() AS [database_name]
     ,ROUTINE_SCHEMA
  ,ROUTINE_NAME
  ,ROUTINE_TYPE 
 FROM INFORMATION_SCHEMA.ROUTINES
 WHERE ROUTINE_NAME LIKE &#39;&#39;%&#39;+@actualsearchstring+&#39;%&#39;&#39; ESCAPE &#39;&#39;/&#39;&#39;

&#39;;
DECLARE @execCommand nvarchar(max);

DECLARE dbs CURSOR STATIC LOCAL FORWARD_ONLY READ_ONLY 
FOR
SELECT name FROM sys.databases (NOLOCK)
OPEN dbs;
FETCH NEXT FROM dbs INTO @dbname;
WHILE @@FETCH_STATUS = 0
BEGIN
    SET @execCommand = &#39;EXEC &#39; + QUOTENAME(@dbname) + &#39;.sys.sp_executesql @dsql&#39;;

    INSERT @results
    EXEC sys.sp_executesql @execCommand, N&#39;@dsql nvarchar(max)&#39;, @dsql

    FETCH NEXT FROM dbs INTO @dbname; 
END

CLOSE dbs;
DEALLOCATE dbs;
SELECT * FROM @results
END
GO

EXEC tools.findInName &#39;_&#39;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/3166770687849296394/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/3166770687849296394?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3166770687849296394'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3166770687849296394'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/07/findinname-stored-procedure-to-search.html' title='findInName - Stored Procedure to search all object names'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-3654279327143331624</id><published>2018-07-31T00:38:00.001+01:00</published><updated>2018-07-31T00:38:35.178+01:00</updated><title type='text'>TSQL - Searching for Escaped Characters</title><content type='html'>Use the ESCAPE keyword to define a character to use to escape a literal.

The _ underscore cannot usually be searched, to do so escape it like this.

&lt;pre class=&quot;brush: sql&quot;&gt;
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE &#39;%/_%&#39; ESCAPE &#39;/&#39;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/3654279327143331624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/3654279327143331624?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3654279327143331624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3654279327143331624'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/07/tsql-searching-for-escaped-characters.html' title='TSQL - Searching for Escaped Characters'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-3885447475207087677</id><published>2018-07-31T00:34:00.001+01:00</published><updated>2018-07-31T00:34:21.622+01:00</updated><title type='text'>findInCode - Stored Procedure to search code in all databases for a string</title><content type='html'>
&lt;pre class=&quot;brush: sql&quot;&gt;
--search all databases
CREATE OR ALTER PROC tools.findInCode
(@searchstring VARCHAR(200))
AS
BEGIN
SET NOCOUNT ON
DECLARE @results TABLE (
     [searchTerm] VARCHAR(255)
    ,[databaseName] VARCHAR(255)
    ,[schemaName] VARCHAR(255)
    ,[objectName] VARCHAR(255)
 ,[typeDesc] VARCHAR(255) )
DECLARE @dbname sysname;
DECLARE @dsql nvarchar(max) = &#39;
 SELECT &#39;&#39;&#39; +@searchstring + &#39;&#39;&#39;  AS [search_term]
   ,DB_NAME() AS [databaseName]
   ,SCHEMA_NAME(schema_id) as schemaName
   ,o.name AS ObjectName
   ,o.type_desc AS typeDesc
 FROM sys.sql_modules m (NOLOCK)
 INNER JOIN sys.objects o (NOLOCK) ON m.object_id = o.object_id
 WHERE m.definition LIKE &#39;&#39;%&#39;+@searchstring+&#39;%&#39;&#39;
&#39;;
DECLARE @execCommand nvarchar(max);

DECLARE dbs CURSOR STATIC LOCAL FORWARD_ONLY READ_ONLY 
FOR
SELECT name FROM sys.databases (NOLOCK)
OPEN dbs;
FETCH NEXT FROM dbs INTO @dbname;
WHILE @@FETCH_STATUS = 0
BEGIN
    SET @execCommand = &#39;EXEC &#39; + QUOTENAME(@dbname) + &#39;.sys.sp_executesql @dsql&#39;;

    INSERT @results
    EXEC sys.sp_executesql @execCommand, N&#39;@dsql nvarchar(max)&#39;, @dsql

    FETCH NEXT FROM dbs INTO @dbname; 
END

CLOSE dbs;
DEALLOCATE dbs;
SELECT * FROM @results
END
GO

EXEC tools.findInCode &#39;findme&#39;


&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/3885447475207087677/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/3885447475207087677?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3885447475207087677'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/3885447475207087677'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/07/findincode-stored-procedure-to-search.html' title='findInCode - Stored Procedure to search code in all databases for a string'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-8252880589444138876</id><published>2018-07-27T00:17:00.000+01:00</published><updated>2018-08-02T00:31:31.224+01:00</updated><title type='text'>Database Mirroring : TSQL Health Scripts</title><content type='html'>
&lt;pre class=&quot;brush: sql&quot;&gt;-- Dynamic Managment View of configuration information

SELECT db_name(sd.[database_id])           AS [Database Name]
      ,sd.mirroring_state                  AS [Mirror State]
      ,sd.mirroring_state_desc             AS [Mirror State]
      ,sd.mirroring_partner_name           AS [Partner Name]
      ,sd.mirroring_role_desc              AS [Mirror Role] 
      ,sd.mirroring_safety_level_desc      AS [Safety Level]
      ,sd.mirroring_witness_name           AS [Witness]
      ,sd.mirroring_connection_timeout AS [Timeout(sec)]
FROM sys.database_mirroring AS sd
WHERE mirroring_guid IS NOT null
ORDER BY [Database Name];
&lt;/pre&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvwD0vueYqgBIx_NdxnrzgfCyC4norwPIG2QoVyFehTGdDiq2-0hHXch6rKiP-qc3NNx_LMkC8NhXNuQZkGgRNxuCJi5wVq6iK12jNoKr1bIaOP7oRXS_EZu-OmE_2g15Jp2QrPQF9U0k/s1600/mirroring_dmv.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;328&quot; data-original-width=&quot;836&quot; height=&quot;155&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvwD0vueYqgBIx_NdxnrzgfCyC4norwPIG2QoVyFehTGdDiq2-0hHXch6rKiP-qc3NNx_LMkC8NhXNuQZkGgRNxuCJi5wVq6iK12jNoKr1bIaOP7oRXS_EZu-OmE_2g15Jp2QrPQF9U0k/s400/mirroring_dmv.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;-- history of all mirored transactions in last 2 hours

USE msdb;

EXEC sp_dbmmonitorresults DatabaseName, 2, 0;
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMG2wjTV683NGnDAa1Pk8mQ6KYnEZ2UFwXeIkm86zyjo4UVokRAXbohT5FrgWz6v_PMxTT0oYXNzHy1RSWrWw0IWMnn977ZvXi8DIDukKYxX9fcei70DNmia8mPWEHn6eZoxMvr3Air2M/s1600/mirroring_mirrored_transactions.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;519&quot; data-original-width=&quot;1229&quot; height=&quot;168&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMG2wjTV683NGnDAa1Pk8mQ6KYnEZ2UFwXeIkm86zyjo4UVokRAXbohT5FrgWz6v_PMxTT0oYXNzHy1RSWrWw0IWMnn977ZvXi8DIDukKYxX9fcei70DNmia8mPWEHn6eZoxMvr3Air2M/s400/mirroring_mirrored_transactions.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;--os performance counters about mirroring

SELECT *,[counter_name] as CounterName,[cntr_value] as CounterValue
FROM sys.dm_os_performance_counters
WHERE [object_name] LIKE (&#39;%Database Mirroring%&#39;)
AND [instance_name]=&#39;mirroredDatabase&#39;
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcX24C4qugLFD_JAWG4eWjgxPu14ipBxf50_Ql6wcnzzpGRxkOgMCCVTwGlpfZ_51q8JodtjbRERHZqmM_9d-cVTBfciUcZ4RZ7ySlygv7Op_gU1Pl4SQRH5I3BZV6kCWFGvCC4ihmi1g/s1600/mirroring_os_performance_counters.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;583&quot; data-original-width=&quot;926&quot; height=&quot;250&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcX24C4qugLFD_JAWG4eWjgxPu14ipBxf50_Ql6wcnzzpGRxkOgMCCVTwGlpfZ_51q8JodtjbRERHZqmM_9d-cVTBfciUcZ4RZ7ySlygv7Op_gU1Pl4SQRH5I3BZV6kCWFGvCC4ihmi1g/s400/mirroring_os_performance_counters.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/8252880589444138876/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/8252880589444138876?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8252880589444138876'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8252880589444138876'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/07/database-mirroring-tsql-health-scripts.html' title='Database Mirroring : TSQL Health Scripts'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvwD0vueYqgBIx_NdxnrzgfCyC4norwPIG2QoVyFehTGdDiq2-0hHXch6rKiP-qc3NNx_LMkC8NhXNuQZkGgRNxuCJi5wVq6iK12jNoKr1bIaOP7oRXS_EZu-OmE_2g15Jp2QrPQF9U0k/s72-c/mirroring_dmv.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-8543566481075979249</id><published>2018-07-22T01:17:00.003+01:00</published><updated>2018-07-22T08:39:33.353+01:00</updated><title type='text'>Linked Server Setting - Promotion of Distributed Transactions</title><content type='html'>This error occured when I tried to access a stored proedure via a linked server.&lt;br /&gt;
Getting the results worked fine, simply executing the stored procedure.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;EXEC [SERVERNAME].[DatabaseName].[SchemaName].[myStoredProcedure]
&lt;/pre&gt;
&lt;br /&gt;
But putting the results into a temporary table meant it became a &#39;distributed transaction&#39;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;CREATE TABLE ##tempTable (column1, column2...)
INSERT INTO ##tempTable
EXEC [SERVERNAME].[DatabaseName].[SchemaName].[myStoredProcedure]
&lt;/pre&gt;
&lt;br /&gt;
OLE DB provider &quot;SQLNCLI10&quot; for linked server &quot;SERVERNAME&quot; returned message &quot;The partner transaction manager has disabled its support for remote/network transactions.&quot;.&lt;br /&gt;
Msg 7391, Level 16, State 2, Line 12&lt;br /&gt;
The operation could not be performed because OLE DB provider &quot;SQLNCLI10&quot; for linked server &quot;SERVERNAME&quot; was unable to begin a distributed transaction.&lt;br /&gt;
&lt;br /&gt;
Both servers were already running the Distributed Transaction Coordinator (DTC) service.&lt;br /&gt;
Multiple posts suggest tuning the security of DTC, but I eventually found the solution was much simpler. Like the setting for Remote Procedure calls &lt;a href=&quot;https://sqlsolace.blogspot.com/2009/09/server-dev-02-is-not-configured-for-rpc.html&quot;&gt;RPC&lt;/a&gt;, it turned out to be a property of the linked server itself, &#39;Enable Promotion of Distributed Transactions&#39;.&lt;br /&gt;
&lt;br /&gt;
The default for &#39;Enable Promotion of Distributed Transactions&#39; is TRUE, setting it to FALSE enabled my code to run.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/8543566481075979249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/8543566481075979249?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8543566481075979249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8543566481075979249'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/07/linked-server-setting-promotion-of.html' title='Linked Server Setting - Promotion of Distributed Transactions'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-5365292456677704858</id><published>2018-07-19T01:23:00.000+01:00</published><updated>2018-07-22T01:24:04.807+01:00</updated><title type='text'>Renaming a Linked Server</title><content type='html'>Simple but very helpful as scripting out a linked server won&#39;t include the password information.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;EXEC master.dbo.sp_serveroption @server=N&#39;OLDNAME&#39;, @optname=N&#39;name&#39;, @optvalue=N&#39;NEWNAME&#39;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/5365292456677704858/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/5365292456677704858?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/5365292456677704858'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/5365292456677704858'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/07/renaming-linked-server.html' title='Renaming a Linked Server'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-7960538398010252615</id><published>2018-07-08T14:01:00.005+01:00</published><updated>2018-07-08T14:01:56.035+01:00</updated><title type='text'>Trace Flag 7470</title><content type='html'>Trace flag 7470 works in SQL 2017! I&#39;m always a little reluctant to use trace flags, especially after reading that Trace flags were becoming redundant due to more database level settings.&lt;br /&gt;
&lt;br /&gt;
Anyway, I&#39;ve eliminated the Sort operator spilling to tempdb by applying 7470.&lt;br /&gt;
&lt;br /&gt;
Note, the documentation says it doesn&#39;t apply to SQL 2017, but I had it on good authority that it would,&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://support.microsoft.com/en-us/help/3088480/fix-sort-operator-spills-to-tempdb-in-sql-server-2012-or-sql-server-20&quot;&gt;Trace Flag 7470 : Fix operator spills to tempdb&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/7960538398010252615/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/7960538398010252615?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/7960538398010252615'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/7960538398010252615'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/07/trace-flag-7470.html' title='Trace Flag 7470'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-4389987712812331793</id><published>2018-06-03T23:21:00.000+01:00</published><updated>2018-06-04T08:25:35.754+01:00</updated><title type='text'>TSQL : HEAP table usage script</title><content type='html'>This script reports usage of HEAP tables over a 15 minute period.&lt;br /&gt;
It reports reads, writes and row counts for the tables.&lt;br /&gt;
I wrote it as I found a system exhibiting high values for Performance Counter &#39;forwarded records/sec&#39;.&lt;br /&gt;
&lt;br /&gt;
See Also : &lt;a href=&quot;http://sqlsolace.blogspot.com/2018/06/tsql-heaps-and-forwarded-records.html&quot;&gt;TSQL : HEAPS and forwarded records&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;IF OBJECT_ID(&#39;tempdb..#Snap1&#39;) IS NOT NULL DROP TABLE #Snap1
IF OBJECT_ID(&#39;tempdb..#Snap2&#39;) IS NOT NULL DROP TABLE #Snap2
IF OBJECT_ID(&#39;tempdb..#rowcounts&#39;) IS NOT NULL DROP TABLE #rowcounts

SELECT   
      s.object_id
    , OBJECT_SCHEMA_NAME(s.object_id) AS schemaname
    , OBJECT_NAME(s.object_id) AS tablename
    , i.name AS indexname
       , SUM(user_seeks) user_seeks, SUM(user_scans) user_scans, SUM(user_lookups) user_lookups, reads = SUM(user_seeks + user_scans + user_lookups), writes =  SUM(user_updates)
INTO #snap1
FROM sys.dm_db_index_usage_stats AS s
INNER JOIN sys.indexes AS i
ON s.object_id = i.object_id
AND i.index_id = s.index_id
WHERE OBJECTPROPERTY(s.object_id,&#39;IsUserTable&#39;) = 1
  AND OBJECTPROPERTY(s.object_id,&#39;TableHasClustIndex&#39;) = 0 -- Reporting only on HEAPS
GROUP BY s.object_id,i.name

WAITFOR DELAY &#39;00:15:00&#39;

SELECT   
      s.object_id
    , OBJECT_SCHEMA_NAME(s.object_id) AS schemaname
    , OBJECT_NAME(s.object_id) AS tablename
    , i.name AS indexname
       , SUM(user_seeks) user_seeks, SUM(user_scans) user_scans, SUM(user_lookups) user_lookups, reads = SUM(user_seeks + user_scans + user_lookups), writes =  SUM(user_updates)
INTO #snap2
FROM sys.dm_db_index_usage_stats AS s
INNER JOIN sys.indexes AS i
ON s.object_id = i.object_id
AND i.index_id = s.index_id
WHERE OBJECTPROPERTY(s.object_id,&#39;IsUserTable&#39;) = 1
  AND OBJECTPROPERTY(s.object_id,&#39;TableHasClustIndex&#39;) = 0 -- Reporting only on HEAPS
GROUP BY s.object_id,i.name

SELECT   sys_schemas.name AS schemaName
  ,sys_objects.name AS tableName
  ,sys_indexes.name AS indexName
  ,SUM(partition_stats.used_page_count) * 8 AS indexsizekb
  ,MAX(partitions.rows) AS tablerows
INTO #rowcounts
FROM sys.dm_db_partition_stats partition_stats
INNER JOIN sys.indexes sys_indexes
  ON partition_stats.[object_id] = sys_indexes.[object_id] 
    AND partition_stats.index_id = sys_indexes.index_id
INNER JOIN sys.objects sys_objects
  ON sys_objects.[object_id] = partition_stats.[object_id] 
INNER JOIN sys.schemas sys_schemas  
  ON sys_objects.[schema_id] = sys_schemas.[schema_id] 
  AND sys_schemas.name &amp;lt;&amp;gt; &#39;SYS&#39;
INNER JOIN sys.partitions partitions
  ON partitions.object_id = partition_stats.object_id 
WHERE OBJECTPROPERTY(sys_objects.object_id,&#39;TableHasClustIndex&#39;) = 0
GROUP BY sys_schemas.name
  ,sys_objects.name
  ,sys_indexes.name
ORDER BY sys_schemas.name
  ,sys_objects.name
  ,sys_indexes.name

SELECT   i.schemaname
  ,i.tablename
  ,i.indexname
  ,(j.user_seeks - i.user_seeks)  AS seeks_period
  ,(i.user_scans - i.user_scans) AS scans_period
  ,(j.user_lookups - i.user_lookups) AS lookups_period
  ,(j.reads - i.reads) AS reads_period
  ,(j.writes - i.writes) AS writes_period
  ,r.tablerows
  ,r.indexsizekb
FROM #Snap1 i
INNER JOIN #Snap2 j ON i.tablename = j.tablename
INNER JOIN #rowcounts r ON r.tableName = i.tablename AND r.indexName = i.indexname
AND COALESCE(i.indexname,&#39;!&#39;) = COALESCE(j.indexname,&#39;!&#39;)
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/4389987712812331793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/4389987712812331793?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/4389987712812331793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/4389987712812331793'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/06/this-script-reports-usage-of-heap.html' title='TSQL : HEAP table usage script'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-7644392875232325293</id><published>2018-06-03T15:27:00.001+01:00</published><updated>2018-06-04T08:24:34.290+01:00</updated><title type='text'>TSQL : HEAPS and Forwarded Records</title><content type='html'>A little bemused that I&#39;m still finding this in application code in the 21st Century, but there you go.

A live app experiencing performance problems due to a significant number of heaps, each frequently used.

&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;SELECT OBJECT_NAME(stats.object_id) as [Table],
idx.name as [Index],
stats.index_type_desc,
stats.page_count,
stats.avg_fragmentation_in_percent,
stats.forwarded_record_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, &#39;DETAILED&#39;) AS stats
INNER JOIN sys.indexes AS idx (NOLOCK)
ON stats.OBJECT_ID = idx.OBJECT_ID
AND stats.index_id = idx.index_id
WHERE forwarded_record_count &amp;gt; 0
ORDER BY forwarded_record_count desc
&lt;/pre&gt;
See also : &lt;a href=&quot;http://sqlsolace.blogspot.com/2018/06/this-script-reports-usage-of-heap.html&quot;&gt;HEAP table usage script
&lt;/a&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4-u-Fqu_MdsHgMoHmuKF5L1Fmp63AkHR5u1FRg3la1MAVg1J-QL93slrNiufdxrm5XFTB5yedxks-ncke8kNJ-IGvalTXSlAPttVx0nyvKO2f_34QXIzWPRa9pFsc2JB8mlALseIYFW0/s1600/heaps.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;541&quot; data-original-width=&quot;787&quot; height=&quot;275&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4-u-Fqu_MdsHgMoHmuKF5L1Fmp63AkHR5u1FRg3la1MAVg1J-QL93slrNiufdxrm5XFTB5yedxks-ncke8kNJ-IGvalTXSlAPttVx0nyvKO2f_34QXIzWPRa9pFsc2JB8mlALseIYFW0/s400/heaps.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/7644392875232325293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/7644392875232325293?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/7644392875232325293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/7644392875232325293'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/06/tsql-heaps-and-forwarded-records.html' title='TSQL : HEAPS and Forwarded Records'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4-u-Fqu_MdsHgMoHmuKF5L1Fmp63AkHR5u1FRg3la1MAVg1J-QL93slrNiufdxrm5XFTB5yedxks-ncke8kNJ-IGvalTXSlAPttVx0nyvKO2f_34QXIzWPRa9pFsc2JB8mlALseIYFW0/s72-c/heaps.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-8158975315536567151</id><published>2018-06-01T19:46:00.000+01:00</published><updated>2018-06-04T08:13:32.824+01:00</updated><title type='text'>TSQL : Clustered Indexes, Identities &amp; Primary Keys</title><content type='html'>I&#39;m Currently looking at a large database where there are
&lt;ul&gt;
&lt;li&gt;HEAPS (tables without a clustered index)&lt;/li&gt;
&lt;li&gt;IDENTITY columns that could serve as Primary Keys (but aren&#39;t)&lt;/li&gt;
&lt;li&gt;PRIMARY KEYS that have been defined as non-clustered (someone has scripted them out and ignored the default clustered status of a PK).&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Anyway, this is coming in useful ...&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;SELECT   SCHEMA_NAME(schema_id) AS SchemaName
  ,name AS TableName
  ,OBJECTPROPERTY(object_id,&#39;TableHasClustIndex&#39;) HasClusteredIndex
  ,OBJECTPROPERTY(object_id,&#39;TableHasIdentity&#39;) HasIdentity
  ,OBJECTPROPERTY(object_id,&#39;TableHasprimarykey&#39;) HasPrimaryKey
FROM sys.tables
WHERE OBJECTPROPERTY(object_id,&#39;TableHasClustIndex&#39;) = 0
ORDER BY 1, 2
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/8158975315536567151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/8158975315536567151?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8158975315536567151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8158975315536567151'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/06/clustered-indexes-identities-primary.html' title='TSQL : Clustered Indexes, Identities &amp; Primary Keys'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-7384530580636322292</id><published>2018-05-18T19:13:00.000+01:00</published><updated>2018-06-03T16:14:08.045+01:00</updated><title type='text'>SQLTips : CONCAT</title><content type='html'>The CONCAT function is available from SQL 2016+.

It can save you a lot of messing around with adding strings together and coping with NULLS and empty strings.


&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;
SELECT CONCAT(&#39;The cat sat&#39;,&#39; &#39;, &#39;on&#39;, &#39; &#39;, &#39;the mat&#39;)
GO
 

SELECT CONCAT(NULL, &#39; and void&#39;)
GO

 
DECLARE @int int = 99
DECLARE @varchar varchar(13) = &#39; red balloons&#39;
SELECT CONCAT(@int,@varchar)
GO

 
DECLARE @varchar varchar(20) = &#39;The date today is &#39;
DECLARE @dt datetime = GETDATE()
SELECT CONCAT(@varchar,@dt)
GO
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/7384530580636322292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/7384530580636322292?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/7384530580636322292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/7384530580636322292'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/05/sqltips-concat.html' title='SQLTips : CONCAT'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-2164057323668051152</id><published>2018-05-15T00:43:00.000+01:00</published><updated>2018-08-02T00:43:35.526+01:00</updated><title type='text'>sp_ms_marksystemobject </title><content type='html'>On searching for a table I found it to be hidden. Turns out it was marked as &#39;ms shipped&#39; i.e was a system object.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSZGN5JjLjlyBFyTfItn6RsE567QzTd7baWRlXw9j4wtQ4Pn6LTgjqlhv1pMIaDf-3lbAuUGlHbcZtKtFdbaV-uMlrCGOzbpDQm1lqhXcjKjgeIaWyZtkoOxnjQ0kLtVwdydvZBRKg1mQ/s1600/ssms.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;134&quot; data-original-width=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSZGN5JjLjlyBFyTfItn6RsE567QzTd7baWRlXw9j4wtQ4Pn6LTgjqlhv1pMIaDf-3lbAuUGlHbcZtKtFdbaV-uMlrCGOzbpDQm1lqhXcjKjgeIaWyZtkoOxnjQ0kLtVwdydvZBRKg1mQ/s1600/ssms.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;select * from sys.tables WHERE name = &#39;sysssislog&#39;
&lt;/pre&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm7j61bRhTSLZ5JJBpX3pL4a0EIud22D0YrP45bArlXoo8mOTL0eVmhU-SzjFc_rStgodzBGv9TfhqAGmvN9Ef4s5e9cuID6EQgVMk-rSRx4vnV8PfjhafjIFabDrr81Ab9IP297K6C7I/s1600/ssislog.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;151&quot; data-original-width=&quot;966&quot; height=&quot;50&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm7j61bRhTSLZ5JJBpX3pL4a0EIud22D0YrP45bArlXoo8mOTL0eVmhU-SzjFc_rStgodzBGv9TfhqAGmvN9Ef4s5e9cuID6EQgVMk-rSRx4vnV8PfjhafjIFabDrr81Ab9IP297K6C7I/s320/ssislog.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
To achieve this yourself you can use sp_ms_marksystemobject &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;EXEC sp_ms_marksystemobject &#39;dbo.sysssislog&#39;
&lt;/pre&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/2164057323668051152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/2164057323668051152?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/2164057323668051152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/2164057323668051152'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/05/spmsmarksystemobject.html' title='sp_ms_marksystemobject '/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSZGN5JjLjlyBFyTfItn6RsE567QzTd7baWRlXw9j4wtQ4Pn6LTgjqlhv1pMIaDf-3lbAuUGlHbcZtKtFdbaV-uMlrCGOzbpDQm1lqhXcjKjgeIaWyZtkoOxnjQ0kLtVwdydvZBRKg1mQ/s72-c/ssms.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-2706573371121939503</id><published>2018-04-09T22:57:00.001+01:00</published><updated>2018-06-03T14:19:09.229+01:00</updated><title type='text'>Tables with Computed Columns</title><content type='html'>Tables with Computed Columns

&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;SELECT
  SCHEMA_NAME(schema_id) AS schemaname
, t.name as tablename
, cc.name
, cc.definition
FROM sys.tables t
INNER JOIN sys.Computed_columns cc
ON t.object_id = cc.object_id
&lt;/pre&gt;
&lt;br /&gt;
and without
&lt;br /&gt;

&lt;pre class=&quot;brush: sql&quot;&gt;
select
  SCHEMA_NAME(schema_id) AS schemaname
, t.name as tablename
from  sys.tables t
WHERE object_id not in (SELECT object_id FROM sys.Computed_columns)
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/2706573371121939503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/2706573371121939503?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/2706573371121939503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/2706573371121939503'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/04/tables-with-computed-columns.html' title='Tables with Computed Columns'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-5491971159258253228</id><published>2018-03-20T02:16:00.000+00:00</published><updated>2018-07-22T02:16:16.708+01:00</updated><title type='text'>Suspect Database - Steps to Recovery</title><content type='html'>For reference, the steps I took to (successfully) recover a 2008 database that was marked as Suspect in Management Studio.&lt;br /&gt;
&lt;br /&gt;
Run each separately, and review the results...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXEC sp_resetstatus &#39;mySuspectDB&#39;&lt;br /&gt;
&lt;br /&gt;
ALTER DATABASE mySuspectDB SET EMERGENCY&lt;br /&gt;
&lt;br /&gt;
DBCC CHECKDB(&#39;mySuspectDB&#39;)&lt;br /&gt;
&lt;br /&gt;
ALTER DATABASE mySuspectDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE&lt;br /&gt;
&lt;br /&gt;
DBCC CHECKDB (&#39;mySuspectDB&#39;, REPAIR_ALLOW_DATA_LOSS)&lt;br /&gt;
&lt;br /&gt;
ALTER DATABASE mySuspectDB SET MULTI_USER&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/5491971159258253228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/5491971159258253228?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/5491971159258253228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/5491971159258253228'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/03/suspect-database-steps-to-recovery.html' title='Suspect Database - Steps to Recovery'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-8582058367684546507</id><published>2018-02-16T20:37:00.000+00:00</published><updated>2018-06-03T16:38:02.219+01:00</updated><title type='text'>HASHBYTES and FOR XML to create a binary checksum</title><content type='html'>&lt;pre class=&quot;brush: sql&quot;&gt;
SELECT TOP (1000) [Id]
      ,[AboutMe]
      ,[Age]
      ,[CreationDate]
      ,[DisplayName]
      ,[DownVotes]
      ,[EmailHash]
      ,[LastAccessDate]
      ,CHKSUM = CONVERT(VARBINARY(20),HASHBYTES(&#39;MD5&#39;, (SELECT s.* FROM (VALUES(NULL))Foo(Bar) FOR XML AUTO, BINARY BASE64)))
  FROM [StackOverFlow2010].[dbo].[Users] s
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/8582058367684546507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/8582058367684546507?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8582058367684546507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8582058367684546507'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/02/hashbytes-and-for-xml-to-create-binary.html' title='HASHBYTES and FOR XML to create a binary checksum'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-8909214935321608223</id><published>2018-01-04T21:10:00.002+00:00</published><updated>2018-01-04T23:01:51.716+00:00</updated><title type='text'>Mail process taking forever Suspended Process - msdb.dbo.sp_readrequest;1</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNH9adCGcWXOFg-ykTU5JvzhDdQrlZzE00iyu5GwFbIrWXguKHR58eEhSqYXvNlDHJKAXpegdpOe-Mp35h3ew5Bmsyx4rAVJtlXfuEGfxNdNvHQ_72OrRk9Bl5TiyBpXDrplUXGR72UkA/s1600/mail_screenshot.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;363&quot; data-original-width=&quot;789&quot; height=&quot;183&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNH9adCGcWXOFg-ykTU5JvzhDdQrlZzE00iyu5GwFbIrWXguKHR58eEhSqYXvNlDHJKAXpegdpOe-Mp35h3ew5Bmsyx4rAVJtlXfuEGfxNdNvHQ_72OrRk9Bl5TiyBpXDrplUXGR72UkA/s400/mail_screenshot.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Finding a process taking forever&amp;nbsp; in the suspended state, I wondered what it could be.&lt;br /&gt;
Fortunately Irina Tudose had already &lt;a href=&quot;http://yrushka.com/index.php/sql-server/performance-tunning/msdb-dbo-sp_readrequest1-long-running-process/&quot;&gt;done the hard work for me.&lt;/a&gt;&amp;nbsp; It is a process used by the mail procedures in msdb. She recommends changing the default value for&amp;nbsp;DatabaseMailExeMinimumLifeTime to resolve this.&lt;br /&gt;
&lt;br /&gt;
See also&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;verdana&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 16.25px;&quot;&gt;&lt;a href=&quot;http://www.connectsql.com/2012/09/sql-server-why-session-with.html&quot;&gt;SQL Server: Why a Session With sp_readrequest Takes so Long to Execute&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px; line-height: 15.6pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&amp;nbsp;msdb.dbo.sysmail_&lt;wbr&gt;&lt;/wbr&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px; line-height: 15.6pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&amp;nbsp;paramvalue&amp;nbsp;=&amp;nbsp;60&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: green; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;--60 Seconds&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px; line-height: 15.6pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&amp;nbsp;paramname&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&#39;&lt;wbr&gt;&lt;/wbr&gt;DatabaseMailExeMinimumLifeTime&lt;wbr&gt;&lt;/wbr&gt;&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px; line-height: 15.6pt;&quot;&gt;
&lt;span style=&quot;color: red; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/8909214935321608223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/8909214935321608223?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8909214935321608223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/8909214935321608223'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2018/01/mail-process-taking-forever-suspended.html' title='Mail process taking forever Suspended Process - msdb.dbo.sp_readrequest;1'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNH9adCGcWXOFg-ykTU5JvzhDdQrlZzE00iyu5GwFbIrWXguKHR58eEhSqYXvNlDHJKAXpegdpOe-Mp35h3ew5Bmsyx4rAVJtlXfuEGfxNdNvHQ_72OrRk9Bl5TiyBpXDrplUXGR72UkA/s72-c/mail_screenshot.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-4642978732342407572</id><published>2017-12-17T22:22:00.001+00:00</published><updated>2017-12-17T22:22:19.945+00:00</updated><title type='text'>Notepad : Commonly used commands</title><content type='html'>Force Windows Update
wuauclt.exe /updatenow
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/4642978732342407572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/4642978732342407572?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/4642978732342407572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/4642978732342407572'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2017/12/notepad-commonly-used-commands.html' title='Notepad : Commonly used commands'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-2028809858936209710</id><published>2017-12-08T22:05:00.000+00:00</published><updated>2017-12-10T22:09:33.660+00:00</updated><title type='text'>Error: 8623, Severity: 16, State: 1. The query processor ran out of internal resources </title><content type='html'>Caught out when generating some dynamic sql today.

The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.

Dynamically generating a the IN clause and I accidentally passed a list of over 22,000 values.

It turns out IN can&#39;t take more than 10,000 values.

&lt;a href=&quot;https://blogs.technet.microsoft.com/mdegre/2012/03/13/8623-the-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan/&quot;&gt;8623 The query processor ran out of internal resources and could not produce a query plan.
&lt;/a&gt;

I&#39;ve obviously rewritten it, but thought the error message interesting.</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/2028809858936209710/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/2028809858936209710?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/2028809858936209710'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/2028809858936209710'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2017/12/error-8623-severity-16-state-1-query.html' title='Error: 8623, Severity: 16, State: 1. The query processor ran out of internal resources '/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2453693540149032389.post-1881493682914523288</id><published>2017-11-28T14:47:00.002+00:00</published><updated>2018-06-03T14:19:10.577+01:00</updated><title type='text'>Database growth from available backup history</title><content type='html'>&lt;pre class=&quot;brush: sql&quot;&gt;SELECT  
 BackupRange.Database_name 
 ,First_Backup 
 ,Last_Backup 
 ,DATEDIFF(dd,First_Backup,Last_Backup) AS days_history 
 ,firstbackup.backup_size/1024/1024 AS FirstBackupSizeMB 
 ,lastbackup.backup_size/1024/1024 AS LastBackupSizeMB 
 ,(lastbackup.backup_size/1024/1024) - (firstbackup.backup_size/1024/1024) as GrowthMB 
 ,CASE WHEN DATEDIFF(dd,First_Backup,Last_Backup) &amp;gt; 0
  THEN ((lastbackup.backup_size/1024/1024) - (firstbackup.backup_size/1024/1024)) / DATEDIFF(dd,First_Backup,Last_Backup)
  ELSE 0
  END AS GrowthRate_MBday 
FROM  
(SELECT  
 [database_name] 
 ,MIN(backup_start_date) AS &#39;First_Backup&#39; 
 ,MAX(backup_start_date) AS &#39;Last_Backup&#39; 
FROM msdb.dbo.backupset  
WHERE [type] = &#39;D&#39;
--AND [database_name] = N&#39;mydatabase&#39;  
GROUP BY [database_name]) BackupRange  
LEFT JOIN msdb.dbo.backupset firstbackup  
  ON  firstbackup.database_name = BackupRange.database_name
  AND firstbackup.backup_start_date = BackupRange.First_Backup
LEFT JOIN msdb.dbo.backupset lastbackup  
  ON  lastbackup.database_name = BackupRange.database_name
  AND lastbackup.backup_start_date = BackupRange.last_Backup
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlsolace.blogspot.com/feeds/1881493682914523288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2453693540149032389/1881493682914523288?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/1881493682914523288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2453693540149032389/posts/default/1881493682914523288'/><link rel='alternate' type='text/html' href='http://sqlsolace.blogspot.com/2017/11/database-growth-from-available-backup.html' title='Database growth from available backup history'/><author><name>r5d4</name><uri>http://www.blogger.com/profile/03732814547965848157</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>