<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>UK Data Platform Team Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/ukdataplatform/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/feed.xml</link>
    <description>Database, BI, Big Data and Advanced Analytics Solutions</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:33:31 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>DfE and Microsoft bring Open Data to life with Power BI</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/dfe-and-microsoft-bring-open-data-to-life-with-power-bi</link>
      <pubDate>Thu, 22 Feb 2018 09:23:34 GMT</pubDate>
      <dc:creator><![CDATA[Nicholas Revell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=1735</guid>
      <description><![CDATA[Microsoft and the Department for Education (DfE) have recently collaborated to showcase how open...]]></description>
      <content:encoded><![CDATA[Microsoft and the Department for Education (DfE) have recently collaborated to showcase how open data published by the UK government can be modelled and visualised with <a href="https://powerbi.microsoft.com/en-us/">Power BI</a> to bring their data to life and make it more engaging.

<strong>School Workforce Census
</strong>

Since 2010, the DfE has published their annual <a href="https://www.gov.uk/government/collections/statistics-school-workforce">School Workforce Census</a> data. This includes statistics on the number and characteristics of teachers, teaching assistants and other non-classroom-based school support staff in all schools in England. The data is published as part of their <a href="https://www.gov.uk/government/publications/department-for-education-open-data-strategy-june-2012">Open Data Strategy</a> and includes a copy of the raw data as spreadsheets in ODS or Microsoft Excel format. This is accompanied with a static PDF report, prepared by the DfE's statisticians, that summarises and describes the key findings.

To understand why we undertook this project and the benefits we wanted to achieve, let's briefly consider the current state of Open Government Data in the UK.

<strong>What is Open Government Data?
</strong>

The UK government is a strong advocate and practitioner of making public sector information available to the public as open data. This means that it is: accessible to all at no more than the cost of reproduction; available in a digital, machine readable format; and free of restriction on its use or redistribution (under the <a href="http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/">Open Government Licence</a> terms).

A key driver for publishing this data is transparency. This includes making data available to allow members of the public to make informed choices about public services, holding central and local government accountable for spending and outcomes, and enabling the private sector to develop innovative new services.

In their 2012 <a href="https://www.gov.uk/government/publications/open-data-white-paper-unleashing-the-potential">Open Data Whitepaper</a>, The government "committed to making open data an effective engine of economic growth, social wellbeing, political accountability and public service improvement". To date, they have published over 40,000 datasets on the <a href="https://data.gov.uk/">Data.Gov.UK</a> site, adopted the principles of the <a href="https://opendatacharter.net/">Open Data Charter</a>, and the UK is now ranked first in the world by <a href="http://opendatabarometer.org/?_year=2016&amp;indicator=ODB">The Open Data Barometer</a> for readiness, implementation and impact, and 2<sup>nd</sup> in the <a href="https://index.okfn.org/place/">Global Open Data Index</a>.

<strong>Who uses Open Government Data?
</strong>

The government provides statistics on the number of views and downloads for published <a href="https://data.gov.uk/data/site-usage/dataset">datasets</a> and views for the <a href="https://data.gov.uk/data/site-usage/publisher">publishers</a> of that data. This provides us with some insights, but it cannot tell us anything about the profiles of the persons or organisations accessing the data or what they did with it.

The government's open data principles focus on the quality, consistency, availability and open access of data. Open data should be in a re-usable format, which means it is structured and stored in a machine-readable form based on open standards. This is typically one or more CSV files depending on the volume of the data, which restricts its usage to those with the tools and skills to analyse the data. Alternatively, it is made available through Applications Programming Interfaces (APIs). It is reasonable to assume, therefore, that the primary users are predominately government departments themselves, researchers, journalists, commercial organisations, or software developers.

Most individuals and organisations are dependent on the private sector to develop services and applications on top of open data to make it easy to use and relevant for their needs. There is a growing industry of organisations and start-ups building these solutions and the government will actively promote apps that utilise open data on its <a href="https://data.gov.uk/apps">open data portal</a>. Transport for London is a great example of the <a href="https://tfl.gov.uk/info-for/media/press-releases/2017/october/tfl-s-free-open-data-boosts-london-s-economy">impact</a> that open data can have, while also recognising that this success has been built on a determined effort over 10 years.

<strong>What were the objectives of this project?</strong>

In the words of Isi Avbulimen, Statistical Officer at the DfE, who worked on the project…

<em>"The School Workforce Power BI dashboard is a joint project between Teachers Analysis Division at the Department for Education and Microsoft. It is an interactive dashboard that will allow users to visualise National, Regional and LA Level data in a colourful, interactive, and graphic form utilising a user-friendly format.
</em>

<em>The dashboard is based entirely on published data from the School Workforce Census (SWC). The data is currently published within a large, complex non-machine readable Excel file comprising of over 20,000 rows, making the data largely inaccessible to the general public who do not have expertise in data manipulation. This dashboard will allow users to pull out the information they are interested in and perform their own analysis.
</em>

<em>The dashboard will allow users to examine time series data for a range of different measures at the click of a button, e.g. users can easily examine how the headcount of teachers within the schools of York has varied over time."
</em>

<strong>How did we prepare the data for analysis?
</strong>

We performed several steps in Power BI to get the data into the correct shape before we created the visualisations. These included loading and consolidating multiple year files into single tables, joining it with additional school data from <a href="https://www.gov.uk/guidance/get-information-about-schools">'Get Information About Schools'</a>, conforming the data to ensure consistency, converting the flat files back into a data model with dimension and fact tables, and adding some calculated measures and shape map files.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/022118_1328_DfEandMicro1.png" />

<em>Screenshot of one of the source files downloaded from Data.Gov.UK
</em>

We also scaled back the scope of the project. A decision was taken to exclude all data for 2010 because there were too many structural differences with other years. We also removed the school level data because it is subject to data suppression to prevent the identification of individuals. This meant that school level aggregations could be slightly different from local authority level aggregations and might lead to confusion. An extension of the project could be to republish this data separately.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/022118_1328_DfEandMicro2.png" />

<em>Screenshot of one of the Power BI report pages
</em>

<strong>What lessons did we learn?
</strong>

The opportunity to analyse trends and changes over time are key insights that would not have been possible without going through the process of consolidating multiple files.

Combining data from multiple sources (e.g. Get Information About Schools) would not have been practical without transforming the data into a related data model. Conversely, building data models provides the opportunity to combine data sources from multiple public sector bodies, a key objective of the <a href="https://www.gov.uk/government/publications/government-transformation-strategy-2017-to-2020/government-transformation-strategy-better-use-of-data">Government Transformation Strategy</a>.

The latest UK assessment by the <a href="https://www.europeandataportal.eu/sites/default/files/country-factsheet_united-kingdom_2017.pdf">European Data Portal</a> identified issues with users' awareness of open data and understanding the value of these datasets. This project took a single dataset and reimagined how it could have been presented (alongside the open data) to lower the barriers to its use.

There are real opportunities to make open data easier to find, access and use. These include: predesigned reports that allow people to get started immediately and interactively query the data; agile tools that empower analysts to explore the data and build their own reports; and natural language interfaces and AI-powered agents that will query the data on your behalf.

The latest generation of self-service visualisation and analytics tools, such as Power BI, will provide all these capabilities. For many requirements this will be a more cost-effective and viable option than directly analysing the open data files or developing an application to do it.

<strong>Finally…
</strong>

<a href="https://msit.powerbi.com/view?r=eyJrIjoiMWFkYmEwMzEtYjEzZi00Nzk5LWFiNTYtNTE2NjA3NTM4Y2JhIiwidCI6IjcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0NyIsImMiOjV9"><strong>Click here to see the report</strong></a>. Try selecting a region from the map or searching for your local authority.]]></content:encoded>
    </item>
    <item>
      <title>Usability and Security – an oxymoron?</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/usability-and-security-an-oxymoron</link>
      <pubDate>Fri, 20 Jan 2017 14:18:32 GMT</pubDate>
      <dc:creator><![CDATA[Kalai Elumalai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=1685</guid>
      <description><![CDATA[by Kalai Elumalai - Data Platform Solution Architect

This article attempts to answer,...]]></description>
      <content:encoded><![CDATA[<strong>by Kalai Elumalai - Data Platform Solution Architect
</strong>
<p style="text-align: justify">This article attempts to answer,</p>

<ul>
 	<li>
<div style="text-align: justify">Why Enterprise Architects should care about usability and security controls?</div></li>
 	<li>
<div style="text-align: justify">How the latest features in SQL Server 2016 (and Azure SQL Database) can help to address those challenges?</div></li>
</ul>
<p style="text-align: justify"><span style="text-decoration: underline">Usability and Security:
</span></p>
<p style="text-align: justify">I recently attended a course (one of the best I've been to) on "People and Security" at Oxford University given by Professor Angela Sasse who has done extensive research in the field of <em>usability and security</em>. Her main research interest is the design and implementation of innovative technologies that are fit for purpose, value for money, and improve productivity and well-being of individuals and society. This course has prompted me to put into context some of the security implementations in Data Warehouse architectures to meet complex security requirements (both internal and external) from a usability perspective.</p>
<p style="text-align: justify">The <em>process</em> of building a secure system is pivotal for its effectiveness. The <em>process</em> is the methodology that is used to elicit the security needs, assess those needs, define the security policies and implement the countermeasures. While designing the countermeasures, the designers should consider that security is not the primary goal of the users and organisation. For example, a data analyst's primary goal is to extract insight from information assets. The role of security is a supporting function, that is, to protect the assets and the operations the system users perform on those assets that are part of their core business activity. [1]</p>
<p style="text-align: justify">Zurko and Simon [2] were among the first to point out that current security mechanisms create additional overhead on all stakeholders: system administrators, application developers, and end users. This overhead puts additional onus on these stakeholders with the amount of work and additional complexity involved in securing the systems and in using the systems while adhering to the security controls in place.</p>
<p style="text-align: justify">The crux of the issue is that the implementation of security methods should not put an impediment on the usability of the system, for e.g. a database administrator looking to implement a security policy should introduce security measures that are resilient enough to allow changes to security policies and also be easy to implement. The ability to technically implement a security measure and the effort required by the users to adhere to the security controls plays a crucial role in the compliance decision. [3] "<em>…The 'pain tolerance' - the amount of extra effort an individual is prepared to make for no personal gain – is what we call the Compliance Budget. The limit of the Compliance Budget is referred to as the compliance threshold; this being the point at which the individual no longer has the will to comply with official requirements.</em>"</p>
<p style="text-align: justify">Also, when you view this from a Data Protection Act perspective, the Information Commissioner's office has defined a set of data protection principles providing guidance to manage the security of the data (personal, sensitive etc.) organisations hold. <a href="https://ico.org.uk/for-organisations/guide-to-data-protection/principle-7-security/">Principle 7</a> suggests that organizations must have the right technical and physical security underpinned by information security policies and procedures. With the proposed changes to the EU Directive on Privacy and the introduction of Privacy by Design (Article 23), it is no longer only a responsibility of a siloed team or department in an organisation that needs to care about privacy. It is gaining more focus now than ever before and the report "Privacy and Data Protection by Design" [4] provides guidance to build in privacy in the lifecycle of system development and not as a bolt on. Organisations must, therefore, need to be better equipped with capabilities to effectively implement information security measures and become compliant with the regulations.</p>
<p style="text-align: justify">In this section, I'm going to discuss about how one of the security requirement was implemented in an Enterprise Data Warehouse project that I've worked on recently. To comply with the data protection act and the organisation's information security policy framework, data was classified at attribute level by different groupings such as highly sensitive, confidential, financially sensitive etc. Based on the data model, data classification and the security policy was defined during the design phase drawing guidance from the organisations information classification standards.</p>
<p style="text-align: justify">At the time of development, the chosen data platform did not have out of the box capability to protect sensitive data attributes. Examples of such data include customer sensitive attributes such as date of birth and email address; financial information such as invoice amount, debt amount, credit or debit card type etc. This sensitive information was stored in the database and as per the organisation information security and privacy policy, we wanted this information to be accessible only to specific roles on a need-to-know basis. Therefore, we wanted to mask certain attributes partially or sometimes fully based on the users role. We opted to build a bespoke solution.</p>
<p style="text-align: justify">The bespoke solution was to create views on top of the underlying tables. For example, entities whose attributes fall into multiple data classification types, will be segregated into separate views. In this way, only the data items allowed by a specific role will be able to access it. This solution met our security requirements and was implemented.</p>
<p style="text-align: justify">Before looking at the challenges of this bespoke solution, let's look at few business scenarios which will be useful for our discussion.</p>

<ul>
 	<li>
<div style="text-align: justify">The data management team in the business, which supports the customer insight team and campaign management team, wanted to run some data quality rules on the completeness/conformance of some of the attributes which are currently deemed as sensitive. For instance: from a marketing perspective, we would like to check whether a field has an email address such as <a href="mailto:abc@xyz.com">abc@xyz.com</a>. The analyst doesn't necessarily need to view the email address and all they care about is whether the column has any value.</div></li>
 	<li>
<div style="text-align: justify">The customer segmentation team may not need access to the date of birth of the customer – they only need the year of birth to understand the age band of their customers.</div></li>
</ul>
<p style="text-align: justify">Let's look at the downside of implementing such a bespoke solution.</p>

<ol>
 	<li>
<div style="text-align: justify">All or nothing: In the above examples, the end user (campaign data planner, customer insight analysts) either gets full access to the underlying data or gets no access to all.</div></li>
 	<li>
<div style="text-align: justify">It becomes very impractical to anticipate at the time of design for all combinations of attributes used by a role, especially when roles are based on the business functions. For instance: In this scenario, after few months of go-live, the Operational Insight team wanted access to some of the financial data to understand the debt position and allocate resources between customer service and credit handling, which was not anticipated during the design phase by the design team.</div></li>
 	<li>
<div style="text-align: justify">The rationale and knowledge of those database views are lost when the delivery team and business transformation team move on (either move to a different project or in case of third party system integrators scenario the resources are released to different assignments). The security logic is hidden in multitude of views and are susceptible to manual errors too.</div></li>
 	<li>
<div style="text-align: justify">When there is a change to the view to be made, you need a resource who has the knowledge of those views to make the change and DBA team to implement the change in Dev/Test/Pre-Prod and Production. Multiple teams, especially with domain knowledge, involved which means more red tape, time and cost. This will allow the end users to request for access to all data rather than going through the complex process of implementing the change in the view to gain access to the required data.</div></li>
</ol>
<p style="text-align: justify">The security controls that are difficult to change and adhering to those controls means more bureaucratic processes. This means most of the time is wasted in non-productive efforts and all of which would compete against the primary business goal taking up the compliance budget [3].</p>
<p style="text-align: justify"><strong>How does Dynamic Data Masking which is a built-in feature in SQL Server 2016 (and Azure SQL Database) help to secure sensitive data?
</strong></p>
<p style="text-align: justify">In simple terms, this feature masks the data that is returned from the DB engine. This new security programmability feature limits access to sensitive data by obfuscating query results. This feature offers:</p>

<ul>
 	<li>
<div style="text-align: justify"><span style="text-decoration: underline">Sensitive Data Protection:</span> Protects sensitive data against unauthorized access by built-in or custom masking rules. Privileged users can view the unmasked data e.g. using DDM to mask sensitive information in an HR database and only authorized users can access the unmasked data.</div></li>
 	<li>
<div style="text-align: justify"><span style="text-decoration: underline">Regulatory Compliance:</span> Enabler for applications to meet regulatory compliance needs such as PCI DSS, Sarbanes-Oxley, HIPAA and other regulations which demand protection of sensitive financial and personal data.</div></li>
 	<li>
<div style="text-align: justify"><span style="text-decoration: underline">Agility and Transparency:</span> The biggest benefit of this feature is its ease of implementation and ease of use. The data is masked on the fly and the underlying data remains intact. And it is completely transparent to the application.</div></li>
</ul>
<p style="text-align: justify"><img alt="" src="https://msdnshared.blob.core.windows.net/media/2017/01/012017_1418_Usabilityan1.png" /></p>
<p style="text-align: justify">In the example above, the <em>Email address</em> column of the <em>Employee</em> table has been masked using a simple set of T-SQL statements based on the security policy. The Data Quality analyst can access the email address column and still can perform their primary tasks without compromising on security compliance. Whilst, the privileged user "admin1", which could be used by applications such as a campaign management tool, can still access the unmasked email address and trigger email campaigns.</p>
<p style="text-align: justify">From implementation perspective, all the DBA or the security admin should do is,</p>

<ul>
 	<li>
<div style="text-align: justify">define the security policy for the sensitive attributes in the entities.</div></li>
 	<li>
<div style="text-align: justify">apply those policies in T-SQL over the sensitive columns.</div></li>
 	<li>
<div style="text-align: justify">these data masking policies will then obfuscate the sensitive data in the query results when accessed by non-privileged users.</div></li>
</ul>
<p style="text-align: justify">If I were doing the project I discussed above, I would be using SQL Server 2016 DDM. It would have not only simplified the implementation but also would have provided an effective governance with a central data masking policy and the agility required to meet the changing business data access needs.</p>
<p style="text-align: justify"><span style="text-decoration: underline">Find out more information on "how to":
</span></p>

<ul>
 	<li>
<div style="text-align: justify"><a href="https://blogs.technet.microsoft.com/dataplatforminsider/2016/01/25/use-dynamic-data-masking-to-obfuscate-your-sensitive-data/">Use Dynamic Data Masking to obfuscate your sensitive data</a></div></li>
 	<li>
<div style="text-align: justify"><a href="https://msdn.microsoft.com/en-GB/library/mt130841.aspx">Limitations and restrictions</a></div></li>
</ul>
<p style="text-align: justify"><span style="text-decoration: underline"><strong>References:
</strong></span></p>
<p style="text-align: justify">[1] Usable security. Why do we need it? How do we get it?; M. Angela Sasse and Ivan Flechais</p>
<p style="text-align: justify">[2] Mary E. Zurko and Richard T. Simon, "User-Centered Security," New Security Paradigms Workshop 1997[3] A. Beautement, M. A. Sasse &amp; M. Wonham, M. (2008).</p>
<p style="text-align: justify">[3] The Compliance Budget: Managing security behaviour in organisations. In Proceedings of the 2008 Workshop on New Security Paradigms (2008)</p>
<p style="text-align: justify">[4] Privacy and Data Protection by Design – from policy to engineering December 2014. European Union Agency for Network and Information Security</p>]]></content:encoded>
    </item>
    <item>
      <title>Using a ‘User Query Store’ for Exceptions and Timeouts</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/using-a-user-query-store-for-exceptions-and-timeouts</link>
      <pubDate>Thu, 29 Sep 2016 13:59:11 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=1666</guid>
      <description><![CDATA[by Mike Boswell – Data Platform Solution Architect.

In the previous post, I mentioned that as a...]]></description>
      <content:encoded><![CDATA[<strong>by Mike Boswell – Data Platform Solution Architect.</strong>

In the previous post, I mentioned that as a Data Solution Architect we regularly work with clients to pilot new data platforms and with SQL Server 2016 an increasing number of clients are looking to modernise those SQL Platforms.

We spoke of how you could create a 'User Query Store' to retain test results.

More recently I had to investigate queries which were timing out or had exceptions. These are usually the priority in getting the applications working before we start performance tuning. Within Query Store these are deemed to be "Aborted" or "Exceptions".

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- Exception Queries<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">rs<span style="color: gray">.<span style="color: black">runtime_stats_id<span style="color: gray">,<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">start_time<span style="color: gray">,<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">end_time<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">avg_physical_io_reads<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">rs<span style="color: gray">.<span style="color: black">avg_rowcount<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">count_executions<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">execution_type_desc<span style="color: gray">,<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_plan<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval rsi <span style="color: blue">ON<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">where<span style="color: black"> rs<span style="color: gray">.<span style="color: black">execution_type<span style="color: gray">=<span style="color: black">4
</span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">order<span style="color: black">
<span style="color: blue">by<span style="color: black"> count_executions <span style="color: blue">desc<span style="color: black">
</span></span></span></span></span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- Aborted Queries<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">rs<span style="color: gray">.<span style="color: black">runtime_stats_id<span style="color: gray">,<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">start_time<span style="color: gray">,<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">end_time<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">avg_physical_io_reads<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">rs<span style="color: gray">.<span style="color: black">avg_rowcount<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">count_executions<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">execution_type_desc<span style="color: gray">,<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_plan<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval rsi <span style="color: blue">ON<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">where<span style="color: black"> rs<span style="color: gray">.<span style="color: black">execution_type<span style="color: gray">=<span style="color: black">3
</span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">order<span style="color: black">
<span style="color: blue">by<span style="color: black"> count_executions <span style="color: blue">desc<span style="color: black">
</span></span></span></span></span></span>

The above queries will output the top queries that have exceptions or aborts along with the SHOWPLAN. As we have imported the sys.objects we are able to reference the object which contains the query. An object id of '0' points to an Ad-Hoc query.

The only challenge with these queries is that you are unable to get a full count of executions where the query has timed out. The reason is that the query could have a different runtime_stats_id and therefore has a separate entry in the <span style="background-color: white">dbo.user_query_store_runtime_stats</span>.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2016/09/092916_1359_UsingaUserQ1.png" />

Therefore, to get a total count of the number of executions, which timed out, you need to group by query_id and run the script below.

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- Exception Queries Grouped by query id.<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black">
<span style="color: fuchsia">sum<span style="color: gray">(<span style="color: black">rs<span style="color: gray">.<span style="color: black">count_executions<span style="color: gray">)<span style="color: black"> sum_of_executions<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval rsi <span style="color: blue">ON<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">where<span style="color: black"> rs<span style="color: gray">.<span style="color: black">execution_type<span style="color: gray">=<span style="color: black">4
</span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">group<span style="color: black">
<span style="color: blue">by<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">order<span style="color: black">
<span style="color: blue">by<span style="color: black">
<span style="color: fuchsia">sum<span style="color: gray">(<span style="color: black">count_executions<span style="color: gray">)<span style="color: black">
<span style="color: blue">desc<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- Aborted Queries Grouped by query id.<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black">
<span style="color: fuchsia">sum<span style="color: gray">(<span style="color: black">rs<span style="color: gray">.<span style="color: black">count_executions<span style="color: gray">)<span style="color: black"> sum_of_executions<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval rsi <span style="color: blue">ON<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">where<span style="color: black"> rs<span style="color: gray">.<span style="color: black">execution_type<span style="color: gray">=<span style="color: black">3
</span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">group<span style="color: black">
<span style="color: blue">by<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">order<span style="color: black">
<span style="color: blue">by<span style="color: black">
<span style="color: fuchsia">sum<span style="color: gray">(<span style="color: black">count_executions<span style="color: gray">)<span style="color: black">
<span style="color: blue">desc<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span>

The grouped output now allows you to see which queries you should focus on the most:

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2016/09/092916_1359_UsingaUserQ2.png" />
<h2>Conclusion</h2>
Query Store or a 'User Query Store' provides a very quick way to fault find timeouts and exceptions in your application. Previously you would have had to set-up a Profiler or Extended Events Trace to fault find. Query Store runs in the background and collects information for you, giving instant insight to your application performance.]]></content:encoded>
    </item>
    <item>
      <title>Exporting SQL Server 2016 Query Store</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/exporting-sql-server-2016-query-store</link>
      <pubDate>Tue, 06 Sep 2016 07:47:04 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=1646</guid>
      <description><![CDATA[By Mike Boswell – Data Platform Solution Architect.

As a Data Solution Architect, we regularly...]]></description>
      <content:encoded><![CDATA[<strong>By Mike Boswell – Data Platform Solution Architect.</strong>

As a Data Solution Architect, we regularly work with clients to pilot new data platforms and with SQL Server 2016 an increasing number of clients are looking to modernise their SQL Server, Oracle and DB2 Platforms.

During the piloting phase we will run performance labs and pilot new features. Now one of these new features which gives us a lot of benefit, both in these labs, and in production is the Query Store (<a href="https://msdn.microsoft.com/en-GB/library/dn817826.aspx">https://msdn.microsoft.com/en-GB/library/dn817826.aspx</a>) in SQL Server 2016.

However, there is one "query store challenge" with this in both a Dev, Test and Production environments. During Dev/Test the database is often restored after a test and we needed a way to keep the query store data for analysis. Likewise, production would like to provide feedback to development on performance enhancements.

Microsoft have yet to produce a utility which will extract query store data, into user database, and this blog explains how you can do this to gain insight into your database performance.

To achieve this, it led me down the path of having to look to export the data from Query Store, build Primary Keys and Columnstore Indexes (columnstore indexes<a href="https://msdn.microsoft.com/en-us/library/gg492088.aspx">https://msdn.microsoft.com/en-us/library/gg492088.aspx</a>).. Primary Keys, created as clustered indexes, to support point lookups and Non Clustered Columnstore Indexes to support aggregations.

Once we had this, we could back up the database and share the output with between dev and test teams now that the performance metric data is safely captured.

Note: The rest of this blog is based on the WorldWideImporters database from <a href="https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0">https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0</a>.
<h2><span style="font-size: 11pt">Setting up Query Store
</span></h2>
For details on setting up Query Store, in SQL Server 2016, please refer to "<a href="https://msdn.microsoft.com/en-us/library/dn817826.aspx">Monitoring Performance By Using the Query Store</a> and a Channel 9 vid at <a href="https://channel9.msdn.com/Shows/Data-Exposed/Query-Store-in-SQL-Server-2016">https://channel9.msdn.com/Shows/Data-Exposed/Query-Store-in-SQL-Server-2016</a>.

Once setup and you have workload running then you should start seeing data returned by running the following DMVs:
<ul>
 	<li><a href="https://msdn.microsoft.com/en-us/library/dn818155.aspx">sys.query_store_plan (Transact-SQL)</a></li>
 	<li><a href="https://msdn.microsoft.com/en-us/library/dn818156.aspx">sys.query_store_query (Transact-SQL)</a></li>
 	<li><a href="https://msdn.microsoft.com/en-us/library/dn818159.aspx">sys.query_store_query_text (Transact-SQL)</a></li>
 	<li><a href="https://msdn.microsoft.com/en-us/library/dn818158.aspx">sys.query_store_runtime_stats (Transact-SQL)</a></li>
 	<li><a href="https://msdn.microsoft.com/en-us/library/dn818147.aspx">sys.query_store_runtime_stats_interval (Transact-SQL)</a></li>
</ul>
and start using Query Store as documented.
<h2><span style="font-size: 11pt">Setting up a User Query Store
</span></h2>
We need to set up a user database to be able to pull down the data from the Query Stored and the script below:
<ul>
 	<li>Create a Database</li>
 	<li>Select from the WorldWideImporters DB (alter to your DB)</li>
 	<li>Import sys.objects table</li>
 	<li>Create Primary Keys</li>
 	<li>Create ColumnStore Indexes to support aggregation of data</li>
</ul>
<div>
<table style="border-collapse: collapse" border="0"><colgroup> <col style="width: 935px" /></colgroup>
<tbody valign="top">
<tr>
<td style="padding-left: 11px;padding-right: 11px;border: solid 0.5pt"><span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">/*<span style="color: black">
</span></span><span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">DISCLAIMER:<span style="color: black">
</span></span><span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">This code is not supported under any Microsoft standard support program or service.<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">This code and information are provided "AS IS" without warranty of any kind, either expressed or implied.<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">The entire risk arising out of the use or performance of the script and documentation remains with you. <span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">Furthermore, Microsoft or the author shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, including, without limitation, damages for loss of business profits, business interruption, loss of business information or other pecuniary loss even if it has been advised of the possibility of such damages.<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">*/<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">create<span style="color: black">
<span style="color: blue">database<span style="color: black"> [UserQueryStore]
</span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ALTER<span style="color: black">
<span style="color: blue">DATABASE<span style="color: black"> [UserQueryStore] <span style="color: blue">SET<span style="color: black">
<span style="color: blue">RECOVERY<span style="color: black">
<span style="color: blue">SIMPLE<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">USE<span style="color: black"> [UserQueryStore]
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">CREATE<span style="color: black">
<span style="color: blue">TABLE<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_sys_objects]
</span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">(<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    userobjectname <span style="color: blue">nvarchar<span style="color: gray">(<span style="color: black">128<span style="color: gray">)<span style="color: black">
<span style="color: gray">NOT<span style="color: black">
<span style="color: gray">NULL,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    userobjectid <span style="color: blue">int<span style="color: black">
<span style="color: gray">NOT<span style="color: black">
<span style="color: gray">NULL,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    userobjecttype <span style="color: blue">char<span style="color: gray">(<span style="color: black">2<span style="color: gray">)<span style="color: black">
<span style="color: gray">NOT<span style="color: black">
<span style="color: gray">NULL<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">select<span style="color: black">
<span style="color: gray">*<span style="color: black">
<span style="color: blue">into<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_plan] <span style="color: blue">from<span style="color: black"> [WideWorldImporters]<span style="color: gray">.<span style="color: black">[sys]<span style="color: gray">.<span style="color: black">[query_store_plan]<span style="color: gray">;<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">select<span style="color: black">
<span style="color: gray">*<span style="color: black">
<span style="color: blue">into<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_query] <span style="color: blue">from<span style="color: black"> [WideWorldImporters]<span style="color: gray">.<span style="color: black">[sys]<span style="color: gray">.<span style="color: black">[query_store_query]<span style="color: gray">;<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">select<span style="color: black">
<span style="color: gray">*<span style="color: black">
<span style="color: blue">into<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_query_text] <span style="color: blue">from<span style="color: black"> [WideWorldImporters]<span style="color: gray">.<span style="color: black">[sys]<span style="color: gray">.<span style="color: black">[query_store_query_text]<span style="color: gray">;<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">select<span style="color: black">
<span style="color: gray">*<span style="color: black">
<span style="color: blue">into<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_runtime_stats] <span style="color: blue">from<span style="color: black"> [WideWorldImporters]<span style="color: gray">.<span style="color: black">[sys]<span style="color: gray">.<span style="color: black">[query_store_runtime_stats]<span style="color: gray">;<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">select<span style="color: black">
<span style="color: gray">*<span style="color: black">
<span style="color: blue">into<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_runtime_stats_interval] <span style="color: blue">from<span style="color: black"> [WideWorldImporters]<span style="color: gray">.<span style="color: black">[sys]<span style="color: gray">.<span style="color: black">[query_store_runtime_stats_interval]<span style="color: gray">;<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">insert<span style="color: black">
<span style="color: blue">into<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_sys_objects]<span style="color: gray">(<span style="color: black">[userobjectname]<span style="color: gray">,<span style="color: black">[userobjectid]<span style="color: gray">,<span style="color: black">[userobjecttype]<span style="color: gray">)<span style="color: black">
<span style="color: blue">select<span style="color: black"> [name]<span style="color: gray">,<span style="color: black"> [object_id]<span style="color: gray">,<span style="color: black">[type] <span style="color: blue">from<span style="color: black"> [WideWorldImporters]<span style="color: gray">.<span style="color: black">[sys]<span style="color: gray">.<span style="color: black">[objects]<span style="color: gray">;<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">INSERT<span style="color: black">
<span style="color: blue">INTO<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_sys_objects]
</span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">
<span style="color: gray">(<span style="color: black">[userobjectname]
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">
<span style="color: gray">,<span style="color: black">[userobjectid]
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">         <span style="color: gray">,<span style="color: black">[userobjecttype]<span style="color: gray">)<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">
<span style="color: blue">VALUES<span style="color: black">
</span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">
<span style="color: gray">(<span style="color: red">'Ad-Hoc Query'<span style="color: gray">,<span style="color: black"> 0<span style="color: gray">,<span style="color: red">'AD'<span style="color: gray">)<span style="color: black">
</span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--Add Primary Keys and ColumnStore Indexes<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ALTER<span style="color: black">
<span style="color: blue">TABLE<span style="color: black"> dbo<span style="color: gray">.<span style="color: black">user_query_store_plan <span style="color: blue">ADD<span style="color: black">
<span style="color: blue">CONSTRAINT<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    PK_user_query_store_plan <span style="color: blue">PRIMARY<span style="color: black">
<span style="color: blue">KEY<span style="color: black">
<span style="color: blue">CLUSTERED<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">(<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    plan_id
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">)<span style="color: black">
<span style="color: blue">WITH<span style="color: gray">(<span style="color: black">
<span style="color: blue">STATISTICS_NORECOMPUTE<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">IGNORE_DUP_KEY<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_ROW_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_PAGE_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ALTER<span style="color: black">
<span style="color: blue">TABLE<span style="color: black"> dbo<span style="color: gray">.<span style="color: black">user_query_store_query <span style="color: blue">ADD<span style="color: black">
<span style="color: blue">CONSTRAINT<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    PK_user_query_store_query <span style="color: blue">PRIMARY<span style="color: black">
<span style="color: blue">KEY<span style="color: black">
<span style="color: blue">CLUSTERED<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">(<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    query_id
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">)<span style="color: black">
<span style="color: blue">WITH<span style="color: gray">(<span style="color: black">
<span style="color: blue">STATISTICS_NORECOMPUTE<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">IGNORE_DUP_KEY<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_ROW_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_PAGE_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ALTER<span style="color: black">
<span style="color: blue">TABLE<span style="color: black"> dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text <span style="color: blue">ADD<span style="color: black">
<span style="color: blue">CONSTRAINT<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    PK_user_query_store_query_text <span style="color: blue">PRIMARY<span style="color: black">
<span style="color: blue">KEY<span style="color: black">
<span style="color: blue">CLUSTERED<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">(<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    query_text_id
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">)<span style="color: black">
<span style="color: blue">WITH<span style="color: gray">(<span style="color: black">
<span style="color: blue">STATISTICS_NORECOMPUTE<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">IGNORE_DUP_KEY<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_ROW_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_PAGE_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ALTER<span style="color: black">
<span style="color: blue">TABLE<span style="color: black"> dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats <span style="color: blue">ADD<span style="color: black">
<span style="color: blue">CONSTRAINT<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    PK_user_query_store_runtime_stats <span style="color: blue">PRIMARY<span style="color: black">
<span style="color: blue">KEY<span style="color: black">
<span style="color: blue">CLUSTERED<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">(<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    runtime_stats_id
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">)<span style="color: black">
<span style="color: blue">WITH<span style="color: gray">(<span style="color: black">
<span style="color: blue">STATISTICS_NORECOMPUTE<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">IGNORE_DUP_KEY<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_ROW_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_PAGE_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ALTER<span style="color: black">
<span style="color: blue">TABLE<span style="color: black"> dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval <span style="color: blue">ADD<span style="color: black">
<span style="color: blue">CONSTRAINT<span style="color: black">
</span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    PK_user_query_store_runtime_stats_interval <span style="color: blue">PRIMARY<span style="color: black">
<span style="color: blue">KEY<span style="color: black">
<span style="color: blue">CLUSTERED<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">(<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    runtime_stats_interval_id
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    <span style="color: gray">)<span style="color: black">
<span style="color: blue">WITH<span style="color: gray">(<span style="color: black">
<span style="color: blue">STATISTICS_NORECOMPUTE<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">IGNORE_DUP_KEY<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_ROW_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">,<span style="color: black">
<span style="color: blue">ALLOW_PAGE_LOCKS<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">ON<span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--ColumnStores<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">CREATE<span style="color: black">
<span style="color: blue">NONCLUSTERED<span style="color: black">
<span style="color: blue">COLUMNSTORE<span style="color: black">
<span style="color: blue">INDEX<span style="color: black"> [user_query_store_plan-CS] <span style="color: blue">ON<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_plan]
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">(<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [plan_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [query_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [plan_group_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [engine_version]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [compatibility_level]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_online_index_plan]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_trivial_plan]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_parallel_plan]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_forced_plan]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_natively_compiled]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [force_failure_count]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_force_failure_reason]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_force_failure_reason_desc]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [count_compiles]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [initial_compile_start_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_compile_start_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_execution_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_compile_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_compile_duration]
</span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">)<span style="color: blue">WITH <span style="color: gray">(<span style="color: blue">DROP_EXISTING<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">COMPRESSION_DELAY<span style="color: black">
<span style="color: gray">=<span style="color: black"> 0<span style="color: gray">)<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">CREATE<span style="color: black">
<span style="color: blue">NONCLUSTERED<span style="color: black">
<span style="color: blue">COLUMNSTORE<span style="color: black">
<span style="color: blue">INDEX<span style="color: black"> [user_query_store_query_text-CS] <span style="color: blue">ON<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_query_text]
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">(<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [query_text_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_part_of_encrypted_module]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [has_restricted_text]
</span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">)<span style="color: blue">WITH <span style="color: gray">(<span style="color: blue">DROP_EXISTING<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">COMPRESSION_DELAY<span style="color: black">
<span style="color: gray">=<span style="color: black"> 0<span style="color: gray">)<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">CREATE<span style="color: black">
<span style="color: blue">NONCLUSTERED<span style="color: black">
<span style="color: blue">COLUMNSTORE<span style="color: black">
<span style="color: blue">INDEX<span style="color: black"> [user_query_store_query-cs] <span style="color: blue">ON<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_query]
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">(<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [query_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [query_text_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [context_settings_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [object_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_internal_query]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [query_parameterization_type]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [query_parameterization_type_desc]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [initial_compile_start_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_compile_start_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_execution_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_compile_batch_offset_start]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_compile_batch_offset_end]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [count_compiles]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_compile_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_compile_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_bind_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_bind_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_bind_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_bind_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_optimize_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_optimize_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_optimize_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_optimize_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_compile_memory_kb]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_compile_memory_kb]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_compile_memory_kb]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [is_clouddb_internal_query]
</span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">)<span style="color: blue">WITH <span style="color: gray">(<span style="color: blue">DROP_EXISTING<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">COMPRESSION_DELAY<span style="color: black">
<span style="color: gray">=<span style="color: black"> 0<span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">CREATE<span style="color: black">
<span style="color: blue">NONCLUSTERED<span style="color: black">
<span style="color: blue">COLUMNSTORE<span style="color: black">
<span style="color: blue">INDEX<span style="color: black"> [user_query_store_runtime_stats_interval-cs] <span style="color: blue">ON<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_runtime_stats_interval]
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">(<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [runtime_stats_interval_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [start_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [end_time]
</span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">)<span style="color: blue">WITH <span style="color: gray">(<span style="color: blue">DROP_EXISTING<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">COMPRESSION_DELAY<span style="color: black">
<span style="color: gray">=<span style="color: black"> 0<span style="color: gray">)<span style="color: black">
<span style="color: blue">ON<span style="color: black"> [PRIMARY]
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">CREATE<span style="color: black">
<span style="color: blue">NONCLUSTERED<span style="color: black">
<span style="color: blue">COLUMNSTORE<span style="color: black">
<span style="color: blue">INDEX<span style="color: black"> [user_query_store_runtime_stats-cs] <span style="color: blue">ON<span style="color: black"> [dbo]<span style="color: gray">.<span style="color: black">[user_query_store_runtime_stats]
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">(<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [runtime_stats_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [plan_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [runtime_stats_interval_id]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [execution_type]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [execution_type_desc]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [first_execution_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_execution_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [count_executions]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_duration]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_cpu_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_logical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_logical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_logical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_logical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_logical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_logical_io_writes]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_logical_io_writes]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_logical_io_writes]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_logical_io_writes]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_logical_io_writes]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_physical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_physical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_physical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_physical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_physical_io_reads]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_clr_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_clr_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_clr_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_clr_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_clr_time]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_dop]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_dop]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_dop]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_dop]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_dop]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_query_max_used_memory]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_query_max_used_memory]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_query_max_used_memory]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_query_max_used_memory]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_query_max_used_memory]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [avg_rowcount]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [last_rowcount]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [min_rowcount]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [max_rowcount]<span style="color: gray">,<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    [stdev_rowcount]
</span>

<span style="color: gray;font-family: Consolas;font-size: 9pt;background-color: white">)<span style="color: blue">WITH <span style="color: gray">(<span style="color: blue">DROP_EXISTING<span style="color: black">
<span style="color: gray">=<span style="color: black">
<span style="color: blue">OFF<span style="color: gray">,<span style="color: black">
<span style="color: blue">COMPRESSION_DELAY<span style="color: black">
<span style="color: gray">=<span style="color: black"> 0<span style="color: gray">)<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO</span></td>
</tr>
</tbody>
</table>
</div>
Once we have the data in our user database we can take the queries mentioned in "<a href="https://msdn.microsoft.com/en-us/library/dn817826.aspx">Monitoring Performance By Using the Query Store</a>" and alter them to point to our user tables. The queries include the user_sys_objects table to be able to display the name of the object that the query is part of. If the query is part of an ad-hoc query then the object name will display as ad-hoc.
<div>
<table style="border-collapse: collapse" border="0"><colgroup> <col style="width: 935px" /></colgroup>
<tbody valign="top">
<tr>
<td style="padding-left: 11px;padding-right: 11px;border: solid 0.5pt"><span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">/*<span style="color: black">
</span></span><span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">/*<span style="color: black">
</span></span><span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">DISCLAIMER:<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">This code is not supported under any Microsoft standard support program or service.<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">This code and information are provided "AS IS" without warranty of any kind, either expressed or implied.<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">The entire risk arising out of the use or performance of the script and documentation remains with you. <span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">Furthermore, Microsoft or the author shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, including, without limitation, damages for loss of business profits, business interruption, loss of business information or other pecuniary loss even if it has been advised of the possibility of such damages.<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">*/<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">USE<span style="color: black"> [UserQueryStore]
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--Last N queries that were executed on the database<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black">
<span style="color: blue">TOP<span style="color: black"> 10 qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">last_execution_time<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ORDER<span style="color: black">
<span style="color: blue">BY<span style="color: black"> rs<span style="color: gray">.<span style="color: black">last_execution_time <span style="color: blue">DESC<span style="color: black">
</span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--Count of executions for each query<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: fuchsia;font-family: Consolas;font-size: 9pt;background-color: white">SUM<span style="color: gray">(<span style="color: black">rs<span style="color: gray">.<span style="color: black">count_executions<span style="color: gray">)<span style="color: black">
<span style="color: blue">AS<span style="color: black"> total_execution_count<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GROUP<span style="color: black">
<span style="color: blue">BY<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black">so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ORDER<span style="color: black">
<span style="color: blue">BY<span style="color: black"> total_execution_count <span style="color: blue">DESC<span style="color: black">
</span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- Top N queries with longest average execution time within last hour<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black">
<span style="color: blue">TOP<span style="color: black"> 10 qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: fuchsia;font-family: Consolas;font-size: 9pt;background-color: white">getutcdate<span style="color: gray">()<span style="color: black">
<span style="color: blue">as<span style="color: black"> CurrentUTCTime<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">last_execution_time<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">avg_duration<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--WHERE rs.last_execution_time &gt; dateadd(hour, -1, getutcdate())<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ORDER<span style="color: black">
<span style="color: blue">BY<span style="color: black"> rs<span style="color: gray">.<span style="color: black">avg_duration <span style="color: blue">DESC<span style="color: black">
</span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--Top N queries that had the biggest average physical IO reads in last 24 hours, <span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--with corresponding average row count and execution count<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black">
<span style="color: blue">TOP<span style="color: black"> 10 qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">rs<span style="color: gray">.<span style="color: black">runtime_stats_id<span style="color: gray">,<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">start_time<span style="color: gray">,<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">end_time<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">avg_physical_io_reads<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">rs<span style="color: gray">.<span style="color: black">avg_rowcount<span style="color: gray">,<span style="color: black"> rs<span style="color: gray">.<span style="color: black">count_executions<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs <span style="color: blue">ON<span style="color: black"> p<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval rsi <span style="color: blue">ON<span style="color: black"> rsi<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">=<span style="color: black"> rs<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">--WHERE rsi.start_time &gt;= dateadd(hour, -24, getutcdate()) <span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">ORDER<span style="color: black">
<span style="color: blue">BY<span style="color: black"> rs<span style="color: gray">.<span style="color: black">avg_physical_io_reads <span style="color: blue">DESC<span style="color: black">
</span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">GO<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- Queries that recently regressed in performance<span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- The following query example returns all queries which execution time was <span style="color: black">
</span></span>

<span style="color: green;font-family: Consolas;font-size: 9pt;background-color: white">-- doubled in last 48 hours.<span style="color: black">
</span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">SELECT<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    qt<span style="color: gray">.<span style="color: black">query_sql_text<span style="color: gray">,<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    q<span style="color: gray">.<span style="color: black">query_id<span style="color: gray">,<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    qt<span style="color: gray">.<span style="color: black">query_text_id<span style="color: gray">,<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    p1<span style="color: gray">.<span style="color: black">plan_id <span style="color: blue">AS<span style="color: black"> plan1<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rsi1<span style="color: gray">.<span style="color: black">start_time <span style="color: blue">AS<span style="color: black"> runtime_stats_interval_1<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rs1<span style="color: gray">.<span style="color: black">runtime_stats_id <span style="color: blue">AS<span style="color: black"> runtime_stats_id_1<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rs1<span style="color: gray">.<span style="color: black">avg_duration <span style="color: blue">AS<span style="color: black"> avg_duration_1<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    p2<span style="color: gray">.<span style="color: black">plan_id <span style="color: blue">AS<span style="color: black"> plan2<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rsi2<span style="color: gray">.<span style="color: black">start_time <span style="color: blue">AS<span style="color: black"> runtime_stats_interval_2<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rs2<span style="color: gray">.<span style="color: black">runtime_stats_id <span style="color: blue">AS<span style="color: black"> runtime_stats_id_2<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rs2<span style="color: gray">.<span style="color: black">avg_duration <span style="color: blue">AS<span style="color: black"> plan2<span style="color: gray">,<span style="color: black">
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    so<span style="color: gray">.<span style="color: black">userobjectname<span style="color: gray">,<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    so<span style="color: gray">.<span style="color: black">userobjecttype
</span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">FROM<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query_text qt <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_query q <span style="color: blue">ON<span style="color: black"> qt<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_text_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p1 <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p1<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs1 <span style="color: blue">ON<span style="color: black"> p1<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs1<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval rsi1 <span style="color: blue">ON<span style="color: black"> rsi1<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">=<span style="color: black"> rs1<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_plan p2 <span style="color: blue">ON<span style="color: black"> q<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">=<span style="color: black"> p2<span style="color: gray">.<span style="color: black">query_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats rs2 <span style="color: blue">ON<span style="color: black"> p2<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">=<span style="color: black"> rs2<span style="color: gray">.<span style="color: black">plan_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_query_store_runtime_stats_interval rsi2 <span style="color: blue">ON<span style="color: black"> rsi2<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">=<span style="color: black"> rs2<span style="color: gray">.<span style="color: black">runtime_stats_interval_id <span style="color: gray">JOIN<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    dbo<span style="color: gray">.<span style="color: black">user_sys_objects so <span style="color: blue">on<span style="color: black"> so<span style="color: gray">.<span style="color: black">userobjectid <span style="color: gray">=<span style="color: black"> q<span style="color: gray">.<span style="color: fuchsia">object_id<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: blue;font-family: Consolas;font-size: 9pt;background-color: white">WHERE<span style="color: black">
</span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rsi1<span style="color: gray">.<span style="color: black">start_time <span style="color: gray">&gt;<span style="color: black">
<span style="color: fuchsia">dateadd<span style="color: gray">(<span style="color: fuchsia">hour<span style="color: gray">,<span style="color: black">
<span style="color: gray">-<span style="color: black">1000<span style="color: gray">,<span style="color: black">
<span style="color: fuchsia">getutcdate<span style="color: gray">())<span style="color: black">
<span style="color: gray">AND<span style="color: black">
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rsi2<span style="color: gray">.<span style="color: black">start_time <span style="color: gray">&gt;<span style="color: black"> rsi1<span style="color: gray">.<span style="color: black">start_time <span style="color: gray">AND<span style="color: black">
</span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt;background-color: white">    rs2<span style="color: gray">.<span style="color: black">avg_duration <span style="color: gray">&gt;<span style="color: black"> 2<span style="color: gray">*<span style="color: black">rs1<span style="color: gray">.<span style="color: black">avg_duration</span></span></span></span></span></span></span></span></span></td>
</tr>
</tbody>
</table>
</div>
<h2><span style="font-size: 11pt">Conclusion
</span></h2>
Once you have this running you are ready to go to be able to share an insight into dev/test and production whilst keeping a snapshot of where the performance was on a particular date. Combining this with a lightweight performance monitor collection, during testing, takes away all the hassle of running a SQLDiag and then waiting to import/aggregate the data via the ReadTrace utility (Part of RML Utilities).]]></content:encoded>
    </item>
    <item>
      <title>The case for building a consolidated SSIS environment</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/the-case-for-building-a-consolidated-ssis-environment</link>
      <pubDate>Thu, 04 Aug 2016 17:06:22 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=1645</guid>
      <description><![CDATA[By Jonathan Ball – Data Platform Solution Architect.

SQL Server Integration Services, SSIS, can...]]></description>
      <content:encoded><![CDATA[By Jonathan Ball – Data Platform Solution Architect.

SQL Server Integration Services, SSIS, can be memory intensive, CPU hungry and will generally want to max out the server that it is running on. Your typical DBA is not going to want this running on the same server as the database engine taking up resources and making the monitoring of the database performance harder. Your typical developer is going to want to have SSIS as near as possible to the database for maintenance, possibly performance and to keep a tidy package for deployment and ongoing maintenance. SSIS packages can be heavily used in keeping data up to date and with the consistent approach to development in visual studio and SQL Server data tools creating integrated data solutions with Continuous Integration, CI and Continuous Deployment, CD is more common.

Deploying SSIS on the same box as your DB engine has been very common and can have benefits for ease of deployment, ongoing maintenance and logging/auditing. Another option is to deploy a separate SQL instance with your application/solution solely for SSIS. This can get costly and keeping track of multiple ETL servers for moving data around the data estate can be an unwanted overhead. In an estate where there is a large amount of SSIS being used it is worth considering a consolidation approach.

So with this in mind what are some of the benefits for consolidating:
<ul>
 	<li><strong>Licensing
</strong></li>
</ul>
This will be one of the strongest arguments for consolidating but savings in this area depend on how you deploy SSIS. If you are installing SSIS on a SQL Server instance that has other services on it, it could be running the database engine or SSRS, then you will already be licensing the server. If you consistently separate the SSIS out to other hardware then you will need to license those instances and consolidating will obviously have merit from a cost perspective.
<ul>
 	<li><strong>Ease of deployment
</strong></li>
</ul>
The project approach for SSIS has made deployment a much simpler matter. The use of ISPAC in a similar approach to DACPAC means the dev teams can pass across the deployment as a whole including the deployment specific variables, connections, folders within it. Deployment to a separate folder for the different applications/solutions combined with a single deployable pack makes manual deployment much easier. The possibility of integration with deployment management software for a CI/CD, approach is much stronger, but that is another blog! With these benefits, deploying to a single environment means that the dev teams and the teams doing the deployments will have one approach and environment to deal with for all releases.
<ul>
 	<li><strong>Logging and auditing.
</strong></li>
</ul>
From an enterprise data architecture perspective this should be high on the list of benefits. Knowing where and when your data is moving is a key part of understanding who is using what, when and for what purpose, with growing regulation identifying this as required. With the SSISDB, SSIS Catalog this information starts to become easier to locate. The out of the box reports available in SSMS querying the SSISDB deliver a good start to viewing and keeping track of the packages that are moving data around. Having this data in one place can massively simplify the job of the data stewards.
<ul>
 	<li><strong>Logical separation of applications/logs/reports.
</strong></li>
</ul>
This is more of a showcase of how project deployment makes separation possible within a consolidated environment. In the SQL Server 2012 release, the changes to SSIS around SSISDB for logging and the project deployment really started to support the case for a consolidated SSIS environment. A deployment of SSIS packages in earlier versions would allow for a single storage location but with no logical or role based grouping and minimal built in logging this would not provide any great benefit. Releases to either folders or into the MSDB would generally all sit in one area relying on naming conventions for any form of identification. Setting up different folders within the SSIS Catalog allows you to keep different applications separated and secured. The reporting will show the execution for these different folders/applications.

There are clearly benefits to putting together a consolidated environment but there are things that need careful planning. As with any environment you will need to consider an appropriate disaster recovery approach, considering high availability with SQL 2016 offering support for the SSISDB with availability groups. The approach for security for execution, separation of projects, reporting will need planning as well as permissions for CLR, third party installations on the environment and the actual execution method to use. With consolidated environment the upgrade path will be easier to identify but will also require more planning. When there are multiple SSIS installs, the sprawl can make standardising and upgrading difficult but with a shared platform if you upgrade, all projects will need to buy into the upgrade.

In addition to these obvious environmental design requirements, a shared platform will need to consider the possibility of setting up execution timetables. The benefit of a shared environment is that it is all located and maintained in one place. What it also means is that the resources are shared so administering the environment and executions will require knowledge and understanding of what the packages are doing and the time windows for execution, you might not want big jobs hitting each other.

There are clearly benefits to consolidating a SSIS platform but it needs a level of planning to make it run smoothly. The need for an appropriate design and architecture to specify the security, availability, disaster recovery and execution methods needs to go hand in hand with a consistent development approach by those producing the SSIS packages and the teams supporting the environment. If you are putting together an approach for consolidating SSIS these points can be used for validation and planning.]]></content:encoded>
    </item>
    <item>
      <title>Live Query Statistics</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/live-query-statistics</link>
      <pubDate>Thu, 07 Jul 2016 09:36:31 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=1635</guid>
      <description><![CDATA[By Mike Reed – Data Platform Solution Architect.

So you work in an organisation who run 'mission...]]></description>
      <content:encoded><![CDATA[By Mike Reed – Data Platform Solution Architect.

So you work in an organisation who run 'mission critical' applications but don't want to pay for tooling. You know, they want you to keep the lights on but won't invest in any of the great 3<sup>rd</sup> party monitoring tools that Microsoft's partners have written to make your life easier. So, you do your best, you write your own suite of monitoring and alerting tools. Sometimes these are pretty sophisticated and if you have the time to invest in them they can be really powerful. Or, you may be at the other end and you just have your 'Top 5 worst performing queries' script that you run when things are going south.

Either way you are going to love some of the new features in SQL Server 2016 that have been put in place to help those monitoring and maintaining SQL Server instances. Actually, these are great features for developers too that will help you tune your queries (you do that right?).

One of those new features is <strong>Live Query Statistics</strong>, a really nice little feature to help you see what's going on while a query is running. It gives you a view of the query you are tracking whilst its running.

You can turn it on several different ways. The easiest is to hit its icon in Management Studio which sits next to Include Actual Execution Plan:

<img src="https://msdnshared.blob.core.windows.net/media/2016/07/070716_0936_LiveQuerySt1.png" alt="" />

But you can also right click inside the text of a query

<img src="https://msdnshared.blob.core.windows.net/media/2016/07/070716_0936_LiveQuerySt2.png" alt="" />

And you get a new tab alongside Results and Messages with your Live Query Statistics information in like the screenshot below. How cool is that!

<img src="https://msdnshared.blob.core.windows.net/media/2016/07/070716_0936_LiveQuerySt3.png" alt="" />

So you get a running progress of the query both in the top and bottom left. Its useful in both places because if you switch to the Results or Messages pane you can still see how far through you are in the bottom left. However, even better, each step in the execution plan has its own little percentage counter so you can see in real time where the hold-up or the pain is.

For example, in the Screenshot below you can see that the hold-up is in the bottom right in the read of the FactResellerSalesXL table.

<img src="https://msdnshared.blob.core.windows.net/media/2016/07/070716_0936_LiveQuerySt4.png" alt="" />

It's also worth noting here that the tool is also available via Activity Monitor. If you right click on a query in the Active Expensive Queries pane you can also activate Live Query Statistics by clicking on Show Live Execution Plan and it will open up in its own tab.

<img src="https://msdnshared.blob.core.windows.net/media/2016/07/070716_0936_LiveQuerySt5.png" alt="" />

Just a final note that there is a warning on the MSDN page which reminds the user that this feature is primarily supposed to be for troubleshooting and that by using this feature it can 'moderately slow the overall query performance'. You have been warned!!

Hope you enjoy this new feature and it makes your life a little easier.]]></content:encoded>
    </item>
    <item>
      <title>Power BI in Your Organisation</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/power-bi-in-your-organisation</link>
      <pubDate>Tue, 21 Jun 2016 13:31:06 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=1125</guid>
      <description><![CDATA[By Michael Robson – Technical Solution Professional (Data Platform / BI). 
	Since the launch of...]]></description>
      <content:encoded><![CDATA[<p><span style="color:#333333"><strong>By Michael Robson – Technical Solution Professional (Data Platform / BI). </strong></span>
	</p><p><span style="color:#333333">Since the launch of Power BI last July there's been a lot of interest and, it's fair to say, a lot of confusion as to exactly what Power BI is and where it fits. </span>
	</p><p><span style="color:#333333"><em>Is it Microsoft's replacement for SSRS? </em></span>
	</p><p><span style="color:#333333"><em>Do I need Office365? </em></span>
	</p><p><span style="color:#333333"><em>This is really cheap; can I replace my Business Objects/Cognos investment with this? </em></span>
	</p><p><span style="color:#333333"><em>How does it compare with Qlik/Tableau? </em></span>
	</p><p><span style="color:#333333">And so on. </span>
	</p><p><span style="color:#333333">You may be familiar with terms such as <em>Polyglot Programming</em> and <em>Polyglot Persistence</em> (see http://martinfowler.com/bliki/PolyglotPersistence.html for more information), which refers to the combination of different technologies to solve complex problems, whilst not relying on a single language or storage mechanism. Modern Information architectures generally refer to this concept when dealing with data from multiple sources with varying properties. We can think of this as perhaps fast moving data vs batch data, or structured vs unstructured data. </span>
	</p><p><span style="color:#333333">If we extend this concept of <em>Polyglot Persistence</em> to also include analytical and reporting tools, we could perhaps coin the phrase <em>Polyglot Analysis </em>or<em> Polyglot Reporting</em>? After all, the needs of your organisation are going to be very different depending on who is consuming information. Does the CEO want the same level of analysis from a reporting tool than an Analyst or a Data Scientist? </span>
	</p><p><span style="color:#333333">So let's think about <em>who</em> our users are and <em>where</em> they fit in the organization. 
</span></p><p><img src="https://msdnshared.blob.core.windows.net/media/2016/06/062116_1532_PowerBIinYo1.png" alt="" /><span style="font-family:Times New Roman;font-size:12pt">
		</span></p><p><span style="color:#333333">In this diagram, we can think of our users as ether consumers or producers.
</span></p><p><span style="color:#333333"><strong>Business Users </strong></span>
	</p><p>The majority of our users are going to be simply consumers. For the most part they'll have reporting delivered to them or they'll login to a portal. Consumption will be typically via static/paginated reporting deriving data from an operational system or a data warehouse. They may also demand a little more interaction via dashboards which provide some ability to search and slice data, but still within a guided environment (links and pathways through the data are defined ahead of time). Commonly, mobile reporting is also delivered to satisfy tablet and mobile users within the community. 
</p><p><strong>Analyst/Super-user/Excel-Jockey </strong>
	</p><p>This is where we start to hit what Gartner refer to as bi-modal IT (http://www.gartner.com/it-glossary/bimodal). The super user or analyst who wants information now and they don't want to wait for IT to deliver it. We can think of this segment of users in two ways: 
</p><ul style="margin-left: 38pt"><li>Self-Service BI: Users who want to consume existing content but want to create their own reports. To deliver this IT might provide a pre-defined model (such as a Data Warehouse or Cube) and a set of tools to connect to it allowing the super-user to create their own content. 
</li><li>Business Analytics: A step beyond Self-Service BI, where analysts not only want to create their own reports and visuals, but they also want to create their own models. Here, an Analyst might take data from multiple sources to create data 'mashups' in order to provide analysis for 'top-of-mind' business problems. Rather than wait for IT to build a solution to address these questions (which could take months), Business Analytics tools allow user to quickly perform ad-hoc analysis to prove/disprove a hypothesis within days, if not hours. 
</li></ul><p><strong>Data Scientist </strong>
	</p><p>The increased demand for Data Science skills means an increased demand for specialised tooling in this discipline. Data Scientists typically will require a set of tools that allow them to experiment with multiple models unconstrained by schemas or existing datasets. 
</p><p><strong>IT</strong>
	</p><p>From IT's perspective, reporting tools will be focused on development and deployment tools for report creation, database/cube development, integration, planning, source control and so on. 
</p><p>Now that we've looked at who our users are and what types of workloads they might be running, where does Power BI fit in?<span style="font-family:Times New Roman;font-size:12pt">
		</span></p><p><img src="https://msdnshared.blob.core.windows.net/media/2016/06/062116_1359_PowerBIinYo2.png" alt="" /><span style="font-family:Times New Roman;font-size:12pt">
		</span></p><p>The chevron-shaded area in the enhanced diagram above shows Power BI's key user base, primarily, the Self-Service and Business Analytics community. It also shows some examples of Microsoft tooling that satisfies the other workloads. You may note, however, that the shaded area overlaps all users to some extent. This is simply because there are feature overlaps. Let's explore this a little. 
</p><p><strong>Power BI for Reporting and Dashboards </strong>
	</p><p>Just like SSRS, Power BI can be used to create rich dashboards and reports. Unlike SSRS, Power BI tends to be not so granular. With SSRS, the developer can open up detailed scripting and formatting to control the navigation path between reports as well as detailed pagination options such as defining margins and so on. Power BI adopts a more drag-and-drop approach, with the focus on obtaining insight from the data through interactive visualisation, not scripting pixel perfect dashboards. 
</p><p><strong>Power BI for the Data Scientist</strong>
	</p><p>I'm not claiming that Power BI can replace a wealth of tools and languages being used by Data Scientists, but there are a couple of key areas where it can significantly accelerate the value Data Scientists can bring to the rest of the organisation. For example, native integration with 
</p><ul><li>R as a data source, allowing you to import the content of data frames, and 
</li><li>R visuals, allowing you to embed native R visuals directly into a Power BI report or dashboard 
</li></ul><p>will allow data scientists to quickly produce and share insights with the business community without the need for complex database integration. 
</p><p><strong>Power BI for IT </strong>
	</p><p>A key use case for Power BI for the IT organisation is rapid prototyping. The underlying technology behind Power BI is SQL Server Analysis Server's tabular engine, allowing IT to produce prototypes using familiar enterprise capabilities. These prototypes could be rapidly developed and shared with the business community to gain feedback, and then, if required, they can be imported into SQL Server. As with the Data Science use case, this could be developed without the need for large infrastructure to be deployed or changed. Once value has been proven to the business, more formal models can be deployed using SQL Server Analysis Services, Azure Machine Learning, and R Server, and necessary integration pipelines built. 
</p><p><strong>Conclusion </strong>
	</p><p>At a high-level, this illustrates where the various BI and Analytics technologies fit into an organisation and what workloads are best suited. Power BI fits into the Self-Service and Business Analytics field well, spanning the spectrum and providing a broad set of tools for your organisation. However, consider the end user and the outcomes they are trying to achieve. It may well be that in order to achieve the outcomes your organisation needs you need to use a number of different reporting tools.<span style="color:#333333">
		</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Moving Schema and Data: SQL Azure Migration Wizard</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/moving-schema-data-sql-azure-migration-wizard</link>
      <pubDate>Mon, 06 Jun 2016 08:59:34 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=736</guid>
      <description><![CDATA[By Dan Stillwell – Data Platform Solution Architect.

In my previous blog I wrote about a scenario...]]></description>
      <content:encoded><![CDATA[By Dan Stillwell – Data Platform Solution Architect.

In my previous blog I wrote about a scenario where one of my customers wanted to utilise the flexibility of Azure for their SQL Server provisioning. The deployment started as a POC but very quickly became more than that with senior members of the organisation using the functionality. At this point we wanted to demonstrate the flexibility and elasticity of Azure by migrating the POC workload to a platform with HA, and SLA's. At this point we done a feasibility study between using SQL within a VM (IaaS) or Azure SQL DB (PaaS). We decided that Azure SQL DB was the right service offering for the requirements of the customer.

Azure strategies can vary and this is one of the great strengths within cloud technologies; whatever the customer requirements, Azure can generally offer a service to meet them. I have worked with customers who want to migrate all databases to Azure, I have worked with some customer who want to use Azure just for disaster recovery and High availability. This particular customer at present - is using Azure for development/ POC work. Once they are happy with the POC in Azure they then deploy and handover the service to their own Data Centre team.

So with this in mind we need to migrate the Schema and data from the standalone SQL Server within an Azure VM to Azure SQL DB. I will walk through the process, but as stated above I need a tool that can migrate in any 'Azure direction'. What I mean by this is the first stage will be to migrate the data from IaaS SQL Server to PaaS SQL DB, but the same method can be used to move it from PaaS to IaaS, PaaS to PaaS, on premise to Azure or Azure to on premise.

There are a few different ways when migrating data from one environment to another. You can use Generate Script Wizard, Deploy Database Wizard, SQL Server data tools, Export Data Tier, SSIS, BCP, sqlpackage.exe, AZ Copy, Backup/ Restore, Transactional Replication, HA technologies to replicate data (Log Shipping, AlwaysOn) to name a few. The tool I have used for the migration process is 'SQL Database Migration Wizard' the tool can be found from the open source site CodePlex (<a href="http://sqlazuremw.codeplex.com/">http://sqlazuremw.codeplex.com/</a>). You can migrate from SQL Server 2005, 2008, 2008R2, 2012, 2014. This is a different tool to the Upgrade Advisor, there is now a SQL Server 2016 Upgrade Advisor available in preview (<a href="https://www.microsoft.com/en-us/download/details.aspx?id=48119">https://www.microsoft.com/en-us/download/details.aspx?id=48119</a>).

One of the issues with migration is the compatibility between the source data/ instance version and the destination. For example, in Azure SQL DB at present CLR, XML, table partitions. FileStream is not supported. Full updated list of Azure SQL DB support (<a href="https://azure.microsoft.com/en-gb/documentation/articles/sql-database-transact-sql-information/">https://azure.microsoft.com/en-gb/documentation/articles/sql-database-transact-sql-information/#features-not-supported-in-sql-database</a>). This tool is a great way to identify in a planned way what may not work or is not supported on the destination environment. The tool uses regular expressions to analyse the phrases, so it can be configurable by yourself. The tool can fix some issues, but some issues can only be identified and not fixed automatically. This tool can be used as an end to end process for migration (analyse, script out schema, BCP the data) or you can use parts of the tool. For example, use the tool to analyse the schema and then use another method to migration the actual data.

Once you install the tool, you will be welcomed with the following splash screen. Here you can see the different options. Please note that you can capture a profiler trace and analyse that via this tool:

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem1.png" alt="" />

At this stage you will connect to a instance or database of SQL Server:

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem2.png" alt="" />

*You will need to create a firewall rule on Azure for the migration tool to access the Azure VM or Azure SQL DB. The IP address from the machine running the tool will require access.

You will then need to select your source database

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem3.png" alt="" />

Select all objects or select individual objects.

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem4.png" alt="" />

Clicking 'Advanced' gives the option to only script schema, data or both. You may wish to only run the schema script first to fix any compatibility issues.

You can also select or deselect compatibility checks at this stage.

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem5.png" alt="" />

After your selection click next, review and then choose to generate the script.

You then get presented with the script which you can then edit within the window, copy out to SSMS or save the script to run manually or edit at another time

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem6.png" alt="" />

In the 'Result Summary' tab any errors will be highlighted in red, you can also see the location of the .dat file where the data has been written to ready for the BCP process to import

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem7.png" alt="" />

Select Next and you will need to enter the destination server

<img class="alignleft" src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem8.png" alt="" />

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

In Azure, you then have an option to select a current SQL Database or create a new one, I am creating a new one when I am selecting a S1 service tier

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem9.png" alt="" />

Once the SQL Database is created, you can then select it from the list and execute the script against it. Alternatively, you can create the database manually and then run the script that you had the option of saving earlier against the database

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem10.png" alt="" />

As you can see, the table has been created and the data has been migrated:

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem11.png" alt="" />

Below are some things to highlight when using the tool:
<ul>
	<li>Please note that this tool is <strong>not</strong> officially supported by Microsoft. It is available on CodePlex which is Microsoft's open source site. Microsoft internal groups do monitor the feedback and discussions and will send a 'best effort' response.</li>
	<li>The tool will fix some compatibility issues. Pay attention to the output report for what has been fixed and what needs additional fixing from you.</li>
	<li>You can work with the script within the tool, or saving it and editing it in SQL Server Management Studio or SQL Server Data Tools (Visual Studio).</li>
	<li>Within your script you can use 'IF Exist', this allows you to run the script multiple times. However, you may not want to script the data at this stage as it will BCP the data multiple times.</li>
	<li>The process should be to allow the tool to fix automatically/ apply any recommendations, fix any other issues, migrate the schema, confirm migration of schema is correct, then import the data via running the BCP Data script.</li>
	<li>If you are loading a large amount of data, you can run the script from different machines to utilise more threads and processing power.</li>
	<li>DAT files are kept by default in 'C:\SQLAzureMW\BCPData)'.</li>
	<li>
<div>You can increase or decrease the parallel processing of the data migration by altering the 'NumberofBCPThreads' within the SQLAzureMW.exe.config file:</div>
&lt;add key="NumberOfBCPThreads" value="8"/&gt;

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/060616_0957_MovingSchem12.png" alt="" /></li>
</ul>
As you can see the Migration Wizard gives great flexibility to assist in moving the schema and data to Azure whether that is IaaS or PaaS. When I have used the tool with my customers it can help solve a major barrier around complexities, time and resource in creating scripts and even a test process for ensuring compatibility to the different platform.]]></content:encoded>
    </item>
    <item>
      <title>Transactional Replication Using an Azure SQL Database Subscriber</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/transactional-replication-using-a-azure-sql-database-subscriber</link>
      <pubDate>Mon, 23 May 2016 13:53:30 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=636</guid>
      <description><![CDATA[By Graeme Scott – Data Platform Solution Architect.

For companies that have geographically...]]></description>
      <content:encoded><![CDATA[By Graeme Scott – Data Platform Solution Architect.

For companies that have geographically dispersed operating models which may involve physical stores, outlets, venues or branches; data replication from individual stores to data centres is often a key technical function that enables companies to measure overall business performance.

It is not uncommon for geographically dispersed companies to capture a significant amount of transactional and operational data at individual stores or branches; in these scenarios, customers often use transactional replication to transport the data centrally for analysis.

With SQL Server 2016 it's now possible to replicate data from an on premise replication publisher to an Azure SQL Database subscriber.

This replication configuration provides customers with the following possibilities:
<ul>
	<li>A very easy route to transition to a hybrid – on premise cloud configuration with minimal disruption to business continuity.</li>
	<li>Off load reporting workload to separate cloud infrastructure.</li>
	<li>Provide fine grain control as to the database objects (tables, views) that are stored within an Azure SQL Database. With replication, individual tables (articles) are added to a publication that are to be replicated to a subscriber.</li>
	<li>With data stored within an Azure SQL Database subscriber, customers can enrich the data and gain increased insight by leveraging a range of Azure services, for example Azure Machine Learning and R.</li>
	<li>Data recoverability and high availability.</li>
</ul>
Setting up transactional replication from an on premise publisher to an Azure SQL Database subscriber is practically identical when compared to an on premise setup experience using SQL Server Management Studio. The configuration can also be achieved using TSQL scripts.

When I setup transactional replication to use an Azure SQL Database subscriber, the only change I had to make compared to a full on premise configuration was the subscriber connection to suit a Azure SQL Database (Azure SQL Database connection string):

<img src="https://msdnshared.blob.core.windows.net/media/2016/05/052316_1353_Transaction11.png" alt="" />

&nbsp;

SQL Server Replication Monitor also works seamlessly with an Azure SQL Database subscriber, all the replication information and diagnostics data are present.

So what are the limitations associated with using an Azure SQL Database as a subscriber to for transactional replication?
<ul>
	<li>Only transactional replication is supported.</li>
	<li>The transactional replication needs to be a push subscription.</li>
	<li>Any post snapshot scripts would need to be verified to determine suitability for an Azure SQL Database.</li>
	<li>A SQL Azure Database can only be a subscriber database for transactional replication.</li>
	<li>There will be limitations on publishing database objects that are CLR based.</li>
</ul>
It's possible to meet the majority of these goals with SQL Server Availability Groups. The main differences with these two options are that Availability Groups replicate an entire database as a secondary replica.

With transactional replication it's possible to replicate only a single table from within a publisher database. This may be less of a barrier for customers to consider moving data and workload to an Azure SQL Database.

The following article has more details about replicating to SQL Azure:

<a href="https://azure.microsoft.com/en-gb/blog/transactional-replication-to-azure-sql-db/">https://azure.microsoft.com/en-gb/blog/transactional-replication-to-azure-sql-db/</a>

The following article has more details about SQL Server replication with SQL Server 2016:

<a href="https://msdn.microsoft.com/en-us/library/ms152559.aspx">https://msdn.microsoft.com/en-us/library/ms152559.aspx</a>

It's outside the scope of this article however it is possible to use earlier versions of SQL Server (SQL Server 2012 upwards) to replicate from an on premise publisher to an Azure virtual machine. Some more details can be found here:

<a href="https://blogs.msdn.microsoft.com/repltalk/2014/07/28/microsoft-sql-replication-between-windows-azure-virtual-machines/">https://blogs.msdn.microsoft.com/repltalk/2014/07/28/microsoft-sql-replication-between-windows-azure-virtual-machines/</a>]]></content:encoded>
    </item>
    <item>
      <title>Back on the mat</title>
      <link>https://docs.microsoft.com/archive/blogs/ukdataplatform/back-on-the-mat</link>
      <pubDate>Fri, 20 May 2016 11:32:13 GMT</pubDate>
      <dc:creator><![CDATA[BenCooper]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ukdataplatform/?p=625</guid>
      <description><![CDATA[By Craig Clayton – Technical Solution Professional.

I recently went back to Brazilian jiu-jitsu...]]></description>
      <content:encoded><![CDATA[By Craig Clayton – Technical Solution Professional.

I recently went back to Brazilian jiu-jitsu after a lay off due to injury (due to old age!). BJJ is a ground based martial art that "<em>promotes the concept that a smaller, weaker person can successfully defend against a bigger, stronger, heavier assailant by using proper technique, leverage, and most notably, taking the fight to the ground, and then applying joint-locks and chokeholds to defeat the opponent"</em>. For more details, see: <a href="https://en.wikipedia.org/wiki/Brazilian_jiu-jitsu">https://en.wikipedia.org/wiki/Brazilian_jiu-jitsu</a>.

<img src="https://msdnshared.blob.core.windows.net/media/2016/05/052016_1132_Backonthema1.png" alt="" /><strong>
</strong>

Whilst learning the art, you get lots of opportunities to try the techniques in live "rolling" or sparring, with the objective to try and submit your opponent, or get them to 'tap out'. This can be quite disheartening when you first start and when you subsequently roll with more experienced team members, as you spend a lot time tapping out! However, this forms the rights to passage - where it all adds to the learning and development of your skill, ability and style.

This Journey reminds me a lot of SQL Server's journey against Oracle. The years of being submitted by the more experienced player, over and over again. But, instead of the SQL Server product team giving up and accepting the product's level, it only toughened the team's resolve. Focusing on the weaknesses and limitations within the product, coupled with leveraging the natural attributes of Microsoft (e.g. Azure, Windows etc.) has led to a real game changing product with SQL Server 2016.

SQL Server 2016 offers outstanding features <em>(these features will be the focus of subsequent blogs by both myself and the rest of the team),</em> all built-in to the product, to provide seamless integration with an attractive price point that negates the need for addition extras. The slide below demonstrates some high-level business benefits underpinned by many new capabilities:

<img src="https://msdnshared.blob.core.windows.net/media/2016/05/052016_1132_Backonthema2.png" alt="" />

Some of the headline features being <em>(but believe me <strong>it is much more than</strong> these points!):</em>
<ul>
	<li>
<div><a href="https://msdn.microsoft.com/en-GB/library/mt163865.aspx">Always Encrypted</a> – where the data is encrypted by the client, hence is stored encrypted within SQL Server as well as across the network finally to be decrypted at the client. This allows businesses greater piece of mind and more potential to use Azure.</div>
&nbsp;</li>
	<li>
<div><a href="https://msdn.microsoft.com/en-us/library/dn935011.aspx">Stretch Database</a> – allowing Customers to archive 'cold' data to Azure, whilst still having the ability to query the data, as if it was still on-premises in the same table. Resulting in the reduction of both storage on-premises and SQL Server maintenance windows.</div>
&nbsp;</li>
	<li>
<div><a href="https://blogs.technet.microsoft.com/dataplatforminsider/2015/12/09/real-time-operational-analytics-using-in-memory-technology/">Real Time Operational Analytics</a> – enabling Customers to report directly from OLTP Source systems in real time, without the fear of disruption to the OLTP capabilities and reducing the need for extensive ETL processes.</div>
&nbsp;</li>
	<li>
<div><a href="https://msdn.microsoft.com/en-US/library/mt604845.aspx">R Services</a> – embracing the data scientist open-source language of choice. Integrated into SQL Server 2016 with massive improvements around performance and security.</div>
&nbsp;</li>
	<li><a href="https://msdn.microsoft.com/en-us/library/dn133186.aspx">Extensive in-memory capabilities</a> – enabling businesses to achieve outstanding performance with less cores, <em>potentially reducing the SQL Server License spend!</em></li>
</ul>
This has resulted in what we see today: Microsoft - <strong>The leader in the Operational Database Management System market </strong>as per the <a href="https://www.gartner.com/doc/reprints?id=1-2PMFPEN&amp;ct=151013">Gartner Magic Quadrant (October 2015) for ODBMS</a>.

<img src="https://msdnshared.blob.core.windows.net/media/2016/05/052016_1132_Backonthema3.png" alt="" />

Finally, <span style="color: red"><strong><em>'SQL Server Tapping out Oracle!'</em>
</strong></span>Subscribe to this blog, to understand more about SQL Server 2016's capabilities across industry, on-premises and the cloud as well as more broad data platform architectural patterns and best practices.]]></content:encoded>
    </item>
  </channel>
</rss>