<?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-2672880126319793008</id><updated>2025-03-08T03:38:15.203-08:00</updated><category term="Administration"/><category term="Development"/><category term="Internals"/><category term="Indexes"/><category term="Denali"/><category term="Performance"/><category term="Misconceptions"/><category term="SQL Server 2016"/><category term="SSIS"/><category term="automation"/><category term="Optimizer"/><category term="XML"/><category term="Concurrency"/><category term="IO"/><category term="Powershell"/><category term="Transaction Log"/><category term="Transactions"/><category term="Books"/><category term="Disaster Recovery"/><category term="SQLOS"/><category term="Security"/><category term="Statistics"/><category term="Azure"/><category term="CLR"/><category term="Central Management Servers"/><category term="Data Quality"/><category term="Policy Based Management"/><category term="Server Agent"/><category term="Setup"/><category term="Sparse Columns"/><category term="Troubleshooting"/><category term="sqlsoton"/><title type='text'>SQL Server - Down &amp;amp; Dirty</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>64</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-7975621504504658571</id><published>2016-08-12T09:15:00.001-07:00</published><updated>2016-08-12T09:15:26.685-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="automation"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><title type='text'>My new book hit No 1 hot new release</title><content type='html'>I am very excited that my new book, Expert Scripting and Automation has hit No 1 hot new release on Amazon.com.&lt;br /&gt;
&lt;br /&gt;
Even more pleasing is that today I have seen the print copy for the first time!&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/AVvXsEhJsFP2b61scINsHsN5rGpV-Ck6PbJz5tnTTGfHwiJbILwLEzE09nQTPa4swU42nUbdNBB0daaZ5toI40IrNy5BFs3dbayXd8_XIApnZeSD8SUDRkML0RyWXNt5XaY24RdbvNql-9Pegwg/s1600/No1+HNR.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJsFP2b61scINsHsN5rGpV-Ck6PbJz5tnTTGfHwiJbILwLEzE09nQTPa4swU42nUbdNBB0daaZ5toI40IrNy5BFs3dbayXd8_XIApnZeSD8SUDRkML0RyWXNt5XaY24RdbvNql-9Pegwg/s640/No1+HNR.jpg&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://sqlserverdownanddirty.blogspot.com/feeds/7975621504504658571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/08/my-new-book-hit-no-1-hot-new-release.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7975621504504658571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7975621504504658571'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/08/my-new-book-hit-no-1-hot-new-release.html' title='My new book hit No 1 hot new release'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJsFP2b61scINsHsN5rGpV-Ck6PbJz5tnTTGfHwiJbILwLEzE09nQTPa4swU42nUbdNBB0daaZ5toI40IrNy5BFs3dbayXd8_XIApnZeSD8SUDRkML0RyWXNt5XaY24RdbvNql-9Pegwg/s72-c/No1+HNR.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-2223568648103660301</id><published>2016-08-06T07:44:00.001-07:00</published><updated>2016-08-06T07:44:34.207-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="automation"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><title type='text'>Expert Scripting &amp; Automation</title><content type='html'>I&#39;m very please to announce that my new book, Expert Scripting and Automation for SQL Server DBAs has now been published.&lt;br /&gt;
&lt;br /&gt;
It is already available on Amazon.com as both an e-book and a print book, and will hit the UK shelves in the coming week.&lt;br /&gt;
&lt;br /&gt;
I don&#39;t believe that there is any other book quite like this one on the market, so I really hope you all enjoy the read!&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/AVvXsEgC2I07OMqYzXowXaTryNv6nJ8jOi6gUK7EL_X94dUTdE8s-NgrDflE91lSHK9PQV7W8JDd7kc8gFAYGIyumpgVH7p799zTRfsPgq4a7_5OZxkXP6wg0TNtGHRA2MpIBVzI3HdnIqXgem0/s1600/2016-08-06_15-37-14.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC2I07OMqYzXowXaTryNv6nJ8jOi6gUK7EL_X94dUTdE8s-NgrDflE91lSHK9PQV7W8JDd7kc8gFAYGIyumpgVH7p799zTRfsPgq4a7_5OZxkXP6wg0TNtGHRA2MpIBVzI3HdnIqXgem0/s320/2016-08-06_15-37-14.jpg&quot; width=&quot;223&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/2223568648103660301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/08/expert-scripting-automation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/2223568648103660301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/2223568648103660301'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/08/expert-scripting-automation.html' title='Expert Scripting &amp; Automation'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC2I07OMqYzXowXaTryNv6nJ8jOi6gUK7EL_X94dUTdE8s-NgrDflE91lSHK9PQV7W8JDd7kc8gFAYGIyumpgVH7p799zTRfsPgq4a7_5OZxkXP6wg0TNtGHRA2MpIBVzI3HdnIqXgem0/s72-c/2016-08-06_15-37-14.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-3167337897903867166</id><published>2016-07-12T09:01:00.000-07:00</published><updated>2016-07-12T09:05:45.399-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Security"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><title type='text'>Using Row-Level Security with HierarchyID</title><content type='html'>When I first heard about Row-Level Security (RSL), one of the first use cases I though of, was to satisfy queries against a hierarchical table. For example, imagine that you had a table of employees details; you could use RSL to limit the rows that each employee could view, to include only those employees who report to them.&lt;br /&gt;
&lt;br /&gt;
So lets have a look at how you could achieve this, by using the HumanResources.Employee table in the AdventureWorks2016CTP3 database.&lt;br /&gt;
&lt;br /&gt;
In order to implement RSL, we will need two objects. The first is a Security Predicate. This consists of an inline table-valued function, which determines if a row should be accessible. The second, is a Security Policy. The Security Policy is a new artifact type in SQL Server 2016, and binds the Security Predicate to a table.&lt;br /&gt;
&lt;br /&gt;
The script below creates the Security Predicate in a schema named Security.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
CREATEFUNCTION
Security.fn_securitypredicate(@OrganizationNode HIERARCHYID)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RETURNS
TABLE&lt;br /&gt;
WITH SCHEMABINDING&lt;br /&gt;
AS&lt;br /&gt;
RETURN SELECT 1 AS fn_securitypredicate_result&lt;br /&gt;
FROM HumanResources.Employee e1&lt;br /&gt;
WHERE
@OrganizationNode.IsDescendantOf(OrganizationNode) = 1&lt;br /&gt;
AND LoginID = &#39;adventure-works\&#39; + SUSER_SNAME() ;&lt;br /&gt;
GO&lt;/blockquote&gt;
&lt;div class=&quot;CodeCxSpFirst&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
The function accepts a single parameter, of the type HIERARCHYID. This is a complex data type, implemented through SQLCLR, which provides a number of methods, which can be used to determine position within a hierarchy, as well as hierarchy ancestry. A full method reference for the data type can be found at&amp;nbsp;&lt;span style=&quot;font-family: &amp;quot;calibri&amp;quot; , sans-serif; font-size: 11pt; line-height: 115%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/bb677193.aspx&quot; style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;&quot;&gt;https://msdn.microsoft.com/en-us/library/bb677193.aspx&lt;/a&gt;.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
Using SCHEMABINDING on the function means that columns refferenced by the Security Predicate cannot be altered, but simplifies security administration, as the user who implicitly calls the function, will not need permissions to any tables or functions that are referenced by the Security Predicate.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
The query uses the IsDecendantOf method, against the @OrganizationNode parameter (which will represent the OrganizationNode column of each row within the Employees table, to find all descendants of the row, where the LoginID column corresponds with the User ID of the user that has run the query. The concatenation of &#39;adventure-works\&#39; is used to make the value returned by the SUSER_SNAME() function match the values stored in the table, where the domain of the user is also recorded. 1 is returned, for each row that matches the criteria, which tells the Security Policy that the row can be accessed.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
The script below creates the Security Policy.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
CREATE SECURITY POLICY Security.EmployeeSecurityPolicy&lt;br /&gt;
ADD FILTER PREDICATE
Security.fn_securitypredicate(OrganizationNode) ON HumanResources.Employee&lt;br /&gt;
WITH (STATE=ON, SCHEMABINDING=ON) ;&lt;/blockquote&gt;
&lt;div class=&quot;CodeCxSpFirst&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
The Security Policy is also created in the Security schema. Creating RSL objects in a separate schema is a best practice, as it simplifies security administration. The ADD FILTER PREDICATE syntax performs several functions. &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
Firstly, it specifies that the predicate should be used to silently filter rows, as opposed to a BLOCK predicate, which will stop DML statements beling issued against rows, and return an error message.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
Secondly, it binds the Security Predicate to the HumanResources.Employee table.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
Thirdly, it passes the OrganizationNode column, from the HumanResources.Employee table, to the Security Predicate function.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
The WITH statement specifies that both STATE and SCHEMABINDING are ON. STATE will determine if the Policy is enabled on creation. SCHEMABINDING will determine if a Security Predicate MUST use SCHEMABINDING, or if it is optional.&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
I talk more about RSL, in my upcoming book, Securing SQL Server, which will be published by Apress, in early 2017.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/3167337897903867166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/07/when-i-first-heard-about-row-level.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3167337897903867166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3167337897903867166'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/07/when-i-first-heard-about-row-level.html' title='Using Row-Level Security with HierarchyID'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-7475553104146997101</id><published>2016-07-07T10:05:00.000-07:00</published><updated>2016-07-07T10:05:24.501-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="automation"/><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><title type='text'>Regular Expressions in SQL Server</title><content type='html'>In my last post&amp;nbsp;&lt;a href=&quot;http://sqlserverdownanddirty.blogspot.co.uk/2016/07/ddl-triggers-as-work-around-for-policy.html&quot;&gt;ddl triggers as work-around for policy limitations&lt;/a&gt;, I discussed how triggers can be used to enforce database settings are not changed. This cannot be achieved through Policy Based Management, because the Database facet does not support On Change: Log or On Change: Prevent modes.&lt;br /&gt;
&lt;br /&gt;
I also noted that I was not happy with the pattern matching that I originally used within the trigger, to resolve the issue. Therefore, in this post, I will talk about how we can use CLR to gain the benefits of regular expressions in SQL Server.&lt;br /&gt;
&lt;br /&gt;
So, the challenge is....We want a trigger that will ensure that no statement can turn off the AUTO CREATE STATISTICS, AUTO UPDATE STATISTICS or AUTO UPDATE STATISTICS ASYNC &amp;nbsp;settings of any database within the instance. The pattern matching offered by the LIKE predicate in T-SQL works well for changes made through the GUI, but if a change is scripted, then a developer may have used an extra space, a tab, or a line break, etc.&lt;br /&gt;
&lt;br /&gt;
The first thing that we need to do to work around this, is create a CLR function, that will accept the SQL Statement from the EVENTDATA() function as a parameter and check the patter against the regex libraries. Below is the c# method to achieve this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;
System;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;
System.Data;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;
System.Data.SqlClient;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;
System.Data.SqlTypes;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;
Microsoft.SqlServer.Server;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; System.Text.RegularExpressions;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;partial&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;UserDefinedFunctions&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
[Microsoft.SqlServer.Server.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SqlFunction&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;
CheckMatch(&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SqlString&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; statement)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Regex&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; rgxUpdate = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Regex&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&quot;AUTO_UPDATE_STATISTICS[_ASYNC]{0,}[\r\n\t{0,}[
\n\t\t]{0,}OFF&quot;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;RegexOptions&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;.IgnoreCase
| &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;RegexOptions&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;.Singleline);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Int16&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; retcounter = 0;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; stringstatement = &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Convert&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;.ToString(statement);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Match&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; matchUpdate = rgxUpdate.Match(stringstatement);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; (matchUpdate.Success)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
retcounter++;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Regex&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; rgxCreate = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Regex&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&quot;AUTO_CREATE_STATS[\r\n\t{0,}[
\n\t\t]{0,}OFF&quot;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;RegexOptions&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;.IgnoreCase
| &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;RegexOptions&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;.Singleline);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Match&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; matchCreate = rgxCreate.Match(stringstatement);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; (matchCreate.Success)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
retcounter++;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; (retcounter &amp;gt; 0)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; 1; }&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; 0; }&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 12.6667px;&quot;&gt;There are a few things to pay particular attention to in this code. Firstly, notice that we are importing the following .NET base libraries:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 12.6667px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;System.Data.SqlTypes&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Microsoft.SqlServer.Server&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;System.Text.RegularExpressions&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;The first of these libraries, is used because we are working with the sqlstring data type, The second library is required because we are creating a function that will be used by SQL Server and the third library is required to use the regex classes.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;The next thing to note in this code is the regex options. We are using regex options to treat the SQL Statement as a single line and to make the pattern match case insensitive.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Once we have built the project, we will need to create an assembly within SQL Server. This can be created using the CREATE ASSEMBLY DDL statement, as demonstrated below.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;overflow: auto; padding: 5px; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: Consolas, Courier, monospace;&quot;&gt;&lt;span style=&quot;line-height: 17.55px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE ASSEMBLY&lt;/span&gt; CheckStats   
&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;c:\sql_assemblies\checkstats.dll&#39;&lt;/span&gt;  
&lt;span style=&quot;color: blue;&quot;&gt;WITH PERMISSION_SET&lt;/span&gt; = &lt;span style=&quot;color: blue;&quot;&gt;SAFE&lt;/span&gt;; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;The script assumes that we have built the project as CheckStats.dll to the c:\sqlassemblies folder.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Now that the assembly has been built, we can create the CLR function, which will call the c# method within the assembly. The script below demonstrates how to create the function.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE FUNCTION&lt;/span&gt; dbo.CheckMatch&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Statement &lt;span style=&quot;color: blue;&quot;&gt;NVARCHAR&lt;/span&gt;(&lt;span style=&quot;color: magenta;&quot;&gt;MAX&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;RETURNS INT&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&lt;span style=&quot;background: white; font-size: 12.6667px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;AS EXTERNAL&lt;/span&gt; NAME CheckStats.UserDefinedFunction.CheckMatch;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;Notice that we reference the method, using the 3-part name Assembly.Class.Method&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;Finally, we can create the server scoped DDL trigger that will respond to ALTER DATABASE statements and call the CLR function. This is demonstrated below.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE TRIGGER&lt;/span&gt; StatisticsManagement&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;ON&lt;/span&gt; &lt;span style=&quot;color: #999999;&quot;&gt;ALL&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;SERVER&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;AFTER&lt;/span&gt; ALTER_DATABASE&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;IF&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; dbo.CheckMatch(&lt;span style=&quot;color: magenta;&quot;&gt;UPPER&lt;/span&gt;(&lt;span style=&quot;color: magenta;&quot;&gt;EVENTDATA&lt;/span&gt;().value(&lt;span style=&quot;color: red;&quot;&gt;&#39;(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]&#39;,&#39;nvarchar(max)&#39;&lt;/span&gt;)))) = 1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;PRINT&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Auto Stats Settings MUST Be Configured As ON&#39;&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;ROLLBACK&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 12.6667px;&quot;&gt;END&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;You can read more about DDL Triggers in my book Pro SQL Server Administration, available from &lt;a href=&quot;http://apress.com/&quot;&gt;apress.com&lt;/a&gt;, Amazon and most book shops.&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;overflow: auto; padding: 5px; word-wrap: normal;&quot;&gt;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/7475553104146997101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/07/regular-expressions-in-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7475553104146997101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7475553104146997101'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/07/regular-expressions-in-sql-server.html' title='Regular Expressions in SQL Server'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-751010343258451351</id><published>2016-07-05T22:09:00.000-07:00</published><updated>2016-07-07T10:05:55.133-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="automation"/><category scheme="http://www.blogger.com/atom/ns#" term="Policy Based Management"/><title type='text'>DDL Triggers as a Work Around for Policy Based Management Limitations</title><content type='html'>A college recently asked for my help in solving a problem with SQL Server Policy Based Management. He had a requirement to enforce a policy that prevent the auto update and auto create statistics settings being changed on production databases during code deployments. The problem is, that these settings are in the Database facet and this facet does not support On Chage:Prevent or On Change Log.&lt;br /&gt;
&lt;br /&gt;
You can determine which actions are supported by which facets, by using the below query:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SELECT&lt;br /&gt;&amp;nbsp; &amp;nbsp; name ,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &#39;Yes&#39; AS on_demand,&lt;br /&gt;&amp;nbsp; &amp;nbsp; CASE&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHEN (CONVERT(BIT, execution_mode &amp;amp; 4)) = 1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; THEN &#39;Yes&#39;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ELSE &#39;No&#39;&lt;br /&gt;&amp;nbsp; &amp;nbsp; END AS on_schedule,&lt;br /&gt;&amp;nbsp; &amp;nbsp; CASE&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHEN (CONVERT(BIT, execution_mode &amp;amp; 2)) = 1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; THEN &#39;Yes&#39;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ELSE &#39;No&#39;&lt;br /&gt;&amp;nbsp; &amp;nbsp; END AS on_change_log,&lt;br /&gt;&amp;nbsp; &amp;nbsp; CASE&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHEN (CONVERT(BIT, execution_mode &amp;amp; 1)) = 1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; THEN &#39;Yes&#39;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ELSE &#39;No&#39;&lt;br /&gt;&amp;nbsp; &amp;nbsp; END AS on_change_prevent&lt;br /&gt;FROM msdb.dbo.syspolicy_management_facets ;&lt;/span&gt;&lt;/blockquote&gt;
Instead, I suggested that he use a DDL trigger to ensure that these settings are not changed, and helped him write the below trigger definition.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;background-color: white;&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;CREATE TRIGGER DBA_StatisticsManagement&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;ON ALL SERVER&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;AFTER ALTER_DATABASE&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;AS&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;BEGIN&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (SELECT UPPER(EVENTDATA().value(&#39;(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]&#39;,&#39;nvarchar(max)&#39;))) &amp;nbsp;LIKE &#39;%AUTO_UPDATE_STATISTICS_ASYNC OFF%&#39;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT &#39;Auto Update Stats Async MUST be configured as ON&#39;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ROLLBACK ;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;END&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (SELECT UPPER(EVENTDATA().value(&#39;(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]&#39;,&#39;nvarchar(max)&#39;))) &amp;nbsp;LIKE &#39;%AUTO_CREATE_STATISTICS OFF%&#39;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT &#39;Auto Create Stats MUST be configured as ON&#39;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ROLLBACK ;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;END&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (SELECT UPPER(EVENTDATA().value(&#39;(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]&#39;,&#39;nvarchar(max)&#39;))) &amp;nbsp;LIKE &#39;%AUTO_UPDATE_STATISTICS OFF%&#39;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT &#39;Auto Update Stats MUST be configured as ON&#39;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ROLLBACK ;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;END&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;END&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;/blockquote&gt;
This trigger has been created on the instance, which means that it will reside in the Master database and is configured to fire when an ALTER DATABASE statement is executed. There is no need for it to fire when a CREATE DATABASE statement is executed, because even when using the GUI to create a database, the auto update and auto create statistics settings are configured with ALTER DATABASE statements, after the initial database creation.&lt;br /&gt;
&lt;br /&gt;
The trigger pulls the statement executed from the EVENTDATA() function and then uses the LIKE predicate to pattern match the strings that would turn off the auto update and auto create statistics options. The event data is returned as an XML document and the schema can be found at&amp;nbsp;&lt;a href=&quot;http://schemas.microsoft.com/sqlserver/2006/11/eventdata/events.xsd&quot;&gt;http://schemas.microsoft.com/sqlserver/2006/11/eventdata/events.xsd&lt;/a&gt;. Therefore, we need to use the value() Xquery method, to extract the data.&lt;br /&gt;
&lt;br /&gt;
After writting this trigger, it played on my mind. Whilst this trigger will always work for changes made through the GUI, there is a chance that it will not work, if the change is made through a script. This is because of the way the LIKE predicate pattern matches the statement. For example, what is a script included an additional space before OFF?&lt;br /&gt;
&lt;br /&gt;
In my next post, I will talk about how I resolved the this, by using a CLR function.&lt;br /&gt;
&lt;br /&gt;
I talk more about DDL triggers and Policy Based Management, in my book, Pro SQL Server Administration, available from &lt;a href=&quot;http://apress.com/&quot;&gt;apress.com&lt;/a&gt;, Amazon and most book shops.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/751010343258451351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/07/ddl-triggers-as-work-around-for-policy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/751010343258451351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/751010343258451351'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/07/ddl-triggers-as-work-around-for-policy.html' title='DDL Triggers as a Work Around for Policy Based Management Limitations'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-7295896664668926470</id><published>2016-06-07T22:18:00.000-07:00</published><updated>2016-06-07T22:18:24.775-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Internals"/><title type='text'>How to Calculate Binary Bit Masks</title><content type='html'>&lt;br /&gt;
Ok, so I know this post is a bit geeky, but there is nothing wrong with a little geeky fun from time to time.&lt;br /&gt;
&lt;br /&gt;
SQL Server uses bit maps for various thinks, such as CPU affinity and Server Agent Operator&#39;s pager availability, but how do you work with bit maps? Well, it is a case of calculating the integer expresentation of the bit map value. This is made more complex because the INT data type is a 32-bit signed integer, meaning that some of the representations will be negative numbers.&lt;br /&gt;
&lt;br /&gt;
Using CPU affinity as an example, the table below shows the processor number, bit mask and signed integer representation for processors 0 - 31.&lt;br /&gt;
&lt;br /&gt;
Processor Number Bit Mask &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Signed Integer Representation&lt;br /&gt;
0 &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; 0000 0000 0000 0000 0000 0000 0000 0001 &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;br /&gt;
1 &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; 0000 0000 0000 0000 0000 0000 0000 0010 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;br /&gt;
2 &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; 0000 0000 0000 0000 0000 0000 0000 0100 &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;br /&gt;
3 &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; 0000 0000 0000 0000 0000 0000 0000 1000 &amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;br /&gt;
4 &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; 0000 0000 0000 0000 0000 0000 0001 0000 &amp;nbsp; &amp;nbsp; 16&lt;br /&gt;
5 &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; 0000 0000 0000 0000 0000 0000 0010 0000 &amp;nbsp; &amp;nbsp; 32&lt;br /&gt;
6 &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; 0000 0000 0000 0000 0000 0000 0100 0000 &amp;nbsp; &amp;nbsp; 64&lt;br /&gt;
7 &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; 0000 0000 0000 0000 0000 0000 1000 0000 &amp;nbsp; &amp;nbsp; 128&lt;br /&gt;
8 &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; 0000 0000 0000 0000 0000 0001 0000 0000 &amp;nbsp; &amp;nbsp; 256&lt;br /&gt;
9 &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; 0000 0000 0000 0000 0000 0010 0000 0000 &amp;nbsp; &amp;nbsp; 512&lt;br /&gt;
10 &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; 0000 0000 0000 0000 0000 0100 0000 0000 &amp;nbsp; &amp;nbsp; 1024&lt;br /&gt;
11 &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; 0000 0000 0000 0000 0000 1000 0000 0000 &amp;nbsp; &amp;nbsp; 2028&lt;br /&gt;
12 &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; 0000 0000 0000 0000 0001 0000 0000 0000 &amp;nbsp; &amp;nbsp; 4096&lt;br /&gt;
13 &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; 0000 0000 0000 0000 0010 0000 0000 0000 &amp;nbsp; &amp;nbsp; 8192&lt;br /&gt;
14 &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; 0000 0000 0000 0000 0100 0000 0000 0000 &amp;nbsp; &amp;nbsp; 16384&lt;br /&gt;
15 &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; 0000 0000 0000 0000 1000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 32768&lt;br /&gt;
16 &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; 0000 0000 0000 0001 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 65536&lt;br /&gt;
17 &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; 0000 0000 0000 0010 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 131072&lt;br /&gt;
18 &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; 0000 0000 0000 0100 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 262144&lt;br /&gt;
19 &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; 0000 0000 0000 1000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 524288&lt;br /&gt;
20 &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; 0000 0000 0001 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 1048576&lt;br /&gt;
21 &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; 0000 0000 0010 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 2097152&lt;br /&gt;
22 &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; 0000 0000 0100 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 4194304&lt;br /&gt;
23 &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; 0000 0000 1000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 8388608&lt;br /&gt;
24 &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; 0000 0001 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 16777216&lt;br /&gt;
25 &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; 0000 0010 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 33554432&lt;br /&gt;
26 &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; 0000 0100 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 67108864&lt;br /&gt;
27 &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; 0000 1000 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 134217728&lt;br /&gt;
28 &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; 0001 0000 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 268435456&lt;br /&gt;
29 &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; 0010 0000 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 536870912&lt;br /&gt;
30 &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; 0100 0000 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; 1073741824&lt;br /&gt;
31 &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; 1000 0000 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; -2147483648&lt;br /&gt;
&lt;br /&gt;
On a 32-core server, there are 2.631308369336935e+35 possible combinations for processor affinity, but a few examples are included below.&lt;br /&gt;
&lt;br /&gt;
Aligned Processors Bit Mask Signed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Integer Representation&lt;br /&gt;
0 and 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0000 0000 0000 0000 0000 0000 0000 0011 &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;br /&gt;
0, 1, 2, and 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0000 0000 0000 0000 0000 0000 0000 1111 &amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;br /&gt;
8 and 9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0000 0000 0000 0000 0000 0011 0000 0000 &amp;nbsp; &amp;nbsp; &amp;nbsp;768&lt;br /&gt;
8, 9, 10, and 11 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0000 0000 0000 0000 0000 1111 0000 0000 &amp;nbsp; &amp;nbsp; &amp;nbsp;3840&lt;br /&gt;
30 and 31 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1100 0000 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; &amp;nbsp;-1073741824&lt;br /&gt;
28, 29, 30, and 31 &amp;nbsp; 1111 0000 0000 0000 0000 0000 0000 0000 &amp;nbsp; &amp;nbsp; &amp;nbsp;-268435456&lt;br /&gt;
&lt;br /&gt;
Because an integer has a a maximum range of 2^32 then the Affinity Mask can only accommodate values for up to 32 CPUs. If your server has between 33 and 64 processors, then SQL Server relies on a 2nd value, called the 64 Bit Affinity Mask, to store the details of the next 32 CPUs.&lt;br /&gt;
&lt;br /&gt;
There are a number of calculators available online, for calculating the signed integer representation of a bit mask. I tend to use &lt;a href=&quot;http://www.binaryconvert.com/convert_signed_int.html&quot;&gt;www.binaryconvert.com/convert_signed_int.html&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/7295896664668926470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/how-to-calculate-binary-bit-masks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7295896664668926470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7295896664668926470'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/how-to-calculate-binary-bit-masks.html' title='How to Calculate Binary Bit Masks'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-3788797525181531496</id><published>2016-06-07T05:35:00.002-07:00</published><updated>2016-06-07T05:35:55.983-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Setup"/><title type='text'>SQL Enterprise Edition vs SQL Enterprise Core Based Licensing Edition</title><content type='html'>&lt;br /&gt;
There is a common point of confusion, when DBAs decide what version of SQL Server to install. Until SQL Server 2012, if you needed Enterprise Edition, then things were straight forward. When SQL Server 2012 was released, however, things changed, with the release of core-based licensing.&lt;br /&gt;
&lt;br /&gt;
Subsequently, SQL Server Enterprise Edition should not be installed in most cases. It is designed as a &quot;tide-me-over&quot; edition, to see companies through, as they move from CAL based, to core based licenses.&lt;br /&gt;
&lt;br /&gt;
What a lot of people do not realize, is there is actually a technical difference between the two editions. The two products have different SKUs and SQL Server Enterprise Edition will only support a maximum of 20 cores.&lt;br /&gt;
&lt;br /&gt;
If you have a server large enough to test this out, you can see for yourself, by running the following query:&lt;br /&gt;
&lt;br /&gt;
SELECT COUNT(*) FROM sys.dm_os_schedulers WHERE status = &#39;VISIBLE ONLINE&#39;&lt;br /&gt;
&lt;br /&gt;
If you are using Enterprise Edition, then the maximum value returned will be either 20, or 40 if the server has hyper-threading turned on.&lt;br /&gt;
&lt;br /&gt;
Check out my books on Apress.com:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.apress.com/9781430239154?gtmf=s&quot;&gt;Pro SQL Server Administration&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.apress.com/9781484217627?gtmf=s&quot;&gt;SQL Server AlwaysOn Revealed&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.apress.com/9781484219423?gtmf=s&quot;&gt;Expert Scripting and Automation for SQL Server DBAs&amp;nbsp;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/3788797525181531496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/sql-enterprise-edition-vs-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3788797525181531496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3788797525181531496'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/sql-enterprise-edition-vs-sql.html' title='SQL Enterprise Edition vs SQL Enterprise Core Based Licensing Edition'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-560957193852812379</id><published>2016-06-07T05:15:00.000-07:00</published><updated>2016-06-07T05:15:22.377-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Optimizer"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><title type='text'>Use SQL 2016 Query Store to Remove Ad-hoc Plans</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;BodyTextFirst&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;Ad-hoc query plans consume memory and
can be of limited use. It is a good idea to remove ad-doc query plans if they
are not being recused. The query below demonstrates how to use Query Store
metadata to identify and remove unwanted ad-hoc query plans from the cache.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;BodyTextFirst&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpFirst&quot;&gt;
DECLARE @SQL NVARCHAR(MAX)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
SELECT @SQL = &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
(&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT
&#39;EXEC sp_query_store_remove_query &#39;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; + CAST(qsq.query_id AS NVARCHAR(6)) + &#39;;&#39;
AS [data()]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM
sys.query_store_query_text AS qsqt&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN
sys.query_store_query AS qsq &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&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; ON
qsq.query_text_id = qsqt.query_text_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN
sys.query_store_plan AS qsp &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&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; ON
qsp.query_id = qsq.query_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN
sys.query_store_runtime_stats AS qsrs &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&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; ON
qsrs.plan_id = qsp.plan_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GROUP BY
qsq.query_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HAVING
SUM(qsrs.count_executions) = 1 &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&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; AND
MAX(qsrs.last_execution_time) &amp;lt; DATEADD (HH, -24, GETUTCDATE())&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER BY
qsq.query_id &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FOR XML
PATH(&#39;&#39;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
) ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;BodyTextFirst&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;



































&lt;span style=&quot;font-family: Calibri, sans-serif; line-height: 115%;&quot;&gt;EXEC(@SQL) ;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;BodyTextFirst&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;span style=&quot;font-family: Calibri, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;BodyTextFirst&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;span style=&quot;font-family: Calibri, sans-serif; line-height: 115%;&quot;&gt;You can find out more about the Query Store in SQL Server 2016, in my new book, Expert Scripting and Automation for SQL Server DBAs, available from Apress at&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Calibri, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 18.4px;&quot;&gt;&lt;a href=&quot;http://www.apress.com/9781484219423?gtmf=s%C2%A0&quot;&gt;www.apress.com/9781484219423?gtmf=s&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;&lt;span style=&quot;font-family: Calibri, sans-serif; line-height: 115%;&quot;&gt;or at Amazon at&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Calibri, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 18.4px;&quot;&gt;&lt;a href=&quot;http://www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422?ie=UTF8&amp;amp;keywords=expert%20scripting%20and%20automation&amp;amp;qid=1465300485&amp;amp;ref_=sr_1_1&amp;amp;sr=8-1&quot;&gt;www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422?ie=UTF8&amp;amp;keywords=expert%20scripting%20and%20automation&amp;amp;qid=1465300485&amp;amp;ref_=sr_1_1&amp;amp;sr=8-1&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/560957193852812379/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/use-sql-2016-query-store-to-remove-ad.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/560957193852812379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/560957193852812379'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/use-sql-2016-query-store-to-remove-ad.html' title='Use SQL 2016 Query Store to Remove Ad-hoc Plans'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-3968103057659603464</id><published>2016-06-07T04:56:00.000-07:00</published><updated>2016-06-07T04:56:09.795-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="automation"/><category scheme="http://www.blogger.com/atom/ns#" term="Powershell"/><title type='text'>Navigating a SQL Server Instance with PowerShell</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;BodyTextFirst&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;As well as navigating a folder
structure with commands such as &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;get-childitem&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;, and &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;set-location&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;, PowerShell can also be used to navigate the SQL Server object
hierarchy of an instance. You can connect PowerShell to the SQL Server database
engine provider by using &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;set-location&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; to navigate to &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;SQLSERVER:\SQL&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; The information returned by &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;get-childitem&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; is dependent on the current location of the object hierarchy. The table below shows what information is returned from each level of the hierarchy.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;BodyTextFirst&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; border: none; mso-border-bottom-alt: solid windowtext .75pt; mso-border-top-alt: solid windowtext .75pt; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184;&quot;&gt;
 &lt;tbody&gt;
&lt;tr&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: none; border-top: solid windowtext 1.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .75pt; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableHead&quot;&gt;
&lt;span lang=&quot;EN-US&quot;&gt;Location&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: none; border-top: solid windowtext 1.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .75pt; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableHead&quot;&gt;
&lt;span lang=&quot;EN-US&quot;&gt;Information Returned&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;border: none; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpFirst&quot;&gt;
&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;border: none;&quot;&gt;SQLSERVER:\SQL&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;border: none;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border: none; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpLast&quot;&gt;
&lt;span lang=&quot;EN-US&quot;&gt;The name of the local machine&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;border: none; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpFirst&quot;&gt;
&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;border: none;&quot;&gt;SQLSERVER:\SQL\ComputerName &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;border: none;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border: none; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpLast&quot;&gt;
&lt;span lang=&quot;EN-US&quot;&gt;The names of the database engine
  instances installed on the local machine&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;border: none; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpFirst&quot;&gt;
&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;border: none;&quot;&gt;SQLSERVER:\SQL\ComputerName\InstanceName&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;border: none;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border: none; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpLast&quot;&gt;
&lt;span lang=&quot;EN-US&quot;&gt;Instance level object types&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border: none; mso-border-bottom-alt: solid windowtext .75pt; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpFirst&quot;&gt;
&lt;span lang=&quot;EN-US&quot;&gt;Lower levels&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border: none; mso-border-bottom-alt: solid windowtext .75pt; padding: 0cm 0cm 0cm 0cm; width: 215.75pt;&quot; valign=&quot;top&quot; width=&quot;360&quot;&gt;
  &lt;div class=&quot;TableTextCxSpLast&quot;&gt;
&lt;span lang=&quot;EN-US&quot;&gt;Object types or objects contained
  within the current location&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;Once you have navigated to the level of the hierarchy, in which you are interested, you are able to use PowerShell to perform basic
operations against objects at that level. For example, the script below will navigate to the &quot;&lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;tables&quot;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; namespace within the &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;&lt;span style=&quot;border: none;&quot;&gt;AdventureWo&lt;span style=&quot;border: none;&quot;&gt;rks2016&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;
database and rename the &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;dbo.DatabaseLog&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; table, to &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;dbo.DatabaseLogPS&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;The &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;dir&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; commands will display the original name and new name of the table.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;div class=&quot;CodeCxSpFirst&quot;&gt;
&lt;a href=&quot;https://www.blogger.com/null&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot;&gt;Import-Module sqlps&lt;o:p&gt;&lt;/o:p&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
sl SQLSERVER:\SQL\ESASSMgmt1\MASTERSERVER\DATABASES\ADVENTUREWORKS2016\TABLES&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
dir | where{$_.name -like
&quot;*DatabaseLog*&quot;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
rename-item -LiteralPath dbo.DatabaseLog
-NewName DatabaseLogPS&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
dir | where{$_.name -like
&quot;*DatabaseLog*&quot;}&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
More complex tasks that do not have a specific cmdlet, associated with them can
be performed by using the&lt;span style=&quot;font-family: inherit;&quot;&gt; &lt;span class=&quot;CodeInline&quot;&gt;&lt;span style=&quot;border: none;&quot;&gt;invoke-sqlcmd&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;cmdlet.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;CodeCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;You can also start PowerShell
from within SSMS. This is done by selecting &quot;Start
PowerShell&quot; from the context menu of an object folder, within Object Explorer.
This will cause the PowerShell CLI to be invoked, with the initial location
being set to the object folder that you used to invoke the CLI.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
My new book, Expert Scripting and Automation for SQL Server DBAs contains extensive details and examples of how to use PowerShell to administer SQL Server. The book is available from Apress at &lt;a href=&quot;http://www.apress.com/9781484219423?gtmf=s&quot;&gt;www.apress.com/9781484219423?gtmf=s&lt;/a&gt; or from Amazon, at &lt;a href=&quot;http://www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422?ie=UTF8&amp;amp;keywords=expert%20scripting%20and%20automation&amp;amp;qid=1465300485&amp;amp;ref_=sr_1_1&amp;amp;sr=8-1&quot;&gt;www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422?ie=UTF8&amp;amp;keywords=expert%20scripting%20and%20automation&amp;amp;qid=1465300485&amp;amp;ref_=sr_1_1&amp;amp;sr=8-1&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div class=&quot;msocomtxt&quot; id=&quot;_com_2&quot; language=&quot;JavaScript&quot;&gt;

&lt;!--[if !supportAnnotations]--&gt;&lt;/div&gt;
&lt;!--[endif]--&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/3968103057659603464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/navigating-sql-server-instance-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3968103057659603464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3968103057659603464'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/navigating-sql-server-instance-with.html' title='Navigating a SQL Server Instance with PowerShell'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-7877762341018948291</id><published>2016-06-06T08:00:00.000-07:00</published><updated>2016-06-06T08:00:13.849-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Central Management Servers"/><title type='text'>Running Administrative Queries Across Multiple Servers</title><content type='html'>As a DBA, sometimes we are asked questions, such as &quot;What is total size of databases used by Application A?&quot; or &quot;Does Application A have any databases with a mismatched collation?&quot;&lt;br /&gt;
&lt;br /&gt;
If Application A has a single database server, then these questions are straight forward to answer. If Application A has databases dispersed across multiple instances, however, then the question becomes more time consuming to answer. The temptation is to connect to each instance individually, and copy/pasting the query.&lt;br /&gt;
&lt;br /&gt;
It is possible to make use of Central Management Servers, to simplify answering this kind of question, however. For example, if you are supporting a large, dispersed data-tier application, you can create a server group, containing each of the instances that support the application.&lt;br /&gt;
&lt;br /&gt;
For example, in the image below, you can see that I have created two folders; one for the EMEA region and another for the US.&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/AVvXsEh4HOMI27roK9zS5Ilhh0IptVSAP6jtsfOacYMgIDD-6DOXGV22dTILbxZ9sd3_ap2HxA0W0Gv3eGXXwzWWCdBsBsiqZO60IKrsgyeHLDCKgBJThjWhxoqudeQB4LQhXnBVgM-oYS_mLX8/s1600/2016-06-06_15-23-12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4HOMI27roK9zS5Ilhh0IptVSAP6jtsfOacYMgIDD-6DOXGV22dTILbxZ9sd3_ap2HxA0W0Gv3eGXXwzWWCdBsBsiqZO60IKrsgyeHLDCKgBJThjWhxoqudeQB4LQhXnBVgM-oYS_mLX8/s1600/2016-06-06_15-23-12.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
&lt;a href=&quot;https://www.blogger.com/null&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot;&gt;&lt;span lang=&quot;EN-IN&quot;&gt;We can now register our &lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;servers\&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;instances under the relevant group. Below, you can see that I use the New Server Registration dialog box, to add servers. In this example, I will add two servers, nammed ESPROD1 and ESPROD2, to the &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;Production&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; | &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;NTAM&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; server group.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&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/AVvXsEiYKP0OOBh4zfLq510nUg6Xnwh7IKqGONKcWpYSE3wa833iFy8H3_BZ9Je-9Z_tret3i7u1-Kf4ittKwOjJdcfrEhTjpfxn7t6K1pzmS_Ilj-J6e8tV34kw0gu3DmzTmgyccEQxEoUpShE/s1600/2016-06-06_15-23-12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYKP0OOBh4zfLq510nUg6Xnwh7IKqGONKcWpYSE3wa833iFy8H3_BZ9Je-9Z_tret3i7u1-Kf4ittKwOjJdcfrEhTjpfxn7t6K1pzmS_Ilj-J6e8tV34kw0gu3DmzTmgyccEQxEoUpShE/s320/2016-06-06_15-23-12.png&quot; width=&quot;254&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-weight: normal;&quot;&gt;Imagine a scenario where you have a
number of SQL Server instances, where the database files are hosted on a SAN
(Storage Area Network). You come into work one morning, to find that there has
been an issue with the production SAN and you need to check all databases, on
all instances, for corruption. This can be easily achieved, using central
management servers.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;div style=&quot;font-family: inherit;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;Because you have a separate SAN for each
environment, in each data center, you will only want to check the servers in
the &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span style=&quot;border: none; line-height: 115%;&quot;&gt;NTAM&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt; server group, as this is where the SAN issue
occurred. Therefore, select New Query, from the context menu of the &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span style=&quot;border: none; line-height: 115%;&quot;&gt;NTAM&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt; server group. This will cause a new query
window to be displayed and we will use &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span style=&quot;border: none; line-height: 115%;&quot;&gt;DBCC CHECKDB &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;to check the consistency of all databases on
both instances. This is demonstrated below:&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;span style=&quot;color: black; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot;&gt;&lt;/a&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;EXEC
sp_MSforeachDB &#39;DBCC CHECKDB (?)&#39; ;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;MsoCommentReference&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: inherit;&quot;&gt;
&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoBodyText&quot; style=&quot;font-family: inherit;&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;This command executes the undocumented&lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;
sp_MSForeachDB&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; system stored procedure.
We pass the command that we want to run against each database, into this
procedure and use &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;?&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt; as a placeholder for the database name. This is automatically
populated by &lt;/span&gt;&lt;span class=&quot;CodeInline&quot;&gt;&lt;span lang=&quot;EN-IN&quot; style=&quot;border: none;&quot;&gt;sp_MSForeachDB&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;, for
each database in turn.&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span lang=&quot;EN-IN&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Below is a partial
output. You can easily see which results relate to each server, along with the
execution context. You may also notice the query status bar is pink instead of
yellow and displays the name of the server group that we can the command
against.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&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/AVvXsEjyE-0bpq9WReP5pNwJbZpj_wBrX8NEZu20QAj_mDrRO4SvJJOq8s5yWrsbLs-fb-JIPnjFWdQ6gZPXFRGg8gL5ZZlxBtCcjJi3g6C6kMZyVjLDGhV23rLIyYpdw5Ta1hQjt7ZkCRNTP2Y/s1600/2016-06-06_15-23-12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;156&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyE-0bpq9WReP5pNwJbZpj_wBrX8NEZu20QAj_mDrRO4SvJJOq8s5yWrsbLs-fb-JIPnjFWdQ6gZPXFRGg8gL5ZZlxBtCcjJi3g6C6kMZyVjLDGhV23rLIyYpdw5Ta1hQjt7ZkCRNTP2Y/s320/2016-06-06_15-23-12.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: inherit;&quot;&gt;
&lt;div&gt;
&lt;div class=&quot;msocomtxt&quot; id=&quot;_com_1&quot; language=&quot;JavaScript&quot;&gt;
&lt;!--[if !supportAnnotations]--&gt;&lt;/div&gt;
&lt;!--[endif]--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/h4&gt;
&lt;div class=&quot;MsoBodyText&quot;&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;To learn much more about Central Management Servers, including further examples of useful queries to run across instances, full details of how to configure them and a demonstration of how to evaluate Policies against Central Management Servers or Server Groups, please refer to my new book, &quot;Expert Scripting and Automation for SQL Server DBAs&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;EN-IN&quot;&gt;&lt;br /&gt;&lt;/span&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/AVvXsEihiCJOzU_fRW0PWichnhG4671a6dqKnSZVVQc_B5LQVQlyfOgEdXlYniv9zE-TBPTx4V0jUxXQgXL2EZaQkt2Ya5Rtz_qqKQ-5BrKPc69lwn4ZYbn2w7yfT39cIHBR6wKpUTaBfO8Agto/s1600/Expert+Scripting+Init+Cover.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihiCJOzU_fRW0PWichnhG4671a6dqKnSZVVQc_B5LQVQlyfOgEdXlYniv9zE-TBPTx4V0jUxXQgXL2EZaQkt2Ya5Rtz_qqKQ-5BrKPc69lwn4ZYbn2w7yfT39cIHBR6wKpUTaBfO8Agto/s320/Expert+Scripting+Init+Cover.png&quot; width=&quot;255&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
Apress link is&amp;nbsp;&lt;a href=&quot;http://www.apress.com/9781484219423?gtmf=s&quot;&gt;www.apress.com/9781484219423?gtmf=s&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
Amazon US link is &lt;a href=&quot;http://www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422/ref=sr_1_1?&quot;&gt;www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422/ref=sr_1_1?&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div class=&quot;msocomtxt&quot; id=&quot;_com_2&quot; language=&quot;JavaScript&quot;&gt;
&lt;!--[if !supportAnnotations]--&gt;&lt;/div&gt;
&lt;!--[endif]--&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/7877762341018948291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/running-administrative-queries-across.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7877762341018948291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7877762341018948291'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/running-administrative-queries-across.html' title='Running Administrative Queries Across Multiple Servers'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4HOMI27roK9zS5Ilhh0IptVSAP6jtsfOacYMgIDD-6DOXGV22dTILbxZ9sd3_ap2HxA0W0Gv3eGXXwzWWCdBsBsiqZO60IKrsgyeHLDCKgBJThjWhxoqudeQB4LQhXnBVgM-oYS_mLX8/s72-c/2016-06-06_15-23-12.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-1123298188521451881</id><published>2016-06-06T02:38:00.000-07:00</published><updated>2016-06-06T07:20:16.485-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Books"/><category scheme="http://www.blogger.com/atom/ns#" term="Powershell"/><category scheme="http://www.blogger.com/atom/ns#" term="Server Agent"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><category scheme="http://www.blogger.com/atom/ns#" term="SSIS"/><title type='text'>Expert Scripting and Automation for SQL Server DBAs</title><content type='html'>My new book &quot;Expert Scripting and Automation for SQL Server DBAs&quot; is now available to pre-order on Amazon and Apress.com&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/AVvXsEidVmoOGSHYEaI_0njS5M39bBBctsW-d791FhgcTaNHeCLVCiGZcN4k9m9ZoamAQHdOZqEmiXEQYOwtZKxhMyinqN9UzmynAQUD1m2_zgMZT9Y5X4Pni084VhFNcFT5F93pHi0ziSb3Z60/s1600/Expert+Scripting+Init+Cover.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidVmoOGSHYEaI_0njS5M39bBBctsW-d791FhgcTaNHeCLVCiGZcN4k9m9ZoamAQHdOZqEmiXEQYOwtZKxhMyinqN9UzmynAQUD1m2_zgMZT9Y5X4Pni084VhFNcFT5F93pHi0ziSb3Z60/s400/Expert+Scripting+Init+Cover.png&quot; width=&quot;318&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
The link for Amazon.com is&amp;nbsp;&lt;a href=&quot;http://www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422/ref=sr_1_1?ie=UTF8&amp;amp;qid=1465205714&amp;amp;sr=8-1&amp;amp;keywords=expert+scripting+and+automation&quot;&gt;www.amazon.com/Expert-Scripting-Automation-Server-DBAs/dp/1484219422/ref=sr_1_1?ie=UTF8&amp;amp;qid=1465205714&amp;amp;sr=8-1&amp;amp;keywords=expert+scripting+and+automation&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
The link for Amazon.co.uk is &lt;a href=&quot;http://www.amazon.co.uk/Expert-Scripting-Automation-Server-DBAs/dp/1484219422/280-0264565-3359429?ie=UTF8&amp;amp;keywords=expert%20scripting%20and%20automation&amp;amp;qid=1465205714&amp;amp;ref_=sr_1_1&amp;amp;sr=8-1&quot;&gt;www.amazon.co.uk/Expert-Scripting-Automation-Server-DBAs/dp/1484219422/280-0264565-3359429?ie=UTF8&amp;amp;keywords=expert%20scripting%20and%20automation&amp;amp;qid=1465205714&amp;amp;ref_=sr_1_1&amp;amp;sr=8-1&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
The link for Apress.com is &lt;a href=&quot;http://www.apress.com/9781484219423?gtmf=s&quot;&gt;www.apress.com/9781484219423?gtmf=s&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
It is worth noting that the expected release date on Amazon is not correct. Publication is actually expected in August.&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/1123298188521451881/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/expert-scripting-and-automation-for-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/1123298188521451881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/1123298188521451881'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/06/expert-scripting-and-automation-for-sql.html' title='Expert Scripting and Automation for SQL Server DBAs'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidVmoOGSHYEaI_0njS5M39bBBctsW-d791FhgcTaNHeCLVCiGZcN4k9m9ZoamAQHdOZqEmiXEQYOwtZKxhMyinqN9UzmynAQUD1m2_zgMZT9Y5X4Pni084VhFNcFT5F93pHi0ziSb3Z60/s72-c/Expert+Scripting+Init+Cover.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-8712597833200699818</id><published>2016-01-18T03:45:00.000-08:00</published><updated>2016-01-18T03:48:58.766-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><category scheme="http://www.blogger.com/atom/ns#" term="SSIS"/><title type='text'>SSIS Toolbox in SSDT for Visual Studio 2015</title><content type='html'>I am currently writing my latest book - Expert Scripting and Automation for DBAs, which Apress will be publishing later this year. The book is based around SQL Server 2016 and I am currently writing a chapter that is based around SSIS.&lt;br /&gt;
&lt;br /&gt;
I needed to use SSDT for Visual Studio 2015, so that I could use the pre-release version of the Azure Feature Pack, for SSIS 2016. When creating a project, however, I was rather disturbed to find that I had no controls in my Toolbox!&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/AVvXsEiDpagaCAbLr8a3yUrqtsuuyisrxAqtN8ukSUbF5ak0xyyWlTvWTiGcsASGoxMwQ5k_wx05V2rBeIppojPHcmPjPP5x747kTDqEMMmEtm6w7noLWVGz0Rdch-DkixIZPdlQyO5GnTkxuds/s1600/empty+toolbox.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDpagaCAbLr8a3yUrqtsuuyisrxAqtN8ukSUbF5ak0xyyWlTvWTiGcsASGoxMwQ5k_wx05V2rBeIppojPHcmPjPP5x747kTDqEMMmEtm6w7noLWVGz0Rdch-DkixIZPdlQyO5GnTkxuds/s1600/empty+toolbox.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Apparently, there are two Toolbox windows, and SSDT defaults to the wrong one. You should navigate to View | Other Windows and open the SSIS Toolbox window. Normality will at once be restored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/8712597833200699818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/01/ssis-toolbox-in-ssdt-for-visual-studio.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/8712597833200699818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/8712597833200699818'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2016/01/ssis-toolbox-in-ssdt-for-visual-studio.html' title='SSIS Toolbox in SSDT for Visual Studio 2015'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDpagaCAbLr8a3yUrqtsuuyisrxAqtN8ukSUbF5ak0xyyWlTvWTiGcsASGoxMwQ5k_wx05V2rBeIppojPHcmPjPP5x747kTDqEMMmEtm6w7noLWVGz0Rdch-DkixIZPdlQyO5GnTkxuds/s72-c/empty+toolbox.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-3690503092983747913</id><published>2015-12-06T22:55:00.000-08:00</published><updated>2016-01-18T03:49:10.750-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Books"/><title type='text'>Pro SQL Server Administration</title><content type='html'>&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/AVvXsEhgKer8h2gPs3UWtZPBde3i7viCah3LsgGf4t020XRmAdQSPm1vY5z_kub4_YPxGX_kpFY7P-tRE5AaZa2iVJX5z9ZUXCNSmUdHGd9OzxpgeaYkIDeyeSfX9ILZ5rABhb8TJe7dhqylbLo/s1600/9781484207116+HiRes.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgKer8h2gPs3UWtZPBde3i7viCah3LsgGf4t020XRmAdQSPm1vY5z_kub4_YPxGX_kpFY7P-tRE5AaZa2iVJX5z9ZUXCNSmUdHGd9OzxpgeaYkIDeyeSfX9ILZ5rABhb8TJe7dhqylbLo/s320/9781484207116+HiRes.jpg&quot; width=&quot;224&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
I am very excited that my first book has now been published by Apress. Pro SQL Server Administration is available in paperback and e-book formats, pretty much everywhere, including&amp;nbsp;&lt;a href=&quot;http://www.apress.com/9781484207116?gtmf=s&quot;&gt;Apress&lt;/a&gt;, &lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter-ebook/dp/B0157W4JNE/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1449471033&amp;amp;sr=1-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;Amazon&lt;/a&gt;&amp;nbsp;and &lt;a href=&quot;https://www.waterstones.com/book/pro-sql-server-administration-2015/peter-carter/9781484207116&quot;&gt;Waterstones&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/3690503092983747913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2015/12/pro-sql-server-administration.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3690503092983747913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/3690503092983747913'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2015/12/pro-sql-server-administration.html' title='Pro SQL Server Administration'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgKer8h2gPs3UWtZPBde3i7viCah3LsgGf4t020XRmAdQSPm1vY5z_kub4_YPxGX_kpFY7P-tRE5AaZa2iVJX5z9ZUXCNSmUdHGd9OzxpgeaYkIDeyeSfX9ILZ5rABhb8TJe7dhqylbLo/s72-c/9781484207116+HiRes.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-6283647376144897447</id><published>2011-07-11T06:54:00.001-07:00</published><updated>2016-01-18T03:49:21.817-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Development"/><title type='text'>Finding Object Dependencies In SQL Server</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In a sprawling database application, it can sometime be a nightmare if you need to alter the definition of a table, for fear that you will break an object that references it, that you were unaware of. (Although this will all be detailed in your documentation of course! ;-) )&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;But recently I found a great DMF, which is documented on MSDN, but I had never come across, that given the name of a table, will list all of the Procedures, Functions, Views and Triggers that reference it, and you can join it back to other system object, such as sys.sql_modules to pull back other useful information, such as is the object schema_bound (which will potentially stop you altering the table, and throw an error when you run the ALTER script.)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The DMF is called sys.&lt;span style=&quot;color: green; font-family: &amp;quot;courier new&amp;quot;; font-size: 10pt;&quot;&gt; &lt;/span&gt;dm_sql_referencing_entities and the example below will list the details of all objects that depend on a table called mySchema.myTable, along with if the object is schema bound, and even the object’s definition (providing it is not encrypted).&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;SELECT referencing_schema_name, referencing_entity_name, is_schema_bound, [definition]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;FROM sys.dm_sql_referencing_entities (&#39;mySchema.myTable&#39;, &#39;OBJECT&#39;) r&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;INNER JOIN sys.sql_modules m &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;mso-tab-count: 1;&quot;&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; &lt;/span&gt;ON r.referencing_id = m.object_id&lt;/span&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/6283647376144897447/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/07/finding-object-dependancies-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/6283647376144897447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/6283647376144897447'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/07/finding-object-dependancies-in-sql.html' title='Finding Object Dependencies In SQL Server'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-7085765213294111993</id><published>2011-07-11T06:35:00.001-07:00</published><updated>2016-01-18T03:49:31.202-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SSIS"/><category scheme="http://www.blogger.com/atom/ns#" term="Troubleshooting"/><title type='text'>SSIS - Execute Process Task Hangs When Run From Server Agent</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;I was faced with an interesting problem recently. I had a SSIS Package that was stored in the Package Store on an ETL Server, and run from a Server Agent job on a Clustered SQL Instance.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;If the package was run in Debug mode, it worked perfectly. If it was run from Windows Scheduled Tasks on the Cluster, it also ran perfectly, but when run from Server Agent on the Cluster, it failed.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Or to be more accurate, it didn’t fail! In fact it didn’t do anything! It reached an execute process task that was calling a decompression utility, and sat there, not working, not failing, not doing anything!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Well, I tried the usual things, such as:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Adding SSIS Server to Local Intranet Zone&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Turning on Allow Unsafe Files&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Using &quot;God Account&quot; to run job&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Using &quot;God Account&quot; to Run As on the execute process&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Making the owner of the .exe the same account as the execution context of the process&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Disable attachment manager&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;I knew the package and executable worked, so I was sure that it was a OS level setting, but what? Well, I struggled with this, with the aid of an infrastructure team and also MS Technical Support, but the answer finally came from the MSDN Forums, who suggested creating an Environment Variable called SEE_MASK_NOZONECHECKS and setting the Value to 1.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;This worked perfectly, but it was an interesting situation, and wanted to share the resolution with you all.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/7085765213294111993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/07/ssis-execute-process-task-hangs-when.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7085765213294111993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7085765213294111993'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/07/ssis-execute-process-task-hangs-when.html' title='SSIS - Execute Process Task Hangs When Run From Server Agent'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-5865741629221125848</id><published>2011-04-24T09:59:00.000-07:00</published><updated>2016-01-18T03:49:42.308-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Denali"/><category scheme="http://www.blogger.com/atom/ns#" term="SSIS"/><title type='text'>Including Current Date In a Flat File Name - SSIS</title><content type='html'>There was a thread on MSDN Forums, which paraphrased, asked &quot;How can I include the current Year and Month in a file name when I create a Flat File in SSIS&quot;&lt;br /&gt;
&lt;br /&gt;
Although this is a relatively straight forward task, because SSIS is so visual, it can be difficult to explain how to do things in Forum threads, so I decided to produce this short walk through video. Hope you enjoy, and find it useful...&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.youtube.com/embed/4Xgzz1VeKqs?feature=player_embedded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/5865741629221125848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/including-current-date-in-flat-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/5865741629221125848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/5865741629221125848'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/including-current-date-in-flat-file.html' title='Including Current Date In a Flat File Name - SSIS'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-6056389374926670103</id><published>2011-04-24T08:12:00.000-07:00</published><updated>2016-01-18T03:49:49.817-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Security"/><title type='text'>Find a User&#39;s Effective Permissions</title><content type='html'>There was a recent post on the MSDN forums, that paraphrased, asked, how do I find out what permissions a User has to all Objects, at all levels, including those granted by their role memberships, etc.&lt;br /&gt;
&lt;br /&gt;
Now, I am assuming that this is a fairly common security auditing task, so I scanned Google to dig out a script that would do it, but to my amazement, I could not find one, so I decided to write one. It is a pretty simple script, using the fn_my_permissions function and a couple of well known system tables.&lt;br /&gt;
&lt;br /&gt;
In order to run it, you will need to be able to impersonate the login that you are running it for, and of course, you will also need the appropriate permissions to the system tables.&lt;br /&gt;
&lt;br /&gt;
Feel free to modify the script, but please give due credit. This will work with 2005 and 2008, but I actually wrote it in Denali, so it is defiantly forward-compatible. Enjoy...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;EXECUTE AS LOGIN = &#39;INSERT LOGIN NAME&#39;&lt;br /&gt;
&amp;nbsp;SELECT t.name,&amp;nbsp; a.subentity_name, a.permission_name &lt;br /&gt;
&amp;nbsp;FROM sys.objects t&lt;br /&gt;
&amp;nbsp;CROSS APPLY fn_my_permissions(QUOTENAME(t.name), &#39;OBJECT&#39;) a&lt;br /&gt;
&amp;nbsp;UNION ALL &lt;br /&gt;
&amp;nbsp;SELECT d.name, a.subentity_name, a.permission_name &lt;br /&gt;
&amp;nbsp;FROM sys.databases d&lt;br /&gt;
&amp;nbsp;CROSS APPLY fn_my_permissions(QUOTENAME(d.name), &#39;DATABASE&#39;) a&lt;br /&gt;
&amp;nbsp;UNION ALL &lt;br /&gt;
&amp;nbsp;SELECT @@SERVERNAME, a.subentity_name, a.permission_name &lt;br /&gt;
&amp;nbsp;FROM fn_my_permissions(NULL, &#39;SERVER&#39;) a&lt;br /&gt;
&amp;nbsp;ORDER BY t.name&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;&amp;nbsp;REVERT &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/6056389374926670103/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/find-users-effective-permissions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/6056389374926670103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/6056389374926670103'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/find-users-effective-permissions.html' title='Find a User&#39;s Effective Permissions'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-2059252415572346463</id><published>2011-04-23T18:19:00.000-07:00</published><updated>2016-01-18T03:50:05.234-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><title type='text'>Head In The Clouds</title><content type='html'>In Paul Randal&#39;s recent SQLSkills Insider e-mail, he talked briefly about the SQL Azure, and how he had not seen his Clients express a large appetite for it&amp;nbsp;&quot;yet&quot;, and that inspired me to write this post, (which I have been meaning to write for a couple of weeks), to share my thoughts on Azure.&lt;br /&gt;
&lt;br /&gt;
So firstly, I just want to state my position on Cloud Computing in general, and that for the most part is very positive. The opportunity to access your applications from any part of the world, with consistent performance and&amp;nbsp;a massively reduced Total Cost Of Ownership has to be exciting, and there are many applications, such as Office and even Exchange, that I feel are a perfect fit for the Cloud.&lt;br /&gt;
&lt;br /&gt;
SQL on the other hand is a different matter. Does it really fit in the Cloud, and if it does, what place does it hold? Will it ever be able to host Enterprise class systems, or will in fall into the category of Virtulization, which is great in the most part, but does not fit well for&amp;nbsp;SQL, especially for Enterprise Solutions?&lt;br /&gt;
&lt;br /&gt;
Well, because of these concerns, and because of the current immaturity of Azure, until recently, I have shyed away from playing around with this app, and kept my focus on traditional SQL, until...&lt;br /&gt;
&lt;br /&gt;
I recently&amp;nbsp;spent several months working on a project to plan the up-scaling of an established 2TB local&amp;nbsp;system to global 32TB Enterprise class system. The obvious choice for this system was a FastTrack Data warehouse Appliance, and I had a fantastic opportunity to do some POC work at Microsoft HQ, (Which I will blog about soon). The POC was successful, and I thought it was a done-deal, but then an instruction came from a very senior level, that we should be investigating putting the application in the Cloud.&lt;br /&gt;
&lt;br /&gt;
Now my gut reaction here was wow! An opportunity to build an Enterprise class database in the Cloud, but within seconds (and luckily before speaking) my professional head suppressed my geek head and I articulated the answer that it would not be practical because of the 50GB limit in Azure. This led to the suggestion that we could shard the data across multiple instances, which is true, but seemed like trying to plug a square hole with a round peg. I knew at that point that the idea was unlikely to go further, and we would probably stay with FastTrack Solution, but I felt it prudent to subscribe to Azure and have a play with it.&lt;br /&gt;
&lt;br /&gt;
So when playing with Azure, the thing that surprised me was how limited the product currently is. A lot of the limitations surround Administration, and make perfect sense, for example, when your database is in the Cloud, why would you need to worry about High Availability? There is already a 4 9s SLA with MS, just by signing up. Some of the other limitations, however, are just a bit strange. For example, you can not create Heap Tables, only Tables with Clustered Indexes. Don&#39;t get me wrong, I&#39;m all in favour of having a CI on all tables, but it just felt like a strange limitation. I also found that quite a few useful tools,&amp;nbsp;such as Service Broker are not supported, and even my favourite %%PhysLoc%% query would not compile!&lt;br /&gt;
&lt;br /&gt;
According to a contact of mine, there are currently only about 20 people in the Azure product team, and as I already mentioned, the offering is still fairly immature, so I fully expect that a lot of functionality will appear over the next few months and years, so from a technical perspective, I don&#39;t feel that we are quite ready to put many systems in the Cloud &quot;yet&quot;, but we may be soon. I also suspect that the size restrictions will be relaxed as bandwidth improves.&lt;br /&gt;
&lt;br /&gt;
My main question mark around Azure (thinking Medium-Term)&amp;nbsp;is more political. If you are storing client data, especially if it is from a sensitive sector, such as public service data, I can not imagine those Clients,&amp;nbsp;when asking the&amp;nbsp;regular question &quot;Where exactly are you storing my data&quot;, liking the answer &quot;Oh, it&#39;s in the Cloud...&quot;&lt;br /&gt;
&lt;br /&gt;
Now I know that this stance is silly because I would be willing to bet large amounts of money that data is much more secure in Microsoft&#39;s Cloud, than it is in the vast majority of Data Centres, but what I&#39;m not sure, is how long it will take, or how to even bring-about that cultural change that would be required, especially as the people who will need to be convinced are likely to be non-technical.&lt;br /&gt;
&lt;br /&gt;
My other question mark, is a rather self-centred one, and revolves around (if I&#39;m honest with myself), humans not liking change, because from a corporate point of view, it is actually a positive...&lt;br /&gt;
&lt;br /&gt;
According to my contact, Microsoft&#39;s medium-term SQL Server policy will be to release features first to the Cloud, because they can easily be rolled back if problematic. (This is a concern in itself for the Cloud because it will always be the most up-to-date but possibly also the most unstable platform), then to release to Appliances. (FastTrack is already on v3, PDW is out and OLTP and BI appliances are on the way), and then finally to release to the traditional market.&lt;br /&gt;
&lt;br /&gt;
Now this leads me to assume, that within the medium-term, large SQL projects will either be hosted in the Cloud, or on Appliances, and both of these environments are largely pre-configured and pre-optimized, so where does that leave skilled SQL professionals, who make a living out of performing those complex optimizations that will no longer be required?&lt;br /&gt;
&lt;br /&gt;
Again, this is probably a silly stance, because there are bound to be a whole&amp;nbsp;different set of issues&amp;nbsp;that will require highly skilled professionals. For example, just because Windows 7 is a damn site easier to work with and configure than DOS 6.1, does not mean that there is no market for Desktop Support Technicians, or Network Engineers,&amp;nbsp;but it does mean that more people are able to support it, which means that the market rates are dramatically lower than they were 15 years ago.&lt;br /&gt;
&lt;br /&gt;
Maybe I&#39;m an eternal pessimist, but it is certainly food for thought? If you have any thoughts on the subject, please feel free to leave comments...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/2059252415572346463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/head-in-clouds.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/2059252415572346463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/2059252415572346463'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/head-in-clouds.html' title='Head In The Clouds'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-1980824940284165154</id><published>2011-04-13T14:57:00.000-07:00</published><updated>2016-01-18T03:50:15.035-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Internals"/><category scheme="http://www.blogger.com/atom/ns#" term="sqlsoton"/><title type='text'>SQL Server Southampton User Group 13/04/2011</title><content type='html'>I was speaking at the Southampton SQL UG tonight, and as promised, here are links to the code samples that I used, plus some more in depth articles on the subjects I spoke about. Thanks to everybody for a good night...!&lt;br /&gt;
&lt;br /&gt;
Shrinking Databases&lt;br /&gt;
&lt;br /&gt;
Why not to shrink a database &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/01/why-not-to-shrink-database.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
The world&#39;s worst maintenance plan? &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/01/worlds-worst-maintenance-plan.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Using %%physloc%%&lt;br /&gt;
&lt;br /&gt;
How to find what page your data is stored on&amp;nbsp;&lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2010/12/what-files-pages-are-is-my-table-stored.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
Logical Order NOT Physical Order &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2010/12/logical-order-not-physical-order.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Allocation Units&lt;br /&gt;
&lt;br /&gt;
What Are Allocation Units &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/04/what-are-allocation-units.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
Querying Allocation Units &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/04/how-to-query-allocation-units.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/1980824940284165154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/sql-server-southampton-user-group.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/1980824940284165154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/1980824940284165154'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/sql-server-southampton-user-group.html' title='SQL Server Southampton User Group 13/04/2011'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-8952597326392206549</id><published>2011-04-06T14:41:00.000-07:00</published><updated>2016-01-18T03:50:27.165-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Disaster Recovery"/><category scheme="http://www.blogger.com/atom/ns#" term="Internals"/><title type='text'>The Curious Case Of The Phantom Last Log Backup!</title><content type='html'>&lt;iframe align=&quot;right&quot; frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=sqldowampdir-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735626243&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=2C2727&amp;amp;bg1=2C2727&amp;amp;f=ifr&quot; style=&quot;align: right; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;&quot;&gt;&lt;/iframe&gt;I was extremely &quot;busy&quot; at work the other day. So much so, I was sat reading Paul Randal&#39;s Blog, when I came across an interesting article on how to tell if your database is really in Full Recovery, &lt;a href=&quot;http://www.sqlskills.com/BLOGS/PAUL/post/New-script-is-that-database-REALLY-in-the-FULL-recovery-mode.aspx&quot;&gt;see here&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
The general premise is that when you switch from Simple to Full recovery model, the model does not change until the log backup chain has been established, with a backup. This is called pseudo-simple mode, and can be recognised by a database that is in Full recovery model showing a NULL value for last_log_backup_lsn in sys.database_recovery_staus&lt;br /&gt;
&lt;br /&gt;
I was a little board, so I though that I would have a look and make sure that our OLTP databases were really in Full Recovery Model, and they were, but much to my surprise I found that some of our VLDs that were in Simple Recovery Model were showing a non-NULL value in the last_log_backup_lsn column in sys.database_recovery_status catalogue view.&lt;br /&gt;
&lt;br /&gt;
This confused me and I ask Paul Randal if there was a pseudo-full mode, but there is not, so why was there a last_log_backup_lsn? Well, intrigued, I kept an eye on the transaction logs of the databases involved, buy using SELECT * FROM sys.fn_dblog(NULL,NULL) which shows all log records in the active VLFs. &lt;br /&gt;
&lt;br /&gt;
Day 1 - 7436 entries, day 2 - 762 entries.&lt;br /&gt;
&lt;br /&gt;
This was good news! It meant that the log had been truncated, so the databases were behaving as if the were in Simple recovery model. This was a relief, as my initial fear was that they were behaving as though they were in Full, and of course, we were not taking Transaction Log backups, as we thought they were in Simple!&lt;br /&gt;
&lt;br /&gt;
So the next test - Was this record of a last LSN only in the&amp;nbsp;sys.database_recovery_status catalogue view or was it&amp;nbsp;embedded more internally? To check this, I ran DBCC PAGE on the boot page of the database. The database ID happened to be 8, so the syntax was &lt;br /&gt;
&lt;br /&gt;
DBCC TRACEON(3604)&lt;br /&gt;
DBCC PAGE(8,1,9,3)&lt;br /&gt;
&lt;br /&gt;
Here, I turned on trace flag 3604, so that the DBCC output would be to the messages window, rather than the event log. The parameters for DBCC Page represent the Database ID, The file number, the page number and then the level of detail. The database boot page is always at page 9 of file 1 &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/03/system-pages-in-sql-server.html&quot;&gt;see here&lt;/a&gt;&amp;nbsp;for more info on system pages.&lt;br /&gt;
&lt;br /&gt;
The results showed that the boot page also contained the lsn and time stamp of the last log backup, so the mystery continued. Where did it come from? Unfortunately, it was a production system that I was looking at, so I was not able to play around with it too much, but after a few hours of trying different things, that I new had occurred on the production system, I managed to reproduce the symptom, with the following script:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;CREATE DATABASE [lsn_test] ON&amp;nbsp; PRIMARY &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;USE [master]&lt;br /&gt;
GO&lt;br /&gt;
ALTER DATABASE [lsn_test] SET RECOVERY FULL WITH NO_WAIT&lt;br /&gt;
GO&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The results were as expected...&lt;br /&gt;
&lt;br /&gt;
name&amp;nbsp;recovery_model_desc&amp;nbsp;last_log_backup_lsn&lt;br /&gt;
lsn_test&amp;nbsp;FULL&amp;nbsp;NULL&lt;br /&gt;
&lt;br /&gt;
So now...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;BACKUP DATABASE [lsn_test] &lt;br /&gt;
TO&amp;nbsp; DISK = N&#39;C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER=MSSQL\Backup\lsn_test.bak&#39; &lt;br /&gt;
WITH NOFORMAT, NOINIT,&amp;nbsp; NAME = N&#39;lsn_test-Full Database Backup&#39;, &lt;br /&gt;
SKIP, NOREWIND, NOUNLOAD,&amp;nbsp; STATS = 10&lt;br /&gt;
GO&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Again, results as expected...&lt;br /&gt;
&lt;br /&gt;
name&amp;nbsp;recovery_model_desc&amp;nbsp;last_log_backup_lsn&lt;br /&gt;
lsn_test&amp;nbsp;FULL&amp;nbsp;25000000006200064&lt;br /&gt;
&lt;br /&gt;
Next, was to switch the Database to Simple...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;USE [master]&lt;br /&gt;
GO&lt;br /&gt;
ALTER DATABASE [lsn_test] SET RECOVERY SIMPLE WITH NO_WAIT&lt;br /&gt;
GO&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Once more, predictable results...&lt;br /&gt;
&lt;br /&gt;
name&amp;nbsp;recovery_model_desc&amp;nbsp;last_log_backup_lsn&lt;br /&gt;
lsn_test&amp;nbsp;SIMPLE&amp;nbsp;NULL&lt;br /&gt;
&lt;br /&gt;
So now lets backup the database again...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;BACKUP DATABASE [lsn_test] TO&amp;nbsp; DISK = N&#39;C:\Program Files\Microsoft SQL=erver\MSSQL10.MSSQLSERVER\MSSQL\Backup\lsn_test.bak&#39; &lt;br /&gt;
WITH NOFORMAT, NOINIT,&amp;nbsp; &lt;br /&gt;
NAME = N&#39;lsn_test-Full Database Backup&#39;, SKIP, NOREWIND, NOUNLOAD,&amp;nbsp; ST=TS = 10&lt;br /&gt;
GO&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Once more, the correct results...&lt;br /&gt;
&lt;br /&gt;
name&amp;nbsp;recovery_model_desc&amp;nbsp;last_log_backup_lsn&lt;br /&gt;
lsn_test&amp;nbsp;SIMPLE&amp;nbsp;NULL&lt;br /&gt;
&lt;br /&gt;
So finally, what happens if we restore the database...?&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;RESTORE DATABASE [lsn_test] FROM&amp;nbsp; DISK = N&#39;C:\Program Files\Microsoft =QL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup\lsn_test.bak&#39; &lt;br /&gt;
WITH&amp;nbsp; FILE = 2,&amp;nbsp; NOUNLOAD,&amp;nbsp; STATS = 10&lt;br /&gt;
GO&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Ah, this doesn&#39;t look so straight forward...!&lt;br /&gt;
&lt;br /&gt;
name&amp;nbsp;recovery_model_desc&amp;nbsp;last_log_backup_lsn&lt;br /&gt;
lsn_test&amp;nbsp;SIMPLE&amp;nbsp;25000000011900001&lt;br /&gt;
So basically, SQL has picked up the last log backup LSN from the restore, but it is meaningless, and essentially a bug. So in the end, it turned out not to be a major issue, but it was certainly interesting, tracking it down, and a big thanks to Paul Randal for helping me get my head around it!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/8952597326392206549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/curious-case-of-phantom-last-log-backup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/8952597326392206549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/8952597326392206549'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/curious-case-of-phantom-last-log-backup.html' title='The Curious Case Of The Phantom Last Log Backup!'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-6174719777516885512</id><published>2011-04-02T13:58:00.000-07:00</published><updated>2016-01-18T03:50:41.014-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Internals"/><title type='text'>How To Query Allocation Units</title><content type='html'>&lt;iframe align=&quot;right&quot; frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=sqldowampdir-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735626243&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=2C2727&amp;amp;bg1=2C2727&amp;amp;f=ifr&quot; style=&quot;align: right; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;&quot;&gt;&lt;/iframe&gt;Following my post explaining Allocation Units &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/04/what-are-allocation-units.html&quot;&gt;see here&lt;/a&gt;&amp;nbsp;I though that I would do a quick follow-up post, demonstrating how you can interrogate these structures. There are two ways of doing this.&lt;br /&gt;
&lt;br /&gt;
The first (and documented way) is to use the catalogue view called sys.allocation units. This view will display one row per allocation unit, for every table and index. This can be joined back to sys.tables, via sys.partition, in order to retrieve the table name, as demonstrated below...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SELECT t.name, au.* FROM sys.allocation_units au&lt;br /&gt;
INNER JOIN sys.partitions p&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON au.container_id = p.partition_id &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;INNER JOIN sys.tables t&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ON p.object_id = t.object_id&lt;br /&gt;
ORDER BY t.name&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
...A portion of the output (run against AdaventureWorks2008) is detailed below...&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/AVvXsEjSsqmLPLePhWQZhiU0d7ZQgzmEz528fq6eqzp3w3wqKA5oZXGXYFweuvDRd_v8RgfxADZWBoHzoh5ZZTWCExaCH0_Y_9Mohta-pqWpH9ts8vEsfyAFeK6N2svhIhQYUJVZSDpKYGGOoCI/s1600/sequence+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; r6=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSsqmLPLePhWQZhiU0d7ZQgzmEz528fq6eqzp3w3wqKA5oZXGXYFweuvDRd_v8RgfxADZWBoHzoh5ZZTWCExaCH0_Y_9Mohta-pqWpH9ts8vEsfyAFeK6N2svhIhQYUJVZSDpKYGGOoCI/s640/sequence+1.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;...This query is interesting, and shows you how large each of the allocation units is, in terms of pages. What is even more interesting, however, is the undocumented way to interrogate allocation units. This is with the use of sys.system_internals_allocation_units. Let re-run the last query, using this catalogue view...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SELECT t.name, au.* FROM sys.system_internals_allocation_units au&lt;br /&gt;
INNER JOIN sys.partitions p&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ON au.container_id = p.partition_id &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;INNER JOIN sys.tables t&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;ON p.object_id = t.object_id&lt;br /&gt;
ORDER BY t.name&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
...Lets have a look at the results of this query...&lt;br /&gt;
&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/AVvXsEjNX69zFClmo2DkijtBkLaSgtsP3jDaSbSAzIbcV7Lf3h2Yb1EScJYQ158BqQNZ-WCg-tweXnpRLzF_1eggiEXfBiqRAJpeZdZYX0abaycPyyhWCuj530rXdyHS8tvv0hnd3RwxC0dS-p8/s1600/sequence+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; r6=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNX69zFClmo2DkijtBkLaSgtsP3jDaSbSAzIbcV7Lf3h2Yb1EScJYQ158BqQNZ-WCg-tweXnpRLzF_1eggiEXfBiqRAJpeZdZYX0abaycPyyhWCuj530rXdyHS8tvv0hnd3RwxC0dS-p8/s640/sequence+1.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
...The results of this query are even more interesting. Here, alongside the page counts, we can also see the location of the first IAM Page in the IAM chain, the indexe&#39;s root page, and the first page of the index. We can crack these results by using the sys.fn_physloc_formatter() function, as below...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SELECT&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;t.name, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;sys.fn_PhysLocFormatter(au.first_page) AS &#39;First Page&#39;, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;sys.fn_PhysLocFormatter(au.root_page) AS &#39;Root Page&#39;, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;sys.fn_PhysLocFormatter(au.first_iam_page) AS &#39;First IAM Page&#39;&lt;br /&gt;
FROM sys.system_internals_allocation_units au&lt;br /&gt;
INNER JOIN sys.partitions p&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ON au.container_id = p.partition_id &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;INNER JOIN sys.tables t&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;ON p.object_id = t.object_id&lt;br /&gt;
ORDER BY t.name&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
...The results are shown below...&lt;br /&gt;
&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/AVvXsEj-aMPlqrL_cSlUcCFgVpWagm3MIshCxI6eVQBAEIsUP4w8YuwPcF_06OLZ4sjYvypS5uoYbjjndiBhmINQnyDdx-mpYXmi6ecF0opGNxZdYraufZak9Yo_hywoIp45PVV4YTMOjaKszKQ/s1600/sequence+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; r6=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-aMPlqrL_cSlUcCFgVpWagm3MIshCxI6eVQBAEIsUP4w8YuwPcF_06OLZ4sjYvypS5uoYbjjndiBhmINQnyDdx-mpYXmi6ecF0opGNxZdYraufZak9Yo_hywoIp45PVV4YTMOjaKszKQ/s640/sequence+1.png&quot; width=&quot;620&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
...Pretty cool hey? Be warned, however, that the sys.system_internals_allocation_units catalogue view is both &lt;strong&gt;undocumented&lt;/strong&gt; and &lt;strong&gt;unsupported!&lt;/strong&gt; This means that I can not vouch that the page locations it gives you will always be accurate. It is, however, a useful and interesting starting point.&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/6174719777516885512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/how-to-query-allocation-units.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/6174719777516885512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/6174719777516885512'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/how-to-query-allocation-units.html' title='How To Query Allocation Units'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSsqmLPLePhWQZhiU0d7ZQgzmEz528fq6eqzp3w3wqKA5oZXGXYFweuvDRd_v8RgfxADZWBoHzoh5ZZTWCExaCH0_Y_9Mohta-pqWpH9ts8vEsfyAFeK6N2svhIhQYUJVZSDpKYGGOoCI/s72-c/sequence+1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-2100085176940703960</id><published>2011-04-02T13:20:00.000-07:00</published><updated>2011-04-02T13:20:21.029-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Internals"/><category scheme="http://www.blogger.com/atom/ns#" term="IO"/><title type='text'>What Are Allocation Units?</title><content type='html'>&lt;span&gt;&lt;iframe align=&quot;right&quot; frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=sqldowampdir-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735626243&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=2C2727&amp;amp;bg1=2C2727&amp;amp;f=ifr&quot; style=&quot;align: right; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;&quot;&gt;&lt;/iframe&gt;&lt;/span&gt;I found out this week that a couple of my colleagues were unfamiliar with Allocation Units, so I thought I would knock-up a quick post explaining what they were, and how you can use them to optimize performance. So first off - what are they?&lt;br /&gt;
&lt;br /&gt;
Well, traditionally, SQL Server has had a fixed limit of 8060-Bytes for a row and 8000-Bytes for a column, as a single row can not span more than one page. So, in more recent versions of SQL Server, it has been possible to push some of this data off-row, in order to let developers overcome this fixed limitation.&lt;br /&gt;
&lt;br /&gt;
So now, every index, including the clustered index, or heap can have it&#39;s data split across multiple allocation units. There are 3 types of allocation unit. The first is for your standard data, and this is called the IN_ROW_DATA Allocation Unit. This is the allocation unit that will hold the majority of your data, in most cases. The second Allocation Unit is know as the LOB_DATA allocation unit. This is used to store the older type LOBs (Large Object Blocks) such as Text, NText and Image. The final Allocation Unit, which is the most recent addition, is the ROW_OVERFLOW_DATA Allocation Unit. Also know as the SLOB (Small-LOB) Allocation Unit, this is used to store newer Large Objects, such as Varchar, NVarchar, SQLVariant (although this should be avoided!) and the .NET based data-types, such as Geospatial data-types.&lt;br /&gt;
&lt;br /&gt;
So, are there three allocation units per table? Oh no! There is a lot more than that! Every index can be partitioned, with a maximum of 1000 partitions, and in SQL Server 2008, you can have up to 1000, indexes, and the Allocation Units propagate down to the partition level, so it is actually possible to have 3 Million Allocation Units. In SQL Server 2005, the limit is 750,000 Allocation Units, because you are limited to 250 indexes per-table.&lt;br /&gt;
&lt;br /&gt;
By default, LOBs (Text, NText and Image) are stored out of row. You can move them in row, by changing the value of &#39;Text In Row&#39; by using sp_tableoption. Obviously, this will only bring in LOBs that will physically fit on the page. (i.e. They still can not be more than 8000-Bytes each, and 8060-Bytes in total), and you can also specify the maximum size for values to bring in-row. If you do not set this limit, the default is 256-Bytes.&lt;br /&gt;
&lt;br /&gt;
By Default, SLOBs are stored in-row (providing they will fit in the row, using the same calculations as above) but you can push them off-row by setting the &#39;Large Value Types Out Of Row&#39; option using sp_tableoption. Unlike the &#39;Text In Row&#39; option, it is not possible to specify a custom size limit. Either all rows that will fit are stored in-row, or all values are stored out of row. The size limit is 8000-Bytes, and this can not be changed.&lt;br /&gt;
&lt;br /&gt;
So the next question, is when should you push data off-row? Well, before we tackle that question, we need to think about how much overhead is caused by pushing data off-row, and this calculation is fairly simple. If LOBs are stored off row, a 16-Byte pointer is stored in the row. If SLOBs are pushed off-row, then a 24-Byte pointer is stored in-row. This can get slightly confusing however, because if you specify the (MAX) operator for a Varchar or NVarchar, then SQL treats it as a LOB, rather than a SLOB, and only requires a 16-Byte pointer.&lt;br /&gt;
&lt;br /&gt;
So the first, and most obvious considerations are (from an SLOB perspective) are 1) Are the majority of SLOBs less than 24-Bytes? If so, there would be no benefit in pushing them off-row. In fact, it would be detrimental. 2) Are the SLOBs more than 8000-Bytes? If so, you have no choice, but to store them off row. 3) Do your SLOBs add-up to more than 8060-Bytes? If so, again, you have no choice, they must be off-row.&lt;br /&gt;
&lt;br /&gt;
But what about the cases in the middle? What about if your SLOBs are all between 24 and 8000-Bytes, and together, they all fit within the 8060-Byte limit? How should you store them? Well, it depends on how you are using your data. If these SLOBs are going to be frequently queried, then you should store them in-row. If you do not, then you are increasing IO, and also forcing that IO to be random, as opposed to sequential, and random IO is not your friend!&lt;br /&gt;
&lt;br /&gt;
If on the other hand, the SLOBs are essentially just a data store, and you are only querying them infrequently, but the other columns in the table are being queried, then you should store the SLOBs off-row. This is because you will be able to fit more rows on a page, and this give you two big advantages. Firstly, queries that need to read this table will have to read less pages (because there will be less pages to read). And the second reason is simply that you will use less memory. If you read less pages, then less pages will be read into the Buffer Cache, and memory pressure will be reduced.</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/2100085176940703960/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/what-are-allocation-units.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/2100085176940703960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/2100085176940703960'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/04/what-are-allocation-units.html' title='What Are Allocation Units?'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-812740579434080868</id><published>2011-03-29T15:31:00.000-07:00</published><updated>2016-01-18T03:50:53.135-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Development"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><title type='text'>The Five Horesmen Of The SQL Server Appocolypse!</title><content type='html'>&lt;iframe align=&quot;right&quot; frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=sqldowampdir-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735626243&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=2C2727&amp;amp;bg1=2C2727&amp;amp;f=ifr&quot; style=&quot;align: right; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;&quot;&gt;&lt;/iframe&gt;Ok, so it should be four horsemen, but there was a two-way tie for fourth place. What can I say?&lt;br /&gt;
&lt;br /&gt;
Thank you all from you votes from the What is the WORST Performing Feature Of SQL Server Poll (&lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/03/what-is-worst-feature-of-sql-server.html&quot;&gt;see this post&lt;/a&gt;)&lt;br /&gt;
You can see the results and percentages in a nice little chart at &lt;a href=&quot;http://appv3.sgizmo.com/reportsview/?key=129207-589953-3ab548e8a93806ae3ccd95468dc83c87&quot;&gt;this link&lt;/a&gt;, and they are certainly interesting, so lets look at the winners in a bit more detail...&lt;br /&gt;
&lt;br /&gt;
The clear winner is Auto shrink / Scheduled shrink. But why is this so bad? Well basically it kills performance, both during the shrink operation, and worse still, after the operation has finished. When you shrink a file, starting at the end of the file, and moving backwards, it takes each page, and moves it to the earliest available space within the file. &lt;br /&gt;
&lt;br /&gt;
This is a resource intensive operation, and can cause performance issues whilst it is running, but also causes your indexes to become highly fragmented. I have already blogged about this in detail, so I won&#39;t repeat myself too much here, but please check out &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/01/why-not-to-shrink-database.html&quot;&gt;this post&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Next&amp;nbsp;in the ranking, is Autogrow logs by 1MB . Why is this so bad? Well, once again, there is a two-fold problem. Firstly, if you log is coming under space pressure, and therefore needing to grow, then it can cause huge performance problems, as it needs to grow the Log file (in some circumstances) for almost every transaction. Remember, depending on the action you are performing, SQL may need to record before and after images of the data.&amp;nbsp;I have also experienced issues in the past, where during large operations, your database suddenly ends up in Recovery, because it has not been able to keep up with the number of log grows required, and eventually resulted in the log becoming corrupt, resulting (in my case - the DB was nearly 1TB) in over an hour of downtime, and of course the transaction being rolled-back. See &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/02/optimizing-you-log-file.html&quot;&gt;this post&lt;/a&gt;&amp;nbsp;for some tips on Log File Optimization.&lt;br /&gt;
&lt;br /&gt;
The other issue is Log File Fragmentation. Log Fragmentation? What on earth is that? Well, basically if you grow your log file in tiny chunks, then you end up with a massive amount of VLFs (or Virtual Log Files). On the VLDB I mentioned above, the client ended up with over 2000. The rule of thumb recommendation, is not to have more than 50! See &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/01/how-many-virtual-log-files-do-i-have.html&quot;&gt;this post&lt;/a&gt;&amp;nbsp;for more info.&lt;br /&gt;
&lt;br /&gt;
Very close behind, in 3rd place, came Functions in Select list. Why not put a function in a SELECT list? That is what they are there for isn&#39;t it? No! No, no, no, no, no, no, no! NO! :)&amp;nbsp;If you put a function in a SELECT list, it needs to be evaluated&amp;nbsp;separately, for every single row of the query, which is causing a &quot;cursor like&quot; effect, and often can not be included in the same execution plan.&amp;nbsp;Lets have a look at an example, and how we could perform the task better...&lt;br /&gt;
&lt;br /&gt;
Using the AdventureWorks2008DW database, I have created the following example, which is a reproduction of one of the worst SQL implementations I have seen. (The code has been changed to protect the guilty!) :)&lt;br /&gt;
&lt;br /&gt;
The first thing I am going to do, is create some &quot;dirty data&quot; in the FactResellerSales table, to demonstrate why the code existed, with the following script...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; UPDATE [AdventureWorksDW2008R2].[dbo].[FactResellerSales]&lt;br /&gt;
&amp;nbsp; SET OrderQuantity = 0&lt;br /&gt;
&amp;nbsp; WHERE ProductKey = 351&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; UPDATE [AdventureWorksDW2008R2].[dbo].[FactResellerSales]&lt;br /&gt;
&amp;nbsp; SET UnitPrice = 0&lt;br /&gt;
&amp;nbsp; WHERE ProductKey = 223&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
...Now to create the Function, which I will call SaftyDiv, and will basically stop a divide by 0 error occuring...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;CREATE FUNCTION dbo.SaftyDiv(@FirstNumber DECIMAL, @SecondNumber DECIMAL)&lt;br /&gt;
RETURNS DECIMAL&lt;br /&gt;
AS&lt;br /&gt;
BEGIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;DECLARE @ReturnValue DECIMAL&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF (@FirstNumber = 0)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;BEGIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;SET @ReturnValue = 0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;END&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ELSE IF (@SecondNumber = 0)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;BEGIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;SET @ReturnValue = 0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;END&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ELSE &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;BEGIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;SET @ReturnValue = @FirstNumber / @SecondNumber&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;END&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;RETURN @ReturnValue&lt;br /&gt;
END&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
...So, there are so many things wrong about this function, I will not patronise you, or drive myself insane by listing them all, but lets see how it performs when we use it to select values from the table...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SELECT &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [SalesTerritoryKey]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[SalesOrderNumber]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[SalesOrderLineNumber]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , [dbo].[SaftyDiv] ([OrderQuantity], [UnitPrice])&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; FROM [AdventureWorksDW2008R2].[dbo].[FactResellerSales]&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;SQL Server Execution Times:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; CPU time = 438 ms,&amp;nbsp; elapsed time = 1559 ms.&lt;br /&gt;
&lt;br /&gt;
...If you look at the Execution plan for this, it looks very clean, but that is in fact, because SQL was unable to include the function in the same plan, and actually had to create a second plan for it!&lt;br /&gt;
&lt;br /&gt;
So lets see what performance we get, if we tear down the buffer cache, and then rewrite this query to use a CASE statement in the Select list. To be honest, there are more elegant ways of doing it than this, but it&#39;s getting late, and this demonstrates the point...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SELECT &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [SalesTerritoryKey]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[SalesOrderNumber]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[SalesOrderLineNumber]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , CASE WHEN ([OrderQuantity] = 0 OR [UnitPrice] = 0) THEN (SELECT 0)&amp;nbsp; ELSE (SELECT [OrderQuantity] / [UnitPrice] ) END&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;
&amp;nbsp; FROM [AdventureWorksDW2008R2].[dbo].[FactResellerSales]&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;SQL Server Execution Times:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; CPU time = 94 ms,&amp;nbsp; elapsed time = 1177 ms.&lt;br /&gt;
&lt;br /&gt;
...So you can see, we got a 78.5% improvement in processor time (because it only needed to compile 1 plan, instead of 2) and we also got a 24.5% improvement in execution time. Remember, in this example, we are only dealing with aprox. 65,000 rows. Imagine if we started scaling that up to millions of rows! &lt;br /&gt;
&lt;br /&gt;
Tied for fourth place, were Encrypt all data with cell level encryption and Cursors. Now I must be honest, this was a surprise for me, I though that cursors would be right up there with Auto/Scheduled shrink. Why did I think that? Well, they are the bain of my life! With no disparity meant what so ever to .NET developers, you can always tell when somebody who is experienced in writing .NET code, but less so in SQL, has been writing SQL code. That is because they love cursors! And it makes perfect sense, in .NET languages, looping is often the best way to achieve your goals, but T-SQL is a SET-Based language, meaning it is optimized for performing an operation on multiple rows at the same time, as opposed looping over a set of rows, which is exactly what a Cursor does.&lt;br /&gt;
&lt;br /&gt;
There is a place is T-SQL for the use of Cursors, but these days, it is a very small, limited place, and basically only shows itself in situations where you need to iterate over a series of DDL objects, such as looping over indexes in a dynamic rebuild scenario.&lt;br /&gt;
&lt;br /&gt;
For almost all other purposes, we have a better way of doing things. For example, if we need to produce a cross-tabulated query, then we have the Pivot and UnPivot operators. If we need to implement recursive logic, then we have Recursive CTEs. For concatenating rows into a string, or vice versa, we have tricks we can use with XML (see &lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/03/denormalizing-column-into-string.html&quot;&gt;this post&lt;/a&gt;&amp;nbsp;for an example), and for very complex logic, or string manipulation, we have CLR integration.&lt;br /&gt;
&lt;br /&gt;
Lets look at an example of using a simple Cursor, versus a simple&amp;nbsp;SET-Based solution&amp;nbsp;to perform the same task, and see how they perform...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;CREATE TABLE #Sales&lt;br /&gt;
(&lt;br /&gt;
SalesAmount DECIMAL,&lt;br /&gt;
RunningTotal DECIMAL&lt;br /&gt;
)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;DECLARE @SalesAmount DECIMAL,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @RunningTotal DECIMAL&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SET @RunningTotal = 0&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;DECLARE myCursor CURSOR&lt;br /&gt;
FOR&lt;br /&gt;
SELECT SalesAmount&lt;br /&gt;
FROM FactResellerSales&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;OPEN myCursor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;FETCH NEXT FROM myCursor INTO @SalesAmount&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;
&amp;nbsp;BEGIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;SET @RunningTotal = @RunningTotal + @SalesAmount&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; INSERT #Sales VALUES (@SalesAmount,@RunningTotal)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;FETCH NEXT FROM myCursor INTO @SalesAmount&lt;br /&gt;
&amp;nbsp;END&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;CLOSE myCursor&lt;br /&gt;
DEALLOCATE myCursor&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;SELECT * FROM #Sales &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot;;&quot;&gt;ORDER BY RunningTotal&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
...To be honest, I don&#39;t know how long this would take to complete, because I got bored of watching it run after about 19 minutes, (remember there are only 65,000 rows in this table)&amp;nbsp;and killed it, so I could run my SET-Based version!&lt;br /&gt;
&lt;br /&gt;
So, how long did the SET-Based version take? Drumb roll...&lt;br /&gt;
&lt;br /&gt;
SELECT a.SalesAmount,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(b.SalesAmount) AS RunningTotal&lt;br /&gt;
FROM FactResellerSales a&lt;br /&gt;
INNER JOIN FactResellerSales b&lt;br /&gt;
ON (a.SalesOrderNumber = b.SalesOrderNumber &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AND a.SalesOrderLineNumber = b.SalesOrderLineNumber) &lt;br /&gt;
GROUP BY a.SalesAmount&lt;br /&gt;
ORDER BY RunningTotal&lt;br /&gt;
&lt;br /&gt;
...Less than 1 Second! I rest my case! :)&lt;br /&gt;
&lt;br /&gt;
So finally, what is wrong with using cell-level encryption? Well nothing, if used in moderation, and it is often a necessary evil, in order to meet regulatory requirements, but if you over-indulge, then you have a problem.&lt;br /&gt;
&lt;br /&gt;
If you need to encrypt a CreditCardNumber column to meet a regulatory requirement, then this is fine. Use a symmetric key, and avoid encrypting that key with an asymmetric key, and that with a certificate, and so on! But do not go right on ahead and encrypt the entire table, despite there being no requirement to do so, other than a manager &quot;thinks it might be a good idea&quot;. As a technical person, it is your responsibility to point out the limitations of technology to the business, so if you, as I have, had a Director telling you that they want the salaries encrypted, to avoid the slightest risk that somebody might find out what a disgustingly large bonus they get, the correct answer is something along the lines of my standard reply... &quot;Yes Sir, certainly, you are the customer, and if that&#39;s what you want, then I can make it happen. However, please be warned that depending of the encryption algorithms used, then this can cause a performance degradation of up to 45-50% when accessing that data, and can cause a data-bloat of up to 4000%!&quot; That is normally enough to make people see it your way! ;-)&lt;br /&gt;
&lt;br /&gt;
I hope you find these results as interesting as I did.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/812740579434080868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/03/five-horesmen-of-sql-server-appocolypse.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/812740579434080868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/812740579434080868'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/03/five-horesmen-of-sql-server-appocolypse.html' title='The Five Horesmen Of The SQL Server Appocolypse!'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-7982316418236221156</id><published>2011-03-20T16:30:00.000-07:00</published><updated>2016-01-18T03:51:36.347-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Administration"/><category scheme="http://www.blogger.com/atom/ns#" term="Development"/><title type='text'>What Is The WORST Feature Of SQL Server?</title><content type='html'>I am planning a post on &quot;How To Kill Your SQL Server Without Even Trying!&quot; and I would like too know what you think the worst features of SQL Server are (From a PERFORMANCE perspective ONLY!) I will do another post on worst practices (from a non-performance perspective) at&amp;nbsp;a later date. If your favourite option is not listed, leave a comment.&lt;br /&gt;
&lt;br /&gt;
Once I have your votes, I will include the most popular answers in a post, with examples.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
document.write(&quot;&lt;scr&quot;+&quot;ipt type=\&quot;text/javascript\&quot; src=\&quot;http://www.surveygizmo.com/s3/polljs/496538-ZQVZ8RVTB8W025IISDRPC6I1S1KLFU/?cookie=&quot;+document.cookie.match(/sg-response-496538/gi)+&quot;\&quot;&gt;&lt;/scr&quot;+&quot;ipt&gt;&quot;);
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/7982316418236221156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/03/what-is-worst-feature-of-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7982316418236221156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/7982316418236221156'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/03/what-is-worst-feature-of-sql-server.html' title='What Is The WORST Feature Of SQL Server?'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2672880126319793008.post-929255971206488760</id><published>2011-03-20T11:29:00.000-07:00</published><updated>2016-01-18T03:51:58.855-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Denali"/><category scheme="http://www.blogger.com/atom/ns#" term="Development"/><category scheme="http://www.blogger.com/atom/ns#" term="SSIS"/><title type='text'>Sexy SSIS In Denali - Usability Enhancements</title><content type='html'>&lt;iframe align=&quot;right&quot; frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=sqldowampdir-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470525762&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=2C2727&amp;amp;bg1=2C2727&amp;amp;f=ifr&quot; style=&quot;align: right; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;&quot;&gt;&lt;/iframe&gt;Following the success of my last post on SSIS in Denali&amp;nbsp;&lt;a href=&quot;http://sqlserverdownanddirty.blogspot.com/2011/02/ssis-in-denali-sexy-but-substance.html&quot;&gt;see here&lt;/a&gt; I have been wanting to do a post for some time, giving an overview of some of the nice new usability enhancements for Developers. Unfortunately, it is predominately visual, so I have been putting it off, as really it requires a webcast, and 1) I hate the sound of my own voice! 2) I do not have any professional screen capture software. Today, however, I bit the bullet and recorded a short piece, that gives an overview of some of my favourite new features for developers. Most of them seem like small changes, but together, they make the product much easier to use.&lt;br /&gt;
&lt;br /&gt;
I hope you enjoy it, but please bare the previous two caveats in mind!!! ;-)&lt;br /&gt;
&lt;br /&gt;
If you enjoy this, and would like to see more webcasts, then please leave a comment to let me know. It&#39;s always good to know how to spend my blogging time!&lt;br /&gt;
&lt;br /&gt;
&lt;object height=&quot;344&quot; width=&quot;425&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/MhI4qVCsLqY?hl=en&amp;fs=1&quot;&gt;&lt;/param&gt;
&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;
&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;
&lt;embed src=&quot;http://www.youtube.com/v/MhI4qVCsLqY?hl=en&amp;fs=1&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;344&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;
&lt;br /&gt;
Find my book, Pro SQL Server Administration on Amazon -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/gp/product/1484207114/ref=s9_simh_gw_g14_i1_r?pf_rd_m=ATVPDKIKX0DER&amp;amp;pf_rd_s=desktop-1&amp;amp;pf_rd_r=0210ZGQQ9H4AK0C909CP&amp;amp;pf_rd_t=36701&amp;amp;pf_rd_p=2079475242&amp;amp;pf_rd_i=desktop&quot;&gt;America&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Pro-Server-Administration-Peter-Carter/dp/1484207114/ref=sr_1_1?ie=UTF8&amp;amp;qid=1453117692&amp;amp;sr=8-1&amp;amp;keywords=pro+sql+server+administration&quot;&gt;United Kingdom&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverdownanddirty.blogspot.com/feeds/929255971206488760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/03/sexy-ssis-in-denali-usability.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/929255971206488760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2672880126319793008/posts/default/929255971206488760'/><link rel='alternate' type='text/html' href='http://sqlserverdownanddirty.blogspot.com/2011/03/sexy-ssis-in-denali-usability.html' title='Sexy SSIS In Denali - Usability Enhancements'/><author><name>Peter Carter</name><uri>http://www.blogger.com/profile/12803330239861262917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='13' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSG8KtR5rbojEXyoSOOke2hrTnKn7KSsr_UegEkVZ7O1-_feWQt-VxOGXJrHribotJZ29t_qDtCbHjDsk4AlD_Kh5KPNAkFci0HkIuE3XJRw5R3J2FjkWYrU59zyQCf0k/s220/MCC11_Logo_Horizontal_Full-color.jpg'/></author><thr:total>0</thr:total></entry></feed>