<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6571655444622533369</id><updated>2024-09-13T07:32:46.154-07:00</updated><category term="T-SQL"/><category term="MS SQL Server 2012"/><category term="Script"/><category term="SQL Server"/><category term="T-SQL Solution"/><category term="SQL"/><category term="Query optimization"/><category term="Performance"/><category term="SQL Server 2014"/><category term="AlwaysOn"/><category term="Availability Group"/><category term="Adhoc Query"/><category term="Clustering"/><category term="High Availability"/><category term="Index"/><category term="SQL Server 2016"/><category term="Cube"/><category term="DML"/><category term="Excel"/><category term="Indexed View"/><category term="Paging"/><category term="SSAS"/><category term="SYSTEM_TIME"/><category term="Sequence Objects"/><category term="TSQL"/><category term="Triggers"/><category term="UPDATE"/><category term=".NET"/><category term="Analysis Services 2012"/><category term="Backups"/><category term="Blocking"/><category term="Business Intelligence"/><category term="CSV"/><category term="Case"/><category term="Connection String"/><category term="Contained Databases"/><category term="Corporate BI"/><category term="DATALENGTH"/><category term="DROP IF EXISTS"/><category term="Duplicates"/><category term="ERROR"/><category term="Error Handling"/><category term="Functions"/><category term="Handling"/><category term="INSERT"/><category term="JOIN"/><category term="JSON"/><category term="LEN"/><category term="LogShipping"/><category term="Migration"/><category term="Numeric Conversion"/><category term="OLEDB"/><category term="OPENJSON"/><category term="OUTPUT"/><category term="Office 365"/><category term="Open Transactions"/><category term="Poison Message"/><category term="PowerPivot"/><category term="Ranking Functions"/><category term="Row versioning"/><category term="SET LANGUAGE. SET DATEFIRST"/><category term="SQL Azure"/><category term="SQL Server Migration"/><category term="SSMS"/><category term="STRING_SPLIT"/><category term="Self-Service BI"/><category term="Service Broker"/><category term="System-versioned table"/><category term="Tabular Model"/><category term="Transactions"/><category term="Views"/><category term="Windows Azure"/><category term="data Model"/><category term="xp_fileexist"/><title type='text'>Atif-ullah Sheikh Sharing SQL knowledge</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>70</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-2952527284965998270</id><published>2017-05-15T06:27:00.003-07:00</published><updated>2017-05-15T06:27:55.191-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Row versioning"/><category scheme="http://www.blogger.com/atom/ns#" term="Script"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><category scheme="http://www.blogger.com/atom/ns#" term="System-versioned table"/><category scheme="http://www.blogger.com/atom/ns#" term="SYSTEM_TIME"/><category scheme="http://www.blogger.com/atom/ns#" term="TSQL"/><title type='text'>System versioned Tables in SQL Server 2016</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
In SQL Server 2016, System versioned tables are the tables
whose data is maintained in the history table. This history is maintained by
SQL Server itself. All you need is to specify 2 additional datetime2 columns (SysStartTime
and SysEndTime in the example below) and a clause with these two columns as : &lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;PERIOD&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;FOR&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;SYSTEM_TIME &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;SysStartTime&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;SysEndTime&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;)&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
To create a system versioned table;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;------
System versioned table&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; Department&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DeptID &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;PRIMARY&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;KEY&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;CLUSTERED&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; DeptName &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; ManagerID &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; ParentDeptID &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; SysStartTime &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;datetime2&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;GENERATED&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ALWAYS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ROW&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;START&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; SysEndTime &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;datetime2&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;GENERATED&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ALWAYS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ROW&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;PERIOD&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FOR&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SYSTEM_TIME &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SysStartTime&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SysEndTime&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;WITH
&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SYSTEM_VERSIONING&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
The system versioned table creates a temporal table which
maintains the history of the data. By default, the name is as MSSQL_TemporalHistoryFor_1541580530.
But you can specify the name of this table in the CREATE TABLE statement above;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;------
System versioned table with name the temporal table&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; Department&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DeptID &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;PRIMARY&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;KEY&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;CLUSTERED&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; DeptName &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; ManagerID &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; ParentDeptID &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; SysStartTime &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;datetime2&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;GENERATED&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ALWAYS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ROW&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;START&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; SysEndTime &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;datetime2&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;GENERATED&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ALWAYS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ROW&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;PERIOD&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FOR&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SYSTEM_TIME &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SysStartTime&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SysEndTime&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;WITH
&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SYSTEM_VERSIONING&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;ON &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; HISTORY_TABLE &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;DepartmentHistory &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
In above example, dbo.DepartmentHistory
is created as temporal table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
In the management
studio, the system versioned tables are shown as below;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ_HZ82Vo9Nrz6W-CIEVEPZmBu9JP0Kov17nyllJmFbBjyCAJSFiF2P4xjOu1Q78gn9rIf5LgtVQJGFGe1SiBMmdPMLox5_ASe1uzAJzCRifLxmGw7RKQtG1WxDjNIk-WjX9EM500CQOBe/s1600/SVT1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ_HZ82Vo9Nrz6W-CIEVEPZmBu9JP0Kov17nyllJmFbBjyCAJSFiF2P4xjOu1Q78gn9rIf5LgtVQJGFGe1SiBMmdPMLox5_ASe1uzAJzCRifLxmGw7RKQtG1WxDjNIk-WjX9EM500CQOBe/s1600/SVT1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id=&quot;_x0000_t75&quot; coordsize=&quot;21600,21600&quot;
 o:spt=&quot;75&quot; o:preferrelative=&quot;t&quot; path=&quot;m@4@5l@4@11@9@11@9@5xe&quot; filled=&quot;f&quot;
 stroked=&quot;f&quot;&gt;
 &lt;v:stroke joinstyle=&quot;miter&quot;/&gt;
 &lt;v:formulas&gt;
  &lt;v:f eqn=&quot;if lineDrawn pixelLineWidth 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 1 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum 0 0 @1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @2 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 0 1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @6 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;sum @8 21600 0&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @10 21600 0&quot;/&gt;
 &lt;/v:formulas&gt;
 &lt;v:path o:extrusionok=&quot;f&quot; gradientshapeok=&quot;t&quot; o:connecttype=&quot;rect&quot;/&gt;
 &lt;o:lock v:ext=&quot;edit&quot; aspectratio=&quot;t&quot;/&gt;
&lt;/v:shapetype&gt;&lt;v:shape id=&quot;Picture_x0020_1&quot; o:spid=&quot;_x0000_i1031&quot; type=&quot;#_x0000_t75&quot;
 style=&#39;width:318pt;height:33.75pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
The above diagram shows
the default name of the temporal table. If you have specified the name of your
temporal table (dbo.DepartmentHistory in our example), then it will be shown;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOLfFQj0fIwHTQUhJuxVblCY4AlSuDdIuN3Hqj3xWahalUoETRhFng1S8Yiy87ZGlMBZBthvN8YnGF358K8eY97nSR24b7EAUtcX3UBo4LRLTTqi_xBzvHWZBub1Y6B2TDxBfK_ly5JK3B/s1600/SVT2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOLfFQj0fIwHTQUhJuxVblCY4AlSuDdIuN3Hqj3xWahalUoETRhFng1S8Yiy87ZGlMBZBthvN8YnGF358K8eY97nSR24b7EAUtcX3UBo4LRLTTqi_xBzvHWZBub1Y6B2TDxBfK_ly5JK3B/s1600/SVT2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape id=&quot;Picture_x0020_3&quot; o:spid=&quot;_x0000_i1030&quot;
 type=&quot;#_x0000_t75&quot; style=&#39;width:289.5pt;height:28.5pt;visibility:visible;
 mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
You can also rename the temporal
table. In sys.objects, these tables are listed as a user_table. To check if any
table have a temporal table or not you can query the “OBJECTPROPERTY” for
property “TableTemporalType”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: magenta; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;OBJECTPROPERTY&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: magenta; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;OBJECT_ID&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;N&#39;dbo.Department&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;N&#39;U&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;),&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;N&#39;TableTemporalType&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;b&gt;INSERT / UPDATE / DELETE&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
When we insert any data
in the main table (dbo.Department), no data is inserted in the history /
temporal table. In case of UPDATE you will see the latest data in main table
and the history data in the temporal. The SysStartTime and SysEndTime are
updated as per the time of UPDATE statement;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: magenta; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Update&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; [dbo]&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;[Department]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; DeptName &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;&#39;A&#39;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; DeptID &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; [dbo]&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;[Department]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH6PILPCNMvKYMFqcCvnjs-MuzGpBdHrNfToFNQDtPRQlz9f-Q5Q-bD4UXXwBRYK9y9Jhj3G9zU0KpQndAeFqhXKq4rvyWZ_dREkNDt-wubef5Zh6MdpIY2Ot1YpgCcBAeF94HPTmfg5FU/s1600/SVT3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH6PILPCNMvKYMFqcCvnjs-MuzGpBdHrNfToFNQDtPRQlz9f-Q5Q-bD4UXXwBRYK9y9Jhj3G9zU0KpQndAeFqhXKq4rvyWZ_dREkNDt-wubef5Zh6MdpIY2Ot1YpgCcBAeF94HPTmfg5FU/s1600/SVT3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape
 id=&quot;Picture_x0020_5&quot; o:spid=&quot;_x0000_i1029&quot; type=&quot;#_x0000_t75&quot; style=&#39;width:468pt;
 height:84.75pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; [dbo]&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;[DepartmentHistory]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5mZj5Rl89vvY9-LoL7UOGE-lTmUC7VM2JPPCFQsGlIeMMwpCap4SZuq0gQXstN26hr978mxZ0RVGEqv1RSO4869PfnX2FGPbtPM1mliUfzLAnTfOo9s3kiUbLIE7T31IIK3zIsh84OHlH/s1600/SVT4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5mZj5Rl89vvY9-LoL7UOGE-lTmUC7VM2JPPCFQsGlIeMMwpCap4SZuq0gQXstN26hr978mxZ0RVGEqv1RSO4869PfnX2FGPbtPM1mliUfzLAnTfOo9s3kiUbLIE7T31IIK3zIsh84OHlH/s1600/SVT4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape id=&quot;Picture_x0020_4&quot; o:spid=&quot;_x0000_i1028&quot;
 type=&quot;#_x0000_t75&quot; style=&#39;width:468pt;height:69.75pt;visibility:visible;
 mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can see above that DeptName for DeptID=3 is changed to ‘A’
and the old value ‘D3’ is available in the temporal table. Please note that the
copy of the complete record is maintained in the temporal table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You cannot delete the data directly from Temporal table.
When you delete data from main table, the data is stored in temporal table and
deleted from the main table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;Delete&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; [dbo]&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;[Department] &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; DeptID &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; [dbo]&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;[Department]&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9iwfvtb0a-Ls_r7WUpg8FefO3xybZqhCmOzgDsLiDAN0Iedqin62u6Mj6PVmxFq_4ZM6OyFrrw59tx6Epja_PAOQTTiU_rk7VyJozfz8K0Dzr70pMwiRvcTxRRSONn6ktO49FYiDfbqKX/s1600/SVT5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9iwfvtb0a-Ls_r7WUpg8FefO3xybZqhCmOzgDsLiDAN0Iedqin62u6Mj6PVmxFq_4ZM6OyFrrw59tx6Epja_PAOQTTiU_rk7VyJozfz8K0Dzr70pMwiRvcTxRRSONn6ktO49FYiDfbqKX/s1600/SVT5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape
 id=&quot;Picture_x0020_6&quot; o:spid=&quot;_x0000_i1027&quot; type=&quot;#_x0000_t75&quot; style=&#39;width:468pt;
 height:79.5pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
As you can see the data is deleted from main table. But the
record is available in temporal table;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; [dbo]&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;[DepartmentHistory]&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSF3dnDrCQp1dOVrbpfRJQj0meRI8m1HU7wJ4WSd5l5NHoor_qJKoClybA07-LOFR1xBYdvNi1u3k5o6sU2yaAwrhZ1N4wWtvCOSUnMNC9RUC_aMipT5ZSZhVEWwDFa0-Lf962srAhwwi_/s1600/SVT6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSF3dnDrCQp1dOVrbpfRJQj0meRI8m1HU7wJ4WSd5l5NHoor_qJKoClybA07-LOFR1xBYdvNi1u3k5o6sU2yaAwrhZ1N4wWtvCOSUnMNC9RUC_aMipT5ZSZhVEWwDFa0-Lf962srAhwwi_/s1600/SVT6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape
 id=&quot;Picture_x0020_7&quot; o:spid=&quot;_x0000_i1026&quot; type=&quot;#_x0000_t75&quot; style=&#39;width:468pt;
 height:76.5pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
When you try to delete from the DepartmentHistory temporal
table, it will generate error;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Delete&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; [dbo]&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;[DepartmentHistory] &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; DeptID &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; 3&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape
 id=&quot;Picture_x0020_8&quot; o:spid=&quot;_x0000_i1025&quot; type=&quot;#_x0000_t75&quot; style=&#39;width:459.75pt;
 height:61.5pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLnMqAsE4zdfyaJDDk_7l0jzhtfyuOYrF3Zj5nskB3hPz-FJBki-6tYYLq8ZpfTIxeH45r3zDmFQmcsVdC5BEMlpv1wAi50waI_jTPx_MLFhU9NpJ7RxcfgXTGATWSfRlZ4hAQ4fUWzWX_/s1600/SVT7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLnMqAsE4zdfyaJDDk_7l0jzhtfyuOYrF3Zj5nskB3hPz-FJBki-6tYYLq8ZpfTIxeH45r3zDmFQmcsVdC5BEMlpv1wAi50waI_jTPx_MLFhU9NpJ7RxcfgXTGATWSfRlZ4hAQ4fUWzWX_/s1600/SVT7.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
So, you cannot delete data from temporal table. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;WHAT ELSE YOU CANNOT
DO&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
TRUNCATE TABLE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraph&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;1.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;You also cannot TRUNCATE the system versioned
and the temporal table. You will get the following error;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none; text-indent: .5in;&quot;&gt;
&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Msg 13545, Level 16, State 1, Line 35&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;
&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;Truncate failed on table &#39;Test16.dbo.Department&#39; because it is not
supported operation on system-versioned tables.&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;
&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;2.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;You cannot change the schema of the temporal
table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;3.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;You cannot add trigger to temporal table&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;YOU CAN ADD INDEX&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can index the temporal table and the main table as per
your requirement.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/2952527284965998270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/05/system-versioned-tables-in-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2952527284965998270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2952527284965998270'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/05/system-versioned-tables-in-sql-server.html' title='System versioned Tables in SQL Server 2016'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ_HZ82Vo9Nrz6W-CIEVEPZmBu9JP0Kov17nyllJmFbBjyCAJSFiF2P4xjOu1Q78gn9rIf5LgtVQJGFGe1SiBMmdPMLox5_ASe1uzAJzCRifLxmGw7RKQtG1WxDjNIk-WjX9EM500CQOBe/s72-c/SVT1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-6069085945147308532</id><published>2017-05-02T06:24:00.001-07:00</published><updated>2017-05-02T06:24:49.545-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Case"/><category scheme="http://www.blogger.com/atom/ns#" term="JOIN"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="TSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="UPDATE"/><title type='text'>Update Table Joined with other on the basis of CASE statement</title><content type='html'>Please check the below example;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sql prettyprinted&quot; style=&quot;background-color: white; border: 1px solid rgb(136, 136, 136); color: #333333; direction: ltr; font-family: inherit; font-size: 14px; list-style-type: none; min-height: 70px; outline: 0px; overflow-x: auto; overflow-y: visible; padding: 2px; word-wrap: normal;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Declare&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableA &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Table&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;CINAME varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;  SerialNo varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;   Status varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;    UniquekeyCiname_serialno varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Declare&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableB &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Table&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;CINAME varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;  SerialNo varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;   Status varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;    UniquekeyCiname_serialno varchar&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; color: #006666; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Insert&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;into&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableA
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ASDAS&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;23SSD&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ASDAS23SSD&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;All&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;WER34&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;WER34&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;All&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;DFDFS&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;3239&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;DFDFS3239&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;All&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ERTER&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ERTER&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;


&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Insert&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;into&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableB
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ASDAS&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;23SSD&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;DEPLOYED&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ASDAS23SSD&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;All&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;WER34&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;5335&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;IN TRANSIT&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;WER345335&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;All&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;DFDFS&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;3239&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;LOST&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;DFDFS3239&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Union&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;All&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ERTER&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;678W&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;DEAD&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;ERTER678W&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;


&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableA
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableB

&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Update&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; a
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Status&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; b&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Status&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; 
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;From&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableA a
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Inner&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Join&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableB b &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Case&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; IsNull&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;SerialNo&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;)&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;UniquekeyCiname_serialno &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;CINAME &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Case&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; IsNull&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;SerialNo&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;)&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; b&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;UniquekeyCiname_serialno &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; b&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;CINAME &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableA
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;vTableB&lt;/span&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/6069085945147308532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/05/update-table-joined-with-other-on-basis.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/6069085945147308532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/6069085945147308532'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/05/update-table-joined-with-other-on-basis.html' title='Update Table Joined with other on the basis of CASE statement'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-7360804891694737544</id><published>2017-04-12T04:37:00.002-07:00</published><updated>2017-04-12T04:38:34.791-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AlwaysOn"/><category scheme="http://www.blogger.com/atom/ns#" term="Availability Group"/><category scheme="http://www.blogger.com/atom/ns#" term="LogShipping"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><title type='text'>Implement Log Shipping with AlwaysOn Availability Group</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Audience&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
This article is for those who understands bot AlwaysOn
Availability Group and Log Shipping. I will not go into the details explaining
the both technologies. The article will only cover the tricky part that is
involved to implement Log Shipping with AlwaysOn Availability Group.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Scenario&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Let’s suppose you have AlwaysOn Availability Group
implemented. Assume you have more than one databases part of the availability
group but due to some technical requirements, you need to provide a read only
access of only one database. Here, Log Shipping can help you to replicate data on
the another machine to give access to the data. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Environment&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Let’s say we have one node as SQL1 and one node as SQL2. You
need to apply Log Shipping on node SQL3 which is not the part of the availability
group replicas. You need to first apply Availability group with Listener (IP
and port). Make sure you can connect with the Primary node (say, its SQL1 is Primary
and SQL2 is secondary at this time) using Listener IP and port that you
specified at the time of the creation of Availability Group on Listener Tab. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Implement Log
Shipping&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Connect the primary Replica using Listener IP and port and implement
Log Shipping using SQL3 as your Log Shipping node. Make sure that the shared
backup path is accessible by all nodes SQL1, SQL2 and SQL3. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Tricky Part&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Right click the availability group and go to Backup
Preferences page. Here select, “Primary” as you backup preference.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Since the log shipping is applied to the Primary replica SQL1
and not on secondary replica SQL2, so when the failover will occur from SQL1 to
SQL2, the log shipping will break. It is because the log shipping jobs are not
applied on the secondary SQL2 node and in case of any log backup on SQL1, the LSN
chain will break even when you will go back to SQL1 from SQL2. So the trick
here is to create the script of the Log Shipping that you implemented on Primary
node SQL1. The script is divided into 2 parts. Copy the “Primary” part of the
script. Failover to the SQL2. Connect to SQL Server using the same Listener IP
and port. This will connect you to SQL2. Open the query window and paste the
copied script. Run the script. The script will create and configure the Log
Shipping on SQL2 for you. Now you have log shipping is configured on both nodes
SQL1 an SQL2.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Result&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Now, in case of failover, your log shipping will never break
as the backups will be taken on Primary node only and the LSN will be maintained.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/7360804891694737544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/04/implement-log-shipping-with-alwayson.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7360804891694737544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7360804891694737544'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/04/implement-log-shipping-with-alwayson.html' title='Implement Log Shipping with AlwaysOn Availability Group'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-4455729000915229658</id><published>2017-02-09T04:10:00.000-08:00</published><updated>2017-02-09T04:10:18.283-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DROP IF EXISTS"/><category scheme="http://www.blogger.com/atom/ns#" term="JSON"/><category scheme="http://www.blogger.com/atom/ns#" term="OPENJSON"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><category scheme="http://www.blogger.com/atom/ns#" term="STRING_SPLIT"/><category scheme="http://www.blogger.com/atom/ns#" term="SYSTEM_TIME"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><title type='text'>SQL Server 2016 T-SQL Enhancements</title><content type='html'>&lt;div style=&quot;margin-bottom: .0001pt; margin: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,sans-serif; font-size: 11.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Few
enhancements are worth discussing.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;DROP IF EXISTS&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Calibri, sans-serif; font-size: 11pt;&quot;&gt;In old versions of SQL Server we had to&amp;nbsp;check
if the table or column exists before dropping it. In SQL Server 2016, this is
made simple by making IF EXISTS optional part of DROP TABLE, DROP INDEX, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: .0001pt; margin: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;EXISTS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Product&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;TRIGGER&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;EXISTS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; trProductInsert&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: .0001pt; margin: 0in;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;INDEX&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;EXISTS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; Department&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;DeptID&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;trProductInsert&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: .0001pt; margin: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: .0001pt; margin: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,sans-serif; font-size: 11.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;It works
with the following objects;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: .0001pt; margin: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;background: white; mso-cellspacing: 0in; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 464px;&quot;&gt;
 &lt;tbody&gt;
&lt;tr&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 111.0pt;&quot; valign=&quot;bottom&quot; width=&quot;148&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
AGGREGATE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 132.75pt;&quot; valign=&quot;bottom&quot; width=&quot;177&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
PROCEDURE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 104.25pt;&quot; valign=&quot;bottom&quot; width=&quot;139&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
TABLE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 111.0pt;&quot; valign=&quot;bottom&quot; width=&quot;148&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
ASSEMBLY&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 132.75pt;&quot; valign=&quot;bottom&quot; width=&quot;177&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
ROLE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 104.25pt;&quot; valign=&quot;bottom&quot; width=&quot;139&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
TRIGGER&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 111.0pt;&quot; valign=&quot;bottom&quot; width=&quot;148&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
VIEW&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 132.75pt;&quot; valign=&quot;bottom&quot; width=&quot;177&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
RULE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 104.25pt;&quot; valign=&quot;bottom&quot; width=&quot;139&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
TYPE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 111.0pt;&quot; valign=&quot;bottom&quot; width=&quot;148&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
DATABASE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 132.75pt;&quot; valign=&quot;bottom&quot; width=&quot;177&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
SCHEMA&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 104.25pt;&quot; valign=&quot;bottom&quot; width=&quot;139&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
USER&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 111.0pt;&quot; valign=&quot;bottom&quot; width=&quot;148&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
DEFAULT&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 132.75pt;&quot; valign=&quot;bottom&quot; width=&quot;177&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
SECURITY POLICY&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 104.25pt;&quot; valign=&quot;bottom&quot; width=&quot;139&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
VIEW&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 111.0pt;&quot; valign=&quot;bottom&quot; width=&quot;148&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
FUNCTION&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 132.75pt;&quot; valign=&quot;bottom&quot; width=&quot;177&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
SEQUENCE&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 104.25pt;&quot; valign=&quot;bottom&quot; width=&quot;139&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 111.0pt;&quot; valign=&quot;bottom&quot; width=&quot;148&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
INDEX&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 132.75pt;&quot; valign=&quot;bottom&quot; width=&quot;177&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 18.75pt; vertical-align: baseline;&quot;&gt;
SYNONYM&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid #DADADA 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-bottom-alt: solid #DADADA .75pt; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 104.25pt;&quot; valign=&quot;bottom&quot; width=&quot;139&quot;&gt;
  &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: .0001pt; margin: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
For column use the following syntax;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;ALTER&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; Department &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;COLUMN&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;EXISTS&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; abc&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;STRING_SPLIT&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Prior to SQL Server, we had to create a Table value function
to get the list of character separated values. MS have now made it the part of
SQL Server built-in functions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: magenta; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;STRING_SPLIT&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;&#39;a,b,c&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;&#39;,&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Also works with the variable;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; @tags &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;a,b,,c,d&#39;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: magenta; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;STRING_SPLIT&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;@tags&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;&#39;,&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: magenta; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;RTRIM&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Returns values are nvarchar if the input in nvarchar or
nchar. Otherwise returns varchar. It accepts a single character as separator. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;SYSTEM_TIME&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
For system versioned tables, we can check the history values
in the query;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Department&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;FOR&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;SYSTEM_TIME&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;BETWEEN&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;&#39;2017-02-08&#39;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;And&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;&#39;2017-02-10&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;The above query will give you all the updates made on the
tblDepartment (with system versioning enabled) between the two given dates. You
can also specify the date and time;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Department&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;FOR&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;SYSTEM_TIME&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;BETWEEN&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;&#39;2017-02-08
09:00:00.000&#39;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;And&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;&#39;2017-02-10 10:00:00.000&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
We will discuss the system version tables in another article.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;JSON&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Create JSON string on the fly;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; Department&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FOR&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;JSON&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Added functions are;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
OPENJSON:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; @JSON &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;4000&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; @json &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: red; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;N&#39;[{&quot;DeptID&quot;:1,&quot;DeptName&quot;:&quot;Dept
1&quot;,&quot;ManagerID&quot;:1,&quot;SysStartTime&quot;:&quot;2017-02-09T08:54:49.6660045&quot;,&quot;SysEndTime&quot;:&quot;9999-12-31T23:59:59.9999999&quot;},{&quot;DeptID&quot;:2,&quot;DeptName&quot;:&quot;D2&quot;,&quot;ManagerID&quot;:1,&quot;SysStartTime&quot;:&quot;2017-02-09T08:54:18.6513263&quot;,&quot;SysEndTime&quot;:&quot;9999-12-31T23:59:59.9999999&quot;},{&quot;DeptID&quot;:3,&quot;DeptName&quot;:&quot;D3&quot;,&quot;ManagerID&quot;:1,&quot;SysStartTime&quot;:&quot;2017-02-09T09:03:01.9862457&quot;,&quot;SysEndTime&quot;:&quot;9999-12-31T23:59:59.9999999&quot;}]&#39;&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;OPENJSON&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; @json&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; a&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
We can also work with multiple records in a json string. In
order to link the data in Jason strings to its respective Jason string;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;OPENJSON&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; @json&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; a&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Cross&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;Apply&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;OPENJSON&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background: white; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
As you can see in the upper query, the cross apply is used
to parse the complete data in the JSON string with multiple records.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/4455729000915229658/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/sql-server-2016-t-sql-enhancements.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/4455729000915229658'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/4455729000915229658'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/sql-server-2016-t-sql-enhancements.html' title='SQL Server 2016 T-SQL Enhancements'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-5314554908986676770</id><published>2017-02-08T04:36:00.000-08:00</published><updated>2017-02-08T04:37:02.961-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2016"/><category scheme="http://www.blogger.com/atom/ns#" term="SSMS"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><title type='text'>Cycle Clipboard Ring SQL Server 2016</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
We have a new feature “Cycle Clipboard ring” in SQL Server
management studio SSMS 13.0.16100.1. This new feature of SSMS allows you to toggle
between what you have copied on the clipboard.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
For example, if you copy something from one query window;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Use&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp; DBNAME&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Go&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; Table1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Then copy another command from another query window;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Use&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp; DBNAME2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Go&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; TableName2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Now open a third query window and press CTRL+SHIFT+V; you
will see one of the items from above. Keep holding CTRL+SHIFT and re-press “V”
and you will see other item from the clipboard. This happens as the anything
copied on the clipboard, it goes into the ring and it keeps rotating with the
key combination on CTRL+SHIFT+V.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
PS: Anything copied outside from SSMS before opening SSMS is
also the part of this ring.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/5314554908986676770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/cycle-clipboard-ring-sql-server-2016.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5314554908986676770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5314554908986676770'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/cycle-clipboard-ring-sql-server-2016.html' title='Cycle Clipboard Ring SQL Server 2016'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-3945523178824918209</id><published>2017-02-02T23:26:00.003-08:00</published><updated>2017-02-02T23:47:27.100-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DATALENGTH"/><category scheme="http://www.blogger.com/atom/ns#" term="LEN"/><category scheme="http://www.blogger.com/atom/ns#" term="Script"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2014"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><title type='text'>LEN and DATALENGTH</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
LEN function is very commonly used function in t-sql. One
thing to note in this function that is ignores the trailing blanks;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;VarChar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;5&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;ati &#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;Len&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Same goes for CHAR and NVARCHAR.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
To overcome this, use and character at the end and minus 1
from the length &lt;span style=&quot;font-family: &amp;quot;wingdings&amp;quot;; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;&quot;&gt;J&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;VarChar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;5&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;ati &#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;?&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;Len&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)-&lt;/span&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Some people might use
DATALENGTH function;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;VarChar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;5&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;ati &#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;DATALENGTH&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
But be alert as
DATALENGTH function counts the bytes, not the length. If you change the data
type of @v from varchar to nvarchar, the result will change;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; N&lt;span style=&quot;color: blue;&quot;&gt;VarChar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;5&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;ati &#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;DATALENGTH&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@v&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Thanks for reading.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraph&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/3945523178824918209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/len-and-datalength.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/3945523178824918209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/3945523178824918209'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/len-and-datalength.html' title='LEN and DATALENGTH'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-5961248987374413253</id><published>2017-02-02T04:26:00.001-08:00</published><updated>2017-02-02T04:26:27.474-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Open Transactions"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><category scheme="http://www.blogger.com/atom/ns#" term="Transactions"/><title type='text'>XACT_ABORT V/S TRY .. CATCH</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
Few days back we witnessed an issue that the SQL Server was
running slow. We investigated and soon found out that there were uncommitted
transactions on the server. We re-confirmed those transactions from the
developers and resolved the issue. Someone tossed the idea to apply SET &amp;nbsp;XACT_ABORT ON in all SPs so that this
situation may not occur again. That made me to write this article so that I can
explain the pros and cons of SET XACT_ABORT ON option. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
SET XACT_ABORT ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
As many of you already know that this options just takes the
whole batch a one transaction. If any of the statement in the batch fails, the transaction
of the whole batch is rolled back. Commits in case of success. Simple. But not that
simple. You cannot control the flow of transaction with if XACT_ABORT is ON.
TRY .. CATCH will not work. Even if you have the error log is implemented in
CATCH block, it will not be saved as it will also get rolled backed. So, DB end
error log is gone. In some cases you may need to continue with the rest of your
code in case of an error, for example return a dataset. You cannot do this as
well. The plus point you will never have an open transaction on your server.
All transactions will either commit or rollback. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Another way to handle an open transaction issue is to apply
TRY .. CATCH in all SPs. Ok, I know. There are few limitations of TRY .. CATCH.
TRY .. CATCH do not catch the schema related errors. It will return an error without
hitting CATCH block where you have rolled back opened transaction in case of a
schema error (table does not exists, etc ). Check the code below;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;-- Table does not exist; object name resolution&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;-- error not caught.&amp;nbsp;
&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;begin&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Tran&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;NonexistingTable&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;commit&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;rollback&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;ERROR_NUMBER&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorNumber&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ERROR_MESSAGE&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorMessage&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@TRANCOUNT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Execute the above statements. You will end up with an opened
transaction. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can also try this in a stored procedure. You will still
end up in an open transaction.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Bow add SET XACT_ABORT ON;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;XACT_ABORT&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;ON&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;-- Table does not exist; object name resolution&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;-- error not caught.&amp;nbsp;
&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;begin&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Tran&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;NonexistingTable&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;commit&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;rollback&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;ERROR_NUMBER&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorNumber&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ERROR_MESSAGE&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorMessage&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@TRANCOUNT&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Your transaction will be rolled back and you will find no
open transaction.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
CONCLUSION&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
XACT_ABORT ON solves the open transaction issue but at the
cost of logging implemented in CATCH block (if you have any). &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
But “&lt;span style=&quot;color: teal; font-family: Consolas; font-size: 9.5pt; line-height: 107%;&quot;&gt;NonexistingTable&lt;/span&gt;” type of issues should
not be in the production environment. Like why will I deploy a SP using a table
that does not exists? Strange thing for me. You should have QA in place and
your deployment scripts should be verified before running in the production environment.
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;You decide.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/5961248987374413253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/xactabort-vs-try-catch.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5961248987374413253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5961248987374413253'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/xactabort-vs-try-catch.html' title='XACT_ABORT V/S TRY .. CATCH'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-7290794981074653327</id><published>2017-02-01T05:57:00.002-08:00</published><updated>2017-02-02T03:48:37.779-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SET LANGUAGE. SET DATEFIRST"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><title type='text'>SET DATEFIRST and SET LANGUAGE</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
This is a tricky part. SQL Server have language settings at
the following levels;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;1.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Server&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;2.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;User Login&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;3.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Session&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You need to be very clear for the language settings of the
user / login as it may impact the date functions;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@Today&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;DATETIME&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@Today&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;getdate&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;();&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;LANGUAGE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Italian&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;DATENAME&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;month&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@Today&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Month Name&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@DATEFIRST&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;LANGUAGE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;us_English&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;DATENAME&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;month&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@Today&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Month Name&#39;&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@DATEFIRST&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;LANGUAGE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;British&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;DATENAME&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;month&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@Today&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Month Name&#39;&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@DATEFIRST&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;LANGUAGE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;us_English&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
As you can see from the above code, I have set the language
back to US English (English in SQL Server language drop downs) as I like to
have it that way. You also see that &lt;span style=&quot;color: magenta; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt; line-height: 107%;&quot;&gt;@@DATEFIRST&lt;/span&gt; function returns
different value for different languages. This value is set on the basis of;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l1 level1 lfo2; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;1.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Language selected&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l1 level1 lfo2; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;2.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;SET DATEFIRST option&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can change the language and still keep the First date of
week same as in US English;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;LANGUAGE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;us_English&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@DATEFIRST&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;LANGUAGE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;British&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@DATEFIRST&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;DATEFIRST&lt;/span&gt; 7&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@DATEFIRST&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
As you can see, US_English sets the &lt;span style=&quot;color: magenta; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt; line-height: 107%;&quot;&gt;@@DateFirst&lt;/span&gt;
to 7 and British sets it to 1. But we have used SET DATEFIRST to change the
language to British but kept &lt;span style=&quot;color: magenta; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt; line-height: 107%;&quot;&gt;@@DATEFIRST&lt;/span&gt;&amp;nbsp; to 7 using SET DATEFIRST option.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
This is very important when you are working multilingual
databases. Where ever you are using day of week values (in DatePart, etc), you
should keep this change in mind as well. Either use one language throughout
your database for Server, users and session. But if there might be any change to
get the benefit of SQL Server multilingual support, you should use SET
DATEFIRST into account when programming to keep all the calculations and checks
aligned.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/7290794981074653327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/set-datefirst-and-set-language.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7290794981074653327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7290794981074653327'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/02/set-datefirst-and-set-language.html' title='SET DATEFIRST and SET LANGUAGE'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-8893480864587624964</id><published>2017-01-30T05:53:00.000-08:00</published><updated>2017-02-02T03:49:56.934-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><category scheme="http://www.blogger.com/atom/ns#" term="xp_fileexist"/><title type='text'>xp_fileexist And its Alternate</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
xp_fileexists is a very useful undocumented stored procedure
of SQL Server.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
The usage of xp_fileexist is as follow;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Exec xp_fileexist “E:\abc.txt”&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
The values returned are&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFBN5VvyRcXRs6jeLA3rPDN6f-y61GzQVjN7TQFzefBOLj4zFaqfR3sx1ioc7Dvv15NX6n-dB2-9Whr6SdHa5rldesE1ux0Nez_45my2ARum7BFnBw1heUWJ9_M5lLJC-inTTt2eAk3P9R/s1600/xpFileExists1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFBN5VvyRcXRs6jeLA3rPDN6f-y61GzQVjN7TQFzefBOLj4zFaqfR3sx1ioc7Dvv15NX6n-dB2-9Whr6SdHa5rldesE1ux0Nez_45my2ARum7BFnBw1heUWJ9_M5lLJC-inTTt2eAk3P9R/s1600/xpFileExists1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can also use OUTPUT parameter to get the value of “File
Exists” column as below;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vFileExists&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;exec&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;xp_fileexist&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;E:\abc.txt&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vFileExists&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;OUTPUT&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vFileExists&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
If you want to save all three returned values, then you will
have to go throu Temp Table approach;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vFileExists&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Table &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;FileExists&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;FileDir&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ParentDirExists&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;insert&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;into&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vFileExists&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;exec&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;xp_fileexist&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;E:\abc.txt&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vFileExists&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Sometimes xp_fileexist behaves abnormally. Your file is
there and it does not check the file and returns 0 in FileExists column. This
is an extended SP so its behavior may also change with different versions of
SQL Server.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
If you are facing the same problem, change you code with
xp_cmdshell “dir” approach;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExistsPath&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@files&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Table &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[FileName]&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;))&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExistsPath&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExistsPath&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;E:\abc.txt&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExistsPath&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;dir &#39;&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExistsPath&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39; /b&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Insert&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;into&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@files&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: maroon;&quot;&gt;xp_cmdshell&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@vExistsPath&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@files&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;Exists(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; 1 &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@files&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;[FileName]&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;abc.txt&#39;&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;And&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;[FileName]&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Not&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Null)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;begin&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;begin&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
The “/b” switch returns only filename with extension as a
result of “dir” command&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/8893480864587624964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/01/xpfileexist-and-its-alternate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/8893480864587624964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/8893480864587624964'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/01/xpfileexist-and-its-alternate.html' title='xp_fileexist And its Alternate'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFBN5VvyRcXRs6jeLA3rPDN6f-y61GzQVjN7TQFzefBOLj4zFaqfR3sx1ioc7Dvv15NX6n-dB2-9Whr6SdHa5rldesE1ux0Nez_45my2ARum7BFnBw1heUWJ9_M5lLJC-inTTt2eAk3P9R/s72-c/xpFileExists1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-5292116083156203148</id><published>2017-01-30T05:52:00.000-08:00</published><updated>2017-01-30T05:52:45.605-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Adhoc Query"/><category scheme="http://www.blogger.com/atom/ns#" term="CSV"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><title type='text'>Handeling comma while creating CSV</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: 12.0pt;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;segoe ui&amp;quot; , sans-serif; font-size: 10.5pt;&quot;&gt;I would recommend you
should NOT use comma &#39;,&#39; in your csv as I think you are facing issues because
of &#39;,&#39; in the data of your text column. Instead you can use &#39;|&#39; sign.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: white; border: solid #888888 1.0pt; mso-border-alt: solid #888888 .75pt; mso-element: para-border-div; padding: 2.0pt 2.0pt 2.0pt 2.0pt;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;&quot;&gt;
&lt;span style=&quot;border: none 1.0pt; color: #000088; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;EXECUTE&lt;/span&gt;&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt; master&lt;/span&gt;&lt;span style=&quot;border: none 1.0pt; color: #666600; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;border: none 1.0pt; color: #666600; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;xp_cmdshell &lt;/span&gt;&lt;span style=&quot;border: none 1.0pt; color: #008800; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;&#39;bcp &quot;SELECT Column1,
Column2, Column3 FROM YourDB.[dbo].[YourTable] ORDER BY 1&quot; queryout
E:\Objects3.txt -t&quot;|&quot; -c -T &#39;&lt;/span&gt;&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;border: none 1.0pt; color: #333333; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 8.0pt; padding: 0in;&quot;&gt;if you still want to use comma as separator due to any limitation,
you can use char(34) before and after the column that you think may have comma
in the text. Adding char(34) i.e. double quote, will make the text with comma
as a single value.&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;segoe ui&amp;quot; , sans-serif; font-size: 10.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;border: none 1.0pt; color: #333333; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 8.0pt; padding: 0in;&quot;&gt;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;segoe ui&amp;quot; , sans-serif; font-size: 10.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: white; border: solid #888888 1.0pt; mso-border-alt: solid #888888 .75pt; mso-element: para-border-div; padding: 2.0pt 2.0pt 2.0pt 2.0pt;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: normal; margin-bottom: 0.0001pt; padding: 0in;&quot;&gt;
&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;EXECUTE master&lt;/span&gt;&lt;span style=&quot;border: none 1.0pt; color: #666600; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;border: none 1.0pt; color: #666600; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;xp_cmdshell &lt;/span&gt;&lt;span style=&quot;border: none 1.0pt; color: #008800; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt; padding: 0in;&quot;&gt;&#39;bcp &quot;SELECT Column1,
char(34) + Column2 + char(34) , Column3 FROM YourDB.[dbo].[YourTable] ORDER BY
1&quot; queryout E:\Objects3.txt -t&quot;,&quot; -c -T &#39;&lt;/span&gt;&lt;span style=&quot;border: 1pt none; font-family: inherit , serif; font-size: 10.5pt; padding: 0in;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;inherit&amp;quot; , serif; font-size: 10.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;segoe ui&amp;quot; , sans-serif; font-size: 10.5pt;&quot;&gt;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12.0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: 12.0pt;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;segoe ui&amp;quot; , sans-serif; font-size: 10.5pt;&quot;&gt;The above code assumes
that you have comma in Column 2 and file created is comma separated CSV.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: 12.0pt;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;segoe ui&amp;quot; , sans-serif; font-size: 10.5pt;&quot;&gt;I hope it will help
you.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/5292116083156203148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/01/handeling-comma-while-creating-csv.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5292116083156203148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5292116083156203148'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/01/handeling-comma-while-creating-csv.html' title='Handeling comma while creating CSV'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-8298424174199438100</id><published>2017-01-23T02:58:00.004-08:00</published><updated>2017-01-23T03:07:12.969-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Adhoc Query"/><category scheme="http://www.blogger.com/atom/ns#" term="OLEDB"/><title type='text'>Microsoft.ACE.OLEDB.12.0 Issues and their solution</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
Few OLEDB issues that I would like to share;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;&lt;b&gt;1.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; font-weight: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;!--[endif]--&gt;&lt;b&gt;Msg 7415, Level 16, State 1, Line 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;b&gt;Ad
hoc access to OLE DB provider &#39;Microsoft.ACE.OLEDB.12.0&#39; has been denied. You
must access this provider through a linked server.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
If you see this message with your OLEDB query,
it means you do not have sufficient rights on the OLEDB source. Please check
your user have enough rights to access the OLEDB provider. The provider must
show in the list of providers as below;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG-JjYOFtoUVzGvVsZunSSCDTeebrsOQ_7yKbgILtQfNu6RI66_ekL0AGj9mbtGdi4GY3Q43UtR4UYpJtJfbabGVZlTm2dJhHnQQT_jLcmKqKypCTXeema_IxRqVAqUbS5EM43swxV8Dpv/s1600/OLEDB1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG-JjYOFtoUVzGvVsZunSSCDTeebrsOQ_7yKbgILtQfNu6RI66_ekL0AGj9mbtGdi4GY3Q43UtR4UYpJtJfbabGVZlTm2dJhHnQQT_jLcmKqKypCTXeema_IxRqVAqUbS5EM43swxV8Dpv/s1600/OLEDB1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shapetype
 id=&quot;_x0000_t75&quot; coordsize=&quot;21600,21600&quot; o:spt=&quot;75&quot; o:preferrelative=&quot;t&quot;
 path=&quot;m@4@5l@4@11@9@11@9@5xe&quot; filled=&quot;f&quot; stroked=&quot;f&quot;&gt;
 &lt;v:stroke joinstyle=&quot;miter&quot;/&gt;
 &lt;v:formulas&gt;
  &lt;v:f eqn=&quot;if lineDrawn pixelLineWidth 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 1 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum 0 0 @1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @2 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 0 1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @6 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;sum @8 21600 0&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @10 21600 0&quot;/&gt;
 &lt;/v:formulas&gt;
 &lt;v:path o:extrusionok=&quot;f&quot; gradientshapeok=&quot;t&quot; o:connecttype=&quot;rect&quot;/&gt;
 &lt;o:lock v:ext=&quot;edit&quot; aspectratio=&quot;t&quot;/&gt;
&lt;/v:shapetype&gt;&lt;v:shape id=&quot;Picture_x0020_1&quot; o:spid=&quot;_x0000_i1026&quot; type=&quot;#_x0000_t75&quot;
 style=&#39;width:197.25pt;height:198.75pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot;&gt;
Secondly, right click the provider and check
“Disallow adhoc Access”. It should be &lt;b&gt;unchecked&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;&lt;b&gt;2.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; font-weight: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;!--[endif]--&gt;&lt;b&gt;Msg 7302, Level 16, State 1, Line 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;b&gt;Cannot
create an instance of OLE DB provider &quot;Microsoft.ACE.OLEDB.12.0&quot; for
linked server &quot;(null)&quot;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
Check the above issues stated in point 1.
If above settings are good, and still getting this error, then it your syntax.
Please check the correct syntax to query using the Provider. For example, to
query excel file, the correct syntax is;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 1.0in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 1.0in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;OPENROWSET&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;Microsoft.ACE.OLEDB.12.0&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 1.5in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none; text-indent: .5in;&quot;&gt;
&lt;span style=&quot;color: red; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&#39;Excel 12.0;Database=F:\FleName.xlsx&#39;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&#39;select * from [sheet1$]&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none; text-indent: .5in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;For csv, the syntax is;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none; text-indent: .5in;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;OPENROWSET &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;Microsoft.ACE.OLEDB.12.0&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&#39;Text;Database=E:\&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&#39;SELECT * from FileName.csv&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;Please
note that in case of excel, File name is give in the “Database” property and
sheet name is given in the “Select * from [sheet1$]” statement.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;In
case of csv, only path is given for “Database” property and file name is given
in the “Select * from Filaname.csv” part.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;3.&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-size: 7pt; font-stretch: normal; font-weight: normal; line-height: normal;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;!--[endif]--&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;OLE DB provider &#39;Microsoft.ACE.OLEDB.12.0&#39; cannot be used for
distributed queries because the provider is configured to run in
single-threaded apartment mode.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;You need to install 64
bit or 32 bit Access driver depending upon the operating system that you have
on the machine where you are running the query to access the excel or csv file.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;&lt;b&gt;4.&lt;span style=&quot;font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; font-weight: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;!--[endif]--&gt;&lt;b&gt;Few columns returning NULL in the dataset&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
You might see this issue where your values
are turning into NULL. If you look deeply into your data, you will notice that
the values in the column are numbers (not alpha numeric charachters) and the
values that are alpha numeric in the parent file are turning into NULL. This is
because the data type of the column is determined based up on the first few
data values in the column. If these are numbers, the datatype will be set to “int”
and all character values will be saved as NULL.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
To solve this issue, you need to do some
changes in the registry as shown in the screen below;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape
 id=&quot;Picture_x0020_2&quot; o:spid=&quot;_x0000_i1025&quot; type=&quot;#_x0000_t75&quot; style=&#39;width:467.25pt;
 height:135pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:\Users\DELL\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-bJnON1Wxg0N5wiqES1AXA_hK7v04WL6lDMWg-S0K4BjU8wR49tHC9DMEYABZeQwBINCqPHx5vnID0IE4fYdOEDw2QG0c_LiLjEPqm47iviAk5fNikWWSasyx_Xe6m1JLT_J5YM00pQtg/s1600/OLEDB2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;194&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-bJnON1Wxg0N5wiqES1AXA_hK7v04WL6lDMWg-S0K4BjU8wR49tHC9DMEYABZeQwBINCqPHx5vnID0IE4fYdOEDw2QG0c_LiLjEPqm47iviAk5fNikWWSasyx_Xe6m1JLT_J5YM00pQtg/s640/OLEDB2.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
Open registry of the server in which you
are processing the csv / Excel file. Go to the following path;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\15.0\Access
Connectivity Engine\Engines\Text&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
We have selected “Text” as we faced this
issue while processing CSV files. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot;&gt;
Change “ImportMixedTypes” property value to
“Text”. Save the registry. Execute the query again and you will now see all
your data returning as Text. You can no move your data as per your table
schema.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/8298424174199438100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/01/microsoftaceoledb120-issues-and-their.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/8298424174199438100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/8298424174199438100'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2017/01/microsoftaceoledb120-issues-and-their.html' title='Microsoft.ACE.OLEDB.12.0 Issues and their solution'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG-JjYOFtoUVzGvVsZunSSCDTeebrsOQ_7yKbgILtQfNu6RI66_ekL0AGj9mbtGdi4GY3Q43UtR4UYpJtJfbabGVZlTm2dJhHnQQT_jLcmKqKypCTXeema_IxRqVAqUbS5EM43swxV8Dpv/s72-c/OLEDB1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-2991357302280261033</id><published>2014-11-03T07:32:00.000-08:00</published><updated>2014-11-03T07:33:40.336-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AlwaysOn"/><category scheme="http://www.blogger.com/atom/ns#" term="Availability Group"/><category scheme="http://www.blogger.com/atom/ns#" term="Clustering"/><category scheme="http://www.blogger.com/atom/ns#" term="High Availability"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2014"/><title type='text'>Testing, Adding Nodes to Clusters and Adding Replicas to Availability Groups - Part 3</title><content type='html'>You can read this article &lt;a href=&quot;http://www.enpointe.com/blog/testing-adding-nodes-to-clusters-adding-replicas-to-availability-groups-part-3&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/2991357302280261033/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/11/testing-adding-nodes-to-clusters-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2991357302280261033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2991357302280261033'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/11/testing-adding-nodes-to-clusters-and.html' title='Testing, Adding Nodes to Clusters and Adding Replicas to Availability Groups - Part 3'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-3456471488010340002</id><published>2014-11-03T07:31:00.002-08:00</published><updated>2014-11-03T07:33:32.485-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AlwaysOn"/><category scheme="http://www.blogger.com/atom/ns#" term="Availability Group"/><category scheme="http://www.blogger.com/atom/ns#" term="Clustering"/><category scheme="http://www.blogger.com/atom/ns#" term="High Availability"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2014"/><title type='text'>Enabling AlwaysOn and Creating Availability Groups - Part 2</title><content type='html'>You can read this article &lt;a href=&quot;http://www.enpointe.com/blog/enabling-alwayson-creating-availability-groups-part-2&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/3456471488010340002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/11/enabling-alwayson-and-creating.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/3456471488010340002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/3456471488010340002'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/11/enabling-alwayson-and-creating.html' title='Enabling AlwaysOn and Creating Availability Groups - Part 2'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-1372162157965489517</id><published>2014-11-03T07:30:00.001-08:00</published><updated>2014-11-03T07:33:20.797-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AlwaysOn"/><category scheme="http://www.blogger.com/atom/ns#" term="Availability Group"/><category scheme="http://www.blogger.com/atom/ns#" term="Clustering"/><category scheme="http://www.blogger.com/atom/ns#" term="High Availability"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2014"/><title type='text'>Introduction and Creating Windows Cluster - Part 1</title><content type='html'>You can read this article &lt;a href=&quot;http://www.enpointe.com/blog/introduction-creating-windows-cluster-part-1&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/1372162157965489517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/11/introduction-and-creating-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/1372162157965489517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/1372162157965489517'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/11/introduction-and-creating-windows.html' title='Introduction and Creating Windows Cluster - Part 1'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-2606368659694619147</id><published>2014-06-17T11:28:00.000-07:00</published><updated>2014-06-18T07:35:12.204-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="data Model"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Office 365"/><category scheme="http://www.blogger.com/atom/ns#" term="PowerPivot"/><title type='text'>Creating a Power Pivot Data Model in Microsoft Excel 2013</title><content type='html'>&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot;&gt;I was featured on SQL Server Pro for writing an article on&amp;nbsp;&lt;/span&gt;&lt;strong style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot;&gt;creating a Power Pivot Data Model in Microsoft Excel 2013&lt;/strong&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot;&gt;. In the article, I am providing step-by-step instructions for generating complex reports in Excel using a Power Pivot Table, an add-in that allows users to gather, store, model and analyze large amounts of data.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot;&gt;Read the full article&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://sqlmag.com/business-intelligence/creating-power-pivot-data-model-excel-2013&quot; rel=&quot;nofollow&quot; style=&quot;background-color: white; color: #f79321; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14.44444465637207px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/2606368659694619147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/06/creating-power-pivot-data-model-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2606368659694619147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2606368659694619147'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/06/creating-power-pivot-data-model-in.html' title='Creating a Power Pivot Data Model in Microsoft Excel 2013'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-999251808175964669</id><published>2014-05-15T07:11:00.004-07:00</published><updated>2014-05-22T09:48:10.440-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Index"/><category scheme="http://www.blogger.com/atom/ns#" term="Query optimization"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2014"/><title type='text'>SQL Server 2014 – Index Enhancements</title><content type='html'>&lt;h2&gt;
Inline Specification of Clustered and NON-Clustered Indexes&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
SQL Server 2014 is launched and there are many new things
added in the product. DBAs were waiting for a very long time for some of those.
Creating Inline Clustered and NON-Clustered Indexes is one of them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
If you are familiar with T-SQL coding, you should know that
you cannot add NON clustered index while creating a table in CREATE TABLE
statement. The NON-Clustered indexes were to be added after the creation of the
table. Now you can add Non-Clustered indexes in the CREATE TABLE statement. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Some of you say “What’s the PLUS point in this?” Well, I
have myself witnessed that when you are creating the database tables, you are
more involved in the design. Generally, you have all the information regarding
the data that the table is going to hold and the major user queries that are
going to be executed on that table. Point is, that is the best time to decide
to add indexes. You generally do this. But at times, you forget to exclusively
add and run the “CREATE INDEX” statement. This results in an un-wanted delays
and, sometimes, results in the crash, especially when you are reading data for
reports from the tables on which you forgot to add an index. With the ability
of creating Inline Indexes, the chances of such mistakes is even lower now.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
If you execute the following in SQL Server 2012, it will
generate an error;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Use&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;AdventureWorks2012&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Go&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;ID&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;IDENTITY &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;KEY&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;NAME&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;FATHERNAME&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;index&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;idx_FATHERNAME &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
The error will be;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.0pt;&quot;&gt;Incorrect syntax near &#39;index&#39;. If this is intended
as a part of a table hint, A WITH keyword and parenthesis are now required. See
SQL Server Books Online for proper syntax.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
But if you execute the same code in SQL Server 2014 (any
edition), the command will be executed successfully.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can also create composite indexes in the same manner.
Included columns and filtered conditions are not yet supported with Inline
specification of indexes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Use&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;AdventureWorks2012&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Go&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;ID&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;IDENTITY &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;KEY&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;NAME&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;FATHERNAME&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;index&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;idx_FATHERNAME &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;FATHERNAME&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;NAME&lt;span style=&quot;color: grey;&quot;&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2&gt;
Table variable can have an index&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Yes, now we can have an index on a table variable defined in
the T-SQL code. We all know the importance of the table variable. Here is the
example code;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; @vTabletest &lt;span style=&quot;color: blue;&quot;&gt;TABLE&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;IDENTITY &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;KEY&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NAME &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FATHERNAME
&lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;index&lt;/span&gt;
idx_FATHERNAME&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Insert&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;into&lt;/span&gt; @vTabletest &lt;span style=&quot;color: blue;&quot;&gt;values &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;A&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;B&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; @vTabletest&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Again, if you try to execute the above code in SQL Server
2012, it will generate errors.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can also create composite indexes in the same manner.
Included columns and filtered conditions are not yet supported with Inline
specification of indexes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2&gt;
Clustered Columnstore Indexes&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
SQL Server 2014 enables you to create a clustered
columnstore index. In the prior versions, only non-clustered columnstore
indexes were offered.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
In order to create a clustered columnstore index on a table,
first you will have to create a table without any index on it i.e. a heap;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TABLE&lt;/span&gt; tblTest&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NAME &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FATHERNAME
&lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Now, execute the command to create a column stored Index;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CLUSTERED&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;COLUMNSTORE&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;INDEX&lt;/span&gt;
idx_CS_Test &lt;span style=&quot;color: blue;&quot;&gt;on&lt;/span&gt; tbltest&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
The above command converts the table into the clustered
columns store index named idx_CS_test. As you can see in the above statement,
you cannot specify the key list in the index specification as we used to do in
the non-clustered columnstore indexes. This is because the whole table is
converted into the columnstore index.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/999251808175964669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/05/sql-server-2014-index-enhancements.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/999251808175964669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/999251808175964669'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/05/sql-server-2014-index-enhancements.html' title='SQL Server 2014 – Index Enhancements'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-4501290061412306684</id><published>2014-03-18T11:30:00.001-07:00</published><updated>2014-03-18T11:31:09.990-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Migration"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Migration"/><category scheme="http://www.blogger.com/atom/ns#" term="Windows Azure"/><title type='text'>Optimizing SQL Azure Database</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;1. Dynamic Management
Views&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;SQL Azure provides a few
handy system views called dynamic management views (DMVs) that are also
available in SQL Server. SQL Azure exposes a subset of the DMVs, but all those
related to query execution are available. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;sys.dm&lt;i&gt;exec&lt;/i&gt;connections&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;sys.dm&lt;i&gt;exec&lt;/i&gt;query&lt;i&gt;plan&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;i&gt;sys.dm&lt;/i&gt;exec&lt;i&gt;query&lt;/i&gt;stats&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;sys.dm&lt;i&gt;exec&lt;/i&gt;requests&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;sys.dm&lt;i&gt;exec&lt;/i&gt;sessions&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;sys.dm&lt;i&gt;exec&lt;/i&gt;sql&lt;i&gt;text&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;i&gt;sys.dm&lt;/i&gt;exec&lt;i&gt;text&lt;/i&gt;query_plan
&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;2. Connection pooling&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Connection pooling is an
important consideration for performance. Although this statement is generally
accurate in the world of database programming, it becomes critical for SQL
Azure. A poorly designed application may create too many connection requests,
which can end up flooding SQL Azure. If too many connection requests are
established, your connections will be throttled, meaning that you can no longer
connect for a period of time.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;3. Indexes&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Creating the right
indexes can be complex; it can take a long time to fully understand indexing
and fine-tune database queries. One of the most important things to remember
with indexing is that its primary purpose is to help SQL Azure find the data it
needs quickly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Indexes are like smaller
tables that contain a subset of the primary table. The tradeoff is that indexes
consume space and must be maintained by the SQL Azure engine as the primary
data changes, which can impact performance under certain scenarios.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Remember, you must have a clustered index on each table in SQL Azure Database.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Windows Azure SQL
Database does not support tables without clustered indexes.&amp;nbsp;A table must
have a clustered index. If a table is created without a clustered constraint, a
clustered index must be created before an insert operation is allowed on the table.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;4. Indexed views&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Indexed views are an excellent alternative when
you absolutely need to JOIN data, and traditional indexing doesn&#39;t yield the
performance you&#39;re looking for. Indexed views behave like tables; the data
covered is materialized to disk so it can be retrieved quickly. Before jumping
on indexed views, understand that they have certain limitations and that due to
their nature, you may incur a performance hit through the usual Insert, Delete,
and Update statements.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;5. Stored procedures&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;You&#39;ve seen various ways
to tune your statements and improve execution plans. However, keep in mind that
you also have stored procedures at your disposal. Stored procedures can give
you an edge if you need to execute logic that requires a large volume of data.
Because you know that returning lots of data turns into a performance problem
in SQL Azure, you can place the business logic that needs the data in a stored
procedure, and have the procedure return a status code. Because you aren&#39;t
charged for CPU time, this becomes an affordable option.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Stored procedures can
also be an interesting security tool, allowing you proxy the calls to
underlying tables through a procedure and never allowing direct access to the
tables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;There are a few
restrictions in SQL Azure Stored Procedures. You cannot use the following in
CREATE PROCEDURE statement;&lt;/span&gt;&lt;span style=&quot;font-size: 13.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul style=&quot;margin-top: 0in;&quot; type=&quot;disc&quot;&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;FOR
     REPLICATION option&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;EXTERNAL
     NAME ( external methods)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;ENCRYPTION
     option&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Also, following XML
commands doe not work in SQL Azure;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;margin-top: 0in;&quot; type=&quot;disc&quot;&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;sp_xml_preparedocument&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;sp_xml_removedocument&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;OpenXML&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;We have the workaround
to tackle with these commands but that is not in the scope of this article.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;NOTE: Reference taken
from http://programming4.us/&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/4501290061412306684/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/03/optimizing-sql-azure-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/4501290061412306684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/4501290061412306684'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/03/optimizing-sql-azure-database.html' title='Optimizing SQL Azure Database'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-8852111232646913498</id><published>2014-03-18T07:03:00.003-07:00</published><updated>2014-05-15T07:13:29.332-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Analysis Services 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="Business Intelligence"/><category scheme="http://www.blogger.com/atom/ns#" term="Corporate BI"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><category scheme="http://www.blogger.com/atom/ns#" term="Self-Service BI"/><category scheme="http://www.blogger.com/atom/ns#" term="SSAS"/><category scheme="http://www.blogger.com/atom/ns#" term="Tabular Model"/><title type='text'>Introducing Tabular Model - Self-Service Business Intelligence</title><content type='html'>Tabular Model is a new feature in SQL Server 2012. Tabular models are in-memory databases in Analysis Services. They use state-of-the-art compression algorithm and multi-threaded query processors named as VertpPaq (xVelocity in-memory analytics engine). This enable fast access to tabular objects and data by reporting applications such as MS Excel.&lt;br /&gt;
&lt;br /&gt;
Tabular Models are created in SQL Server Data Tools (SSDT). It is the upgraded version of BI developer. SSDT is also used to develop Reports, Integration Services and Multidimensional projects. Tabular Model project is deployed as Analysis Services database just like Multidimensional projects. In Tabular Model, we can add partitions for optimization purposes. Row-level security can also be implemented in Tabular Model. We can also import external data to make it a part of the model. We can add relationships, measures and calculated columns on the tabular data in the model. Hierarchies are also supported in Tabular model as in multidimensional model. This makes it more do-able and easy to go with project type in SSAS. As Tabular Model is deployed as Analysis Services database, client applications can connect to the deployed model for reporting purposes.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Analysis services provides three approaches to develop business intelligence semantic models;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
1. Tabular&lt;/div&gt;
&lt;div&gt;
2. Multidimensional&lt;/div&gt;
&lt;div&gt;
3. PowerPivot&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Tabular Model is based on relational structure such as tables and relationships for modeling of data. Multidimensional and data mining are based on OLAP (cubes and dimensions). PowerPivot is a self-service BI tool.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Tabular Model support data access through two modes;&lt;/div&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Cached Mode&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&amp;nbsp;In cached mode, you can integrate data from multiple sources including relational databases, data feeds, and flat text files.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Direct-Query Mode&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&amp;nbsp;In this mode, you can by-pass the In-Memory model and allow cklient applications to query directly from the relational database.
In short, Tabular model is designed to query huge data with much lesser response time in different client application, especially in MS Excel.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b&gt;Comparing With Multidimensional Model&lt;/b&gt;&lt;br /&gt;
With the release of Tabular Model, there are few decisions by Managers that has to be made. Some common questions are;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Question 1: When to use Tabular Model and Multidimensional Model?&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Answer:&lt;/b&gt; Both Tabular and Multidimensional Models are the part of Analysis Services. Bot are developed in SSDT. The answer lies within the data to be used in the model. If you have huge data, like in TBs, to process in the model, then Multidimensional Model is the best suite for you. Tabular Model are more compressed than Multidimensional but it also requires more memory to load and process the data in memory. PowerPivot Models are for even lesser data size.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Question 2: What do we mean by &#39;External Data&#39; or &#39;External Source&#39;?&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Answer: &lt;/b&gt;We can import data in Tabular Model and PowerPivot from&lt;b&gt;&amp;nbsp;&lt;/b&gt;External sources. These can be text files, excel files, data feeds and even some document formats. In multidimensional, you can only load data from relational sources using OLEDB and managed providers.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Question 3: What is the core benefit of Tabular Model?&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Answer: &lt;/b&gt;&amp;nbsp;The core benefit is that they are easy to implement as PowerPivot. You can develop more efficient and effective solution. The data processing is very fast and it is easy to understand, It uses DAX as programming language. DAX is quite similar to Excel formula language. &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Question 4: Should we convert the current Multidimensional Models to Tabular?&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Answer: &lt;/b&gt;NO. The project types are not interchangeable. And it will not be an effective decission to convert the multidimensional model into Tabular model. It is best to use the model for the new requirements.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Analysis Services 2012 Two in One Product&lt;/b&gt;&lt;br /&gt;
Most important aspect of Analysis Services 2012 is that it is two products in one. In SQL Server 2008 R2 and before, we only had Multidimensional Model option in Analysis services. But in SQL Server 2012, you can choose between Multidimensional and Tabular Model while installing SSAS instance. You need to have separate instance for both if you want to use both, multidimensional and tabular model.
In the figure below, you can see that on Feature selection page, there is only one selection for Analysis Services;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAPflEGT9g5M3jocgzKE9q7gFpF_p7HWSbo7XXXBfI7xTEZNkExVx5v1jbAj1lzUESplW-9jhRH_GPCaKFgBhcAC-DiFJWVnarQfduCrfMiDiKiCFdzrUk77_dHMIiUBsUmvi8pHtMbvun/s1600/FeatureSelection.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAPflEGT9g5M3jocgzKE9q7gFpF_p7HWSbo7XXXBfI7xTEZNkExVx5v1jbAj1lzUESplW-9jhRH_GPCaKFgBhcAC-DiFJWVnarQfduCrfMiDiKiCFdzrUk77_dHMIiUBsUmvi8pHtMbvun/s320/FeatureSelection.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
But when you pass on to the Analysis configuration page, there you will see a radio button for Server Mode selection. The options are;

a. Multidimensional and Data Mining Mode
b. Tabular Mode
 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_GzjL1UF73dFFgnh4wQp83IIob1jRJip1hXxPPPZ7bAjpr92aTem2-ub8-m7zaY5B8WMCmY_246nL6YMD6EZ6XauGbziy5XIhF7RybMCuT_RAWRaSjTGtSqRGpw5i8uY0Zz98i6huNDw7/s1600/ServerMode.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_GzjL1UF73dFFgnh4wQp83IIob1jRJip1hXxPPPZ7bAjpr92aTem2-ub8-m7zaY5B8WMCmY_246nL6YMD6EZ6XauGbziy5XIhF7RybMCuT_RAWRaSjTGtSqRGpw5i8uY0Zz98i6huNDw7/s320/ServerMode.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Licensing&lt;/b&gt;&lt;br /&gt;
Analysis services 2012 is available in the following editions of SQL Server;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;SQL Server Standard Edition&amp;nbsp;&lt;/li&gt;
&lt;li&gt;SQL Server BI Edition&amp;nbsp;&lt;/li&gt;
&lt;li&gt;SQL Server Enterprise Edition&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
In SQL Server Standard edition, you can only have Multidimensional Mode. SQL Server BI edition and SQL Server Enterprise editions have both Multidimensional and Tabular Mode. In terms of Analysis Services functionality, these two editions are the same; the only difference between them is that SQL Server Business Intelligence edition licensing is based on buying a server license plus Client Access Licenses (CALs), whereas SQL Server Enterprise edition is licensed on a per-CPU core basis. (You can no longer license SQL Server Enterprise edition on a server-plus-CALs basis as was possible in the past.) In SQL Server Business Intelligence and SQL Server Enterprise editions, both Tabular and Multidimensional models contain all available features and can use as many cores as the operating system makes available.

The upshot of this is that it could be more expensive in some situations to use Tabular than
Multidimensional because Multidimensional is available in SQL Server Standard edition and Tabular is not. If you have a limited budget, already have existing Multidimensional skills, or are willing to learn them, and your data volumes mean that you do not need to use Multidimensional features such as partitioning, it might make sense to use Multidimensional and SQL Server Standard edition to save money. If you are willing to pay slightly more for SQL Server Business Intelligence edition or SQL
Server Enterprise edition, however, then licensing costs should not be a consideration in your choice of model.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;b&gt;A hint to Self-Service BI and Corporate BI&lt;/b&gt;&lt;br /&gt;
Over the last few years, trends and demand of BI have significantly changed. Now, users are more interested in having the hold on their data and analyze it according to their own run-time requirement on the spot. Prior to that, they had to involve an IT professional to develop complex reports for them. This is Corporate BI. This scenario still exists but for analysis work, it becomes more cost and time consuming for engaging IT professional for the analysis work. This resulted in a new Self-Service BI. There are tools available in the market like QlikView and Tableu that enables users to query their own data in a user friendly interface. Analysis Services is a corporate-BI tool by MS as you need an IT professional to design and build an Analysis Services database. There are disadvantages of self-service BI like poor-quality data, lack of integration between multiple source systems, etc. Still, self-service BI is high on demand and the reason is that most of the data users think that in most cases, the time consuming step of creating a data warehouse is un-necessary in their initial scenario. MS, as a software company could not ignore this market demand, so in 2010, it released its own serf service BI tool, PowerPivot. Tabular Model resembles a lot to PowerPivot and a refined version of PowerPivot as you get the scalability and manageability in the Tabular Model. PowerPivot is more Agile and Self-Service BI tool.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/8852111232646913498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/03/introducing-tabular-model-self-service.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/8852111232646913498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/8852111232646913498'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2014/03/introducing-tabular-model-self-service.html' title='Introducing Tabular Model - Self-Service Business Intelligence'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAPflEGT9g5M3jocgzKE9q7gFpF_p7HWSbo7XXXBfI7xTEZNkExVx5v1jbAj1lzUESplW-9jhRH_GPCaKFgBhcAC-DiFJWVnarQfduCrfMiDiKiCFdzrUk77_dHMIiUBsUmvi8pHtMbvun/s72-c/FeatureSelection.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-7896653114286550110</id><published>2013-12-10T09:18:00.001-08:00</published><updated>2014-03-18T07:34:11.083-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Adhoc Query"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><title type='text'>Comparing File Names in a directory with the list in Excel File</title><content type='html'>Here is the Script...&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;---- Get File Names rom you directory&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vOSFiles&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Table &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;MyFileName&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;1000&lt;span style=&quot;color: grey;&quot;&gt;),&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;MyDepth&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;IsFile&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;bit&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Insert&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;into&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vOSFiles&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;EXEC&lt;/span&gt; &lt;span style=&quot;color: maroon;&quot;&gt;xp_dirtree&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;G:\Atif\&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; 1&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--Select * from @vOSFiles where IsFile
= 1&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;---- Get List of Files from Excel&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;----&amp;nbsp;
Insert Excel File list to another Temp Table. &lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;---- The structure o fthis table
depends upon you excel file and requirement&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExcelFileList&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Table &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;MyFileName&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;1000&lt;span style=&quot;color: grey;&quot;&gt;))&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;---- This is for xlsx files &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Insert&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;into&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExcelFileList&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;[MyFileName]&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;OPENROWSET&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;Microsoft.ACE.OLEDB.12.0&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&#39;Excel 12.0 Xml;Database=G:\Budjet.xlsx;HDR=Yes;IMEX=1&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;&#39;SELECT * FROM [Sheet2$]&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--Select * &lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--from @vOSFiles&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;---- Join the two tables on the File
Names&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.*,&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;MyFileName&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;not&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Null&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;then&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Exists&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Else&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Not Exists&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;FileExistance&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vOSFiles&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;a&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Left&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;Outer&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Join&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vExcelFileList&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;b&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;on&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;MyFileName&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;MyFileName&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Where&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;IsFile&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;
1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;You might want to enable ad hoc query options;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;---- Enable AdHoc Queries&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--USE MSDB&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--sp_configure &#39;show advanced options&#39;,
1;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--RECONFIGURE;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--sp_configure &#39;Ad Hoc Distributed
Queries&#39;, 1;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--RECONFIGURE;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;---- Add OLEDB referance for xlsx&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--EXEC master.dbo.sp_MSset_oledb_prop
N&#39;Microsoft.ACE.OLEDB.12.0&#39;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--&amp;nbsp;&amp;nbsp;&amp;nbsp;
, N&#39;AllowInProcess&#39;, 1&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--EXEC master.dbo.sp_MSset_oledb_prop
N&#39;Microsoft.ACE.OLEDB.12.0&#39;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--&amp;nbsp;&amp;nbsp;&amp;nbsp;
, N&#39;DynamicParameters&#39;, 1&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;--GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;











































&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
For XLS files (earlier 2007 versions of Excel), you can run the OpenRowset query as;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;OPENROWSET&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;Microsoft.Jet.OLEDB.4.0&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: red; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&#39;Excel 4.0;Database=G:\Budjet.xls&#39;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: red; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&#39;SELECT * FROM
[sheet2$]&#39;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;a href=&quot;http://www.tkqlhce.com/click-7351013-10655704&quot; target=&quot;_top&quot;&gt;5% OFF All Lenovo ThinkPad&#39;s. Coupon Code:CJDEC5UK &lt;/a&gt;&lt;img border=&quot;0&quot; src=&quot;http://www.awltovhc.com/image-7351013-10655704&quot; height=&quot;1&quot; width=&quot;1&quot; /&gt;

&lt;a href=&quot;http://www.dpbolvw.net/click-7351013-10662243&quot; target=&quot;_top&quot;&gt;Lenovo UK Homepage&lt;/a&gt;&lt;img border=&quot;0&quot; src=&quot;http://www.awltovhc.com/image-7351013-10662243&quot; height=&quot;1&quot; width=&quot;1&quot; /&gt;

&lt;a href=&quot;http://www.tkqlhce.com/click-7351013-10911615&quot; target=&quot;_top&quot;&gt;
&lt;img alt=&quot;www.1and1.co.uk&quot; border=&quot;0&quot; src=&quot;http://www.tqlkg.com/image-7351013-10911615&quot; height=&quot;60&quot; width=&quot;468&quot; /&gt;&lt;/a&gt;

&lt;a href=&quot;http://www.tkqlhce.com/click-7351013-11060117&quot; target=&quot;_top&quot;&gt;
&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://www.ftjcfx.com/image-7351013-11060117&quot; height=&quot;150&quot; width=&quot;180&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.anrdoezrs.net/click-7351013-10657364&quot; target=&quot;_top&quot;&gt;
&lt;img alt=&quot;5% OFF All Lenovo ThinkPad&#39;s.&quot; border=&quot;0&quot; src=&quot;http://www.tqlkg.com/image-7351013-10657364&quot; height=&quot;90&quot; width=&quot;728&quot; /&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/7896653114286550110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/12/comparing-file-names-in-directory-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7896653114286550110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7896653114286550110'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/12/comparing-file-names-in-directory-with.html' title='Comparing File Names in a directory with the list in Excel File'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-3245188038827186407</id><published>2013-11-25T09:16:00.000-08:00</published><updated>2013-12-10T10:42:10.818-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ERROR"/><category scheme="http://www.blogger.com/atom/ns#" term="Error Handling"/><category scheme="http://www.blogger.com/atom/ns#" term="Handling"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><title type='text'>Error Handling in SQL Server 2012</title><content type='html'>As we all know that from SQL Server 2005 and onward, we had TRY CATCH to handle the exceptions / errors in t-sql code along with&amp;nbsp;@@ERROR methodology.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;@@ERROR&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Returns an error number if the previous statement encountered an error. If the error was one of the errors in the sys.messages catalog view, then @@ERROR contains the value from the sys.messages.message_id column for that error. You can view the text associated with an @@ERROR error number in sys.messages.&lt;br /&gt;&lt;br /&gt;Because @@ERROR is cleared and reset on each statement executed, check it immediately following the statement being verified, or save it to a local variable that can be checked later.&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;color: #2a2a2a; font-family: &#39;Segoe UI&#39;, &#39;Lucida Grande&#39;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; line-height: normal;&quot;&gt;Simple Example;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;[dbo]&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[tblTest]&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;[NAME]&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;[varchar]&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;NOT&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;NULL,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;CONSTRAINT&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;[PK_tblTest_1]&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;KEY&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;CLUSTERED&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;[NAME]&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;ASC&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;INTO&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Atif&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Union&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Sheikh&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;

































&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: magenta; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Update&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Atif&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Where&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Sheikh&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;@@ERROR&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt; 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;print&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Error Generated&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Print&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;No Error.&#39;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;















&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;TRY CATCH&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
We can also make use of TRY CATCH block in order to catch the error;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;Update&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Set&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Atif&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Where&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Sheikh&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;print&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Error Generated.&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;

















&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;We can make use of transactions and roll back transactipon in the CATCH block&lt;/o:p&gt;. The TRY...CATCH construct also supports additional system functions (ERROR_LINE, ERROR_MESSAGE, ERROR_PROCEDURE, ERROR_SEVERITY, and ERROR_STATE) that return more error information than @@ERROR. TRY...CATCH also supports an ERROR_NUMBER function that is not limited to returning the error number in the statement immediately after the statement that generated an error.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;Update&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Set&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Atif&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Where&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Sheikh&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;print&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Error Generated.&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;ERROR_NUMBER&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorNumber&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ERROR_SEVERITY&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorSeverity&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ERROR_STATE&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorState&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ERROR_PROCEDURE&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorProcedure&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ERROR_LINE&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorLine&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ERROR_MESSAGE&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ErrorMessage&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;

































&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;THROW&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;Now, in SQL Server 2012, we can also use THROW to throw the exception to the application. You can say it works like RAISERROR;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: magenta;&quot;&gt;Update&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Set&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Atif&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;Where&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Sheikh&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;print&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Error Generated.&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;THROW&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;





















&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;o:p&gt;You can use THROW statement like RAISERROR as well;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: magenta;&quot;&gt;Update&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;Set&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&#39;Atif&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;Where&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&#39;Sheikh&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;print&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Error Generated.&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;THROW&lt;/span&gt; 51000&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Primary Key Violates.&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;
1&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;CATCH&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;o:p&gt;





















&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;

&lt;a href=&quot;http://www.tkqlhce.com/click-7351013-11060117&quot; target=&quot;_top&quot;&gt;
&lt;img src=&quot;http://www.ftjcfx.com/image-7351013-11060117&quot; width=&quot;180&quot; height=&quot;150&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/a&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.anrdoezrs.net/click-7351013-10657364&quot; target=&quot;_top&quot;&gt;
&lt;img src=&quot;http://www.tqlkg.com/image-7351013-10657364&quot; width=&quot;728&quot; height=&quot;90&quot; alt=&quot;5% OFF All Lenovo ThinkPad&#39;s.&quot; border=&quot;0&quot;/&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/3245188038827186407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/error-handling-in-sql-server-2012.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/3245188038827186407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/3245188038827186407'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/error-handling-in-sql-server-2012.html' title='Error Handling in SQL Server 2012'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-5196847705177989318</id><published>2013-11-21T04:14:00.000-08:00</published><updated>2013-11-28T23:43:51.979-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="Sequence Objects"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><title type='text'>Limitatoin of Sequence Objects in SQL Server 2012</title><content type='html'>Sequence Object introduced in SQL Server 2012 is a good features added by MS SQL Server team. I have already discussed this in my post &lt;a href=&quot;http://atifullahsheikh.blogspot.com/2013/11/sequence-object-in-sql-server-2012.html&quot; target=&quot;_blank&quot;&gt;&quot;Sequence Object in SQL Server 2012&quot;&lt;/a&gt; but there are many limitations. I will try to explain the prominent limitations.&lt;br /&gt;
&lt;br /&gt;
Let us create a sequence object in our test database.&lt;br /&gt;
&lt;br /&gt;
CREATE SEQUENCE LimitSequence AS INT&lt;br /&gt;
&amp;nbsp;START WITH 1&lt;br /&gt;
&amp;nbsp;INCREMENT BY 1&lt;br /&gt;
GO&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Also, create a test table with ID generated by using the sequence object;&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE dbo.TestLimit(ID INT,Name VARCHAR(100))&lt;br /&gt;
GO&lt;br /&gt;
INSERT INTO dbo.TestLimit VALUES&lt;br /&gt;
&amp;nbsp;(NEXT VALUE FOR LimitSequence,&#39;Atif&#39;),&lt;br /&gt;
&amp;nbsp;(NEXT VALUE FOR LimitSequence,&#39;Sheikh&#39;),&lt;br /&gt;
&amp;nbsp;(NEXT VALUE FOR LimitSequence,&#39;Asif&#39;)&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
&lt;strong style=&quot;background-color: white; box-sizing: border-box; color: #141412; font-family: &#39;Source Sans Pro&#39;, Helvetica, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;Cannot Use DISTINCT, UNION, UNION ALL, EXCEPT or INTERSECT&amp;nbsp;&lt;/strong&gt;&lt;br /&gt;
&lt;strong style=&quot;background-color: white; box-sizing: border-box; color: #141412; font-family: &#39;Source Sans Pro&#39;, Helvetica, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/strong&gt;
Now, if you try to run the query using sequence object with any of these clauses, you will get an error message;&lt;br /&gt;
&lt;br /&gt;
Select Distinct NEXT VALUE FOR LimitSequence,* from dbo.TestLimit&lt;br /&gt;
&lt;br /&gt;
On executing the above query, you get an eror message as ;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;Msg 11721, Level 15, State 1, Line 1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;NEXT VALUE FOR function cannot be used directly in a statement that uses a DISTINCT, UNION, UNION ALL, EXCEPT or INTERSECT operator.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This applies to all operators.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong style=&quot;background-color: white; box-sizing: border-box; color: #141412; font-family: &#39;Source Sans Pro&#39;, Helvetica, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;Using simple ORDER BY clause&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you try the query using the sequence object with simple ORDER by clause, it will generate an error;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Select NEXT VALUE FOR LimitSequence,* from dbo.TestLimit&lt;/div&gt;
&lt;div&gt;
Order by ID&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Error message is;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Msg 11723, Level 15, State 1, Line 1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;NEXT VALUE FOR function cannot be used directly in a statement that contains an ORDER BY clause unless the OVER clause is specified.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Good part for this is to user OVER (ORDER BY &lt;columnname&gt;).&amp;nbsp;&lt;/columnname&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Select NEXT VALUE FOR LimitSequence,*, ROW_NUMBER() Over (Order by ID) as RNO from dbo.TestLimit&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The above query will execute without any error.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong style=&quot;background-color: white; box-sizing: border-box; color: #141412; font-family: &#39;Source Sans Pro&#39;, Helvetica, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;TOP&amp;nbsp;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong style=&quot;background-color: white; box-sizing: border-box; color: #141412; font-family: &#39;Source Sans Pro&#39;, Helvetica, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/div&gt;
Cannot use with TOP.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Select Top(10) NEXT VALUE FOR LimitSequence,* from dbo.TestLimit&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This query will generate error message as;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Msg 11739, Level 15, State 1, Line 1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;NEXT VALUE FOR function cannot be used if ROWCOUNT option has been set, or the query contains TOP or OFFSET.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As stated in the error message, if ROWCOUNT is set or TOP and OFFSET is used, the query will generate an error message.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong style=&quot;background-color: white; box-sizing: border-box; color: #141412; font-family: &#39;Source Sans Pro&#39;, Helvetica, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;CASE, CHOOSE, COALESCE, IIF, ISNULL, or NULLIF&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong style=&quot;background-color: white; box-sizing: border-box; color: #141412; font-family: &#39;Source Sans Pro&#39;, Helvetica, sans-serif; font-size: 16px; line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
All these are not allowed. I will give the example if ISNULL function;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Select Isnull( NEXT VALUE FOR LimitSequence,0),* from dbo.TestLimit&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Erro rmessage is;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Msg 11741, Level 15, State 1, Line 1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;NEXT VALUE FOR function cannot be used within CASE, CHOOSE, COALESCE, IIF, ISNULL and NULLIF.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You can try the rest of the functions yourself.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;WHERE Clause&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
You cannot use it in WHERE clasuse;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Select * from dbo.TestLimit&lt;/div&gt;
&lt;div&gt;
where NEXT VALUE FOR LimitSequence = 6&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Error message will be;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Msg 11720, Level 15, State 1, Line 2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;NEXT VALUE FOR function is not allowed in the TOP, OVER, OUTPUT, ON, WHERE, GROUP BY, HAVING, or ORDER BY clauses.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So, these are few prominent limitation for the sequence objects.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/5196847705177989318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/limitatoin-of-sequence-objects-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5196847705177989318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/5196847705177989318'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/limitatoin-of-sequence-objects-in-sql.html' title='Limitatoin of Sequence Objects in SQL Server 2012'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-2790720841948281824</id><published>2013-11-20T04:46:00.000-08:00</published><updated>2013-11-28T23:42:53.926-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Contained Databases"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><title type='text'>Contained Database</title><content type='html'>&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;What is it?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
A contained database is a database within a sql server instance that is not dependent upon the instance itself in terms of users and metadata. All users and metadata is stored within the contained database.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;What is the purpose?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
These database are easy to port from instance / server to instance / server. You don&#39;t have to worry about the user logins associated with the database. This is very handy when you are dealing with large number of database users.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Any Important Note / drawback?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Important note is that in SQLServer 2012, only Partial containment type is supported. It means that your database can be a None contained database or partially contained database.&amp;nbsp;&lt;span style=&quot;color: #2a2a2a; line-height: 18px;&quot;&gt;A partially contained database is a contained database that can allow some features that cross the database boundary. SQL Server includes the ability to determine when the containment boundary is crossed.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2a2a2a; line-height: 18px;&quot;&gt;Fully contained user entities (those that never cross the database boundary), for example sys.indexes. Any code that uses these features or any object that references only these entities is also fully contained.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #2a2a2a; line-height: 18px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #2a2a2a; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;As stated above, SQL Server 2012 is supported with only partially contained state. A partially contained database is a contained database that allows the use of uncontained features.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #2a2a2a; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;According to BOL, use the&amp;nbsp;&lt;a href=&quot;http://technet.microsoft.com/en-us/library/ff929336.aspx&quot; style=&quot;color: #0066dd; text-decoration: none;&quot;&gt;sys.dm_db_uncontained_entities&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href=&quot;http://technet.microsoft.com/en-us/library/ms175081.aspx&quot; style=&quot;color: #0066dd; text-decoration: none;&quot;&gt;sys.sql_modules &lt;/a&gt;view to return information about uncontained objects or features. By determining the containment status of the elements of your database, you can discover what objects or features must be replaced or altered to promote containment.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #2a2a2a; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The behavior of partially contained databases differs most distinctly from that of non-contained databases with regard to collation.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #2a2a2a; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;How to create?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #2a2a2a; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Ok, enough theory. there are three steps to create a contained database;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #2a2a2a; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;1. First, we need to enable the &quot;contained database authentication&quot;. We can do this using T-SQL;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;color: #c0504d; font-size: 9.5pt;&quot;&gt;sp_configure&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&#39;contained database authentication&#39;&lt;/span&gt;,&amp;nbsp;1&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-GB&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;RECONFIGURE&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #333333; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;color: blue; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
2. Then we create a new database as contained database;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #333333; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue; font-family: inherit;&quot;&gt;&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;USE&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;master&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span lang=&quot;EN-GB&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span lang=&quot;EN-GB&quot; style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;CREATE&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DATABASE &lt;/span&gt;&lt;span style=&quot;color: #4f81bd;&quot;&gt;TestDB&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #8fb08c; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;CONTAINMENT&lt;/span&gt;&lt;span style=&quot;color: #9bbb59; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;PARTIAL&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;color: #333333; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; color: lime; font-family: inherit; font-size: 9.5pt;&quot;&gt;--Create table with records&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 12px; line-height: 18.15625px;&quot;&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #8fb08c; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;TestDB&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;TABLE&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #8fb08c;&quot;&gt;tblTest&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #8fb08c; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #8fb08c; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #8fb08c; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;Name&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;varchar&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;250&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #8fb08c; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: 9.5pt;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;INTO&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #8fb08c;&quot;&gt;tblTest&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;VALUES&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;10,&lt;span style=&quot;color: red;&quot;&gt;&#39;Atif&#39;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;),&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;20,&lt;span style=&quot;color: red;&quot;&gt;&#39;Imran&#39;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;),&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;30,&lt;span style=&quot;color: red;&quot;&gt;&#39;Asif&#39;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;GO&lt;/span&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 12pt; line-height: 18.15625px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;color: #333333; font-size: 12px; list-style-type: disc; margin: 0in 0in 0pt;&quot;&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;&lt;span style=&quot;color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
3. Then, at last, we will be creating the user(s) for the our partially contained database;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #8fb08c;&quot;&gt;TestDB&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;USER&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;TestUser&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;WITH&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;PASSWORD&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;N&#39;testCUser1$&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;DEFAULT_SCHEMA&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;dbo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue; font-family: inherit; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: #c0504d;&quot;&gt;&amp;nbsp;sp_addrolemember&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;db_owner&#39;&lt;/span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red; font-size: 9.5pt;&quot;&gt;&#39;TestUser&#39;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #2a2a2a; font-size: 13px; line-height: 18px; padding-bottom: 15px;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue; font-size: 9.5pt; line-height: 18.15625px;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;color: #333333; font-size: 12px; line-height: 18.15625px; list-style-type: disc; margin: 0in;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
In order to test our exercise, we have to log into a new session using the above created user. Check you server Server authentication settings. As I am using sql server user and not a Domain user, the instance should be configured as &quot;SQL Server and Windows authentication mode&quot;. In the figure I have specified the user name and password of the user that we have created in the contained database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn8IYcL2aUT3JcDHY_NPaY1rz4lxziBG-DIXxtSIoRKhDBvnwW9qekHOn3R2S3H7shGasWjjsnjn-KXvntPXPlIeMigR0_M2heccL0JsVo_tqKoyDRWGc6-bxTctztBGb0J8AVstpCZ_of/s1600/Contained1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn8IYcL2aUT3JcDHY_NPaY1rz4lxziBG-DIXxtSIoRKhDBvnwW9qekHOn3R2S3H7shGasWjjsnjn-KXvntPXPlIeMigR0_M2heccL0JsVo_tqKoyDRWGc6-bxTctztBGb0J8AVstpCZ_of/s320/Contained1.png&quot; width=&quot;278&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, we have to specify the name of the contained database. You will have to type it as the user you have specified does not exists in the sql server instance.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht4MFaL8QwCtqsHA2M3bJqNIhrTXinWz8JdBe14M-3Z2grxuldDBLFcdD_EBPmoPWbgIPKBUMac45_NMKN07DQjFDrhK_P2KK1nrsw5OUhaHt9DVA8B7_TXy7HlQkrd2qJHZnl8eVEhK4F/s1600/Contained2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht4MFaL8QwCtqsHA2M3bJqNIhrTXinWz8JdBe14M-3Z2grxuldDBLFcdD_EBPmoPWbgIPKBUMac45_NMKN07DQjFDrhK_P2KK1nrsw5OUhaHt9DVA8B7_TXy7HlQkrd2qJHZnl8eVEhK4F/s320/Contained2.png&quot; width=&quot;273&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
Once the login name is authenticated, you will have you object explorer listing only the contained database;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKzBjyByoTFASabaqJ_cIcLWvH223AAdV3Wb3zLVU59Vf_tjrpYQ1o2gMsBzhAvERf_3w0klKZECLqIdpclagZuy-hMQ609L5Flz-XQcU3syMZK_69r4OrfMy2URQJLvOyPaZqnJ1MCKzS/s1600/Contained3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKzBjyByoTFASabaqJ_cIcLWvH223AAdV3Wb3zLVU59Vf_tjrpYQ1o2gMsBzhAvERf_3w0klKZECLqIdpclagZuy-hMQ609L5Flz-XQcU3syMZK_69r4OrfMy2URQJLvOyPaZqnJ1MCKzS/s320/Contained3.png&quot; width=&quot;233&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
That&#39;s it. We have successfully created a contained database.&lt;br /&gt;
&lt;b&gt;Ok, what about the old databases that i need to convert to partial contained database?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can convert an uncontained database to partial contained database by using the following 3 steps;&lt;br /&gt;
&lt;br /&gt;
1. Enable the &quot;contained database authentication&quot; as above.&lt;br /&gt;
2. Alter the database as;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;ALTER&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;DATABASE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;[MyDatabase]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 9.5pt;&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;CONTAINMENT&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;PARTIAL&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div lang=&quot;en-GB&quot; style=&quot;list-style-type: disc; margin: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
3. In the last step, we move the user(s) to the database;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: teal; font-size: 9.5pt;&quot;&gt;sp_migrate_user_to_contained&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: teal; font-size: 9.5pt;&quot;&gt;@username&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;N&#39;MyDBLogin&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: teal; font-size: 9.5pt;&quot;&gt;@rename&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;N&#39;keep_name&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;span style=&quot;color: teal; font-size: 9.5pt;&quot;&gt;@disablelogin&lt;/span&gt;&lt;span style=&quot;font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;
&lt;span style=&quot;color: red;&quot;&gt;N&#39;disable_login&#39;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue; font-family: inherit; font-size: 9.5pt;&quot;&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;









&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above statement, we have un-authorized the &#39;MyDBLogin&#39; to log in the instance. We did not changed the login name here by specifying the value &#39;keep_name&#39; for @rename.&lt;br /&gt;
&lt;br /&gt;
Now, if you log in using this user as in our last example, you will only see the &#39;MyDatabase&#39; in teh object explorer.&lt;br /&gt;
&lt;br /&gt;
Hope this will help you.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/2790720841948281824/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/contained-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2790720841948281824'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/2790720841948281824'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/contained-database.html' title='Contained Database'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn8IYcL2aUT3JcDHY_NPaY1rz4lxziBG-DIXxtSIoRKhDBvnwW9qekHOn3R2S3H7shGasWjjsnjn-KXvntPXPlIeMigR0_M2heccL0JsVo_tqKoyDRWGc6-bxTctztBGb0J8AVstpCZ_of/s72-c/Contained1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-4575158037988474413</id><published>2013-11-19T04:34:00.002-08:00</published><updated>2013-11-21T04:15:24.866-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><category scheme="http://www.blogger.com/atom/ns#" term="Query optimization"/><category scheme="http://www.blogger.com/atom/ns#" term="Sequence Objects"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL Solution"/><title type='text'>Sequence Object in SQL Server 2012</title><content type='html'>MS SQL Server has introduced a new feature of Sequence Objects in SQL Server 2012. In the prior versions, IDENTITY was used to generate sequence numbers. The limitation of IDENTITY was that it was related to one table. The scope of Sequence Objects is database. So, if you want to add a same value to two tables, you can use this feature. Also, you can generate the next sequence number before going into the transaction. The IDENTITY is incremented in the transaction at the time of INSERT. Another plus point of Sequence Object is that you can define the maximum value for the object and re-initialize the counter of the object without any extra programming effort.&lt;br /&gt;
&lt;br /&gt;
Here is the code of creating teh new sequence object in SQL Server 2012 Management Studio;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-color: white; line-height: 18.15625px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;SEQUENCE dbo&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;NextCustomerID
    &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;as BIGINT
    &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;START &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;WITH &lt;/span&gt;1
    &lt;span style=&quot;color: teal;&quot;&gt;INCREMENT &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;BY &lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;GO
&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
This will add a new sequence object. You can see this object in Object Explorer under your database in &lt;b&gt;Programming --&amp;gt; Sequence&lt;/b&gt; folder.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjGNGpnmpCr7zE9-tPkWNviWYMfuRgC85F-RZTJXECp_JnaIlbCuVbXImz_3Anj0TX7qdpGk9jeG6AfVuFH_scuP_kBKvZiuyygu1J-llSfB7jtOIzPhvqTKOcHlVEMzyfQVDsIm2p7cRG/s1600/Sequence1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjGNGpnmpCr7zE9-tPkWNviWYMfuRgC85F-RZTJXECp_JnaIlbCuVbXImz_3Anj0TX7qdpGk9jeG6AfVuFH_scuP_kBKvZiuyygu1J-llSfB7jtOIzPhvqTKOcHlVEMzyfQVDsIm2p7cRG/s320/Sequence1.png&quot; width=&quot;235&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Well, it not over yet. The query used to create this object creates the object with the default values. You can set many parameters. If you right click the newly created object and click properties, this will open the property window for this object. Here you can set Minimum value, Maximum Value, Cycle and Cache.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6VzJEX9DJc1Yes_5Q2jEmDRPNEYMNMAsb7SuAhOoYxsl_U8bfkjzzRl_gMCL4c9zlGrGxFRRY3x8zMpYoOfKhepp__SAxnTFBIwrb8jcCEoucr1nY0-AjiEu3pGGxG5HNIOhvtZ1hUG-S/s1600/Sequence2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;286&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6VzJEX9DJc1Yes_5Q2jEmDRPNEYMNMAsb7SuAhOoYxsl_U8bfkjzzRl_gMCL4c9zlGrGxFRRY3x8zMpYoOfKhepp__SAxnTFBIwrb8jcCEoucr1nY0-AjiEu3pGGxG5HNIOhvtZ1hUG-S/s320/Sequence2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Minimum and Maximum are the minimum and maximum values for the object. Cycle check box states that the value will re-initialize when the maximum value is reached. You can also set the re-start value (From where it will start after reaching the maximum value). Cache option tells the object how many values it will have remaining to avoid extra Disk I/Os during the increment process. For example, if cache size is set to 25, it will &amp;nbsp;not generate 25 numbers in it memory. It will only keep the current value and the remaining values. If 3 IDs are generated for the object with cache of 25, it will have 4 and 22 in its memory. For more information on cache mechanism you can &lt;a href=&quot;http://technet.microsoft.com/en-us/library/ff878091.aspx&quot; target=&quot;_blank&quot;&gt;Click Here&lt;/a&gt;&amp;nbsp;and check the Cache Management section.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Ok, here is the code for generating the sequence number from the object;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-color: white; line-height: 18.15625px;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;-- Get the next available ID
&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@CustID &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@CustID &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;NEXT &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;VALUE &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;FOR &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;NextCustomerID&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@CustID &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;as &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;Customer ID&#39;&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Please remember that the sequence object is not transaction specific. Once you generate the sequence with the NEXT VALUE, it is consumed weather the transaction is committed and rolled back. This is similar to the IDENTITY. Hence, the sequence objects also may have gaps in between as we have in IDENTITY columns.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In case you want to restart the sequence, you can use;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;ALTER&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;SEQUENCE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;NextCustomerID&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;RESTART&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;You can use the OVER ORDER BY clause with NEXT VALUE FOR for generating the next sequence values;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;NEXT&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;VALUE&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;FOR&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;NextCustomerID&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;OVER &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;ORDER&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;BY&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;RNO&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ListNumber&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
You can check books online for more information.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
There are also the limitations of the Sequence Objects which I will cover in the separate topic and try to explain with examples.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/4575158037988474413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/sequence-object-in-sql-server-2012.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/4575158037988474413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/4575158037988474413'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/sequence-object-in-sql-server-2012.html' title='Sequence Object in SQL Server 2012'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjGNGpnmpCr7zE9-tPkWNviWYMfuRgC85F-RZTJXECp_JnaIlbCuVbXImz_3Anj0TX7qdpGk9jeG6AfVuFH_scuP_kBKvZiuyygu1J-llSfB7jtOIzPhvqTKOcHlVEMzyfQVDsIm2p7cRG/s72-c/Sequence1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-1096404594665872459</id><published>2013-11-18T04:30:00.001-08:00</published><updated>2014-08-07T10:49:06.246-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cube"/><category scheme="http://www.blogger.com/atom/ns#" term="DML"/><category scheme="http://www.blogger.com/atom/ns#" term="Index"/><category scheme="http://www.blogger.com/atom/ns#" term="Indexed View"/><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="Paging"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><category scheme="http://www.blogger.com/atom/ns#" term="Query optimization"/><category scheme="http://www.blogger.com/atom/ns#" term="Script"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Triggers"/><title type='text'>Columnstore Indexes</title><content type='html'>This is the new feature added in SQL Server 2012 to overcome query performance and index data compression issues. The data stored in the columnstore index is pretty much compressed and very optimized. In SQL Srever 2012, if you have a columnstore index, you cannot perform the DML operations on the table i.e. you cannot insert / update or delete any record. The purpose of this index is for Data warehousing. You have to devise the logic in order to populate the data, for example table partitioning. But this issue is resolved in SQL Server 2014. But there, you will have to create a CLUSTERED COLUMNSTORE INDEX.&lt;br /&gt;
&lt;br /&gt;
You can add this index simply by right clicking the Index folder under the table on which you want to add the column store index;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUkHqQ2GJi6k2hrbEGhSpp5q3493lgbH4qA6dRqCAlEOS9sJnjVNMquzssKwnFBycfYQB2AFIZ_8dJarddi5K1E1oIlb54FwK5oC9EDCLj4gqc9-xvWhHzv2xkMff-V_mtAgAZEvscNUUG/s1600/ColumnStore1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUkHqQ2GJi6k2hrbEGhSpp5q3493lgbH4qA6dRqCAlEOS9sJnjVNMquzssKwnFBycfYQB2AFIZ_8dJarddi5K1E1oIlb54FwK5oC9EDCLj4gqc9-xvWhHzv2xkMff-V_mtAgAZEvscNUUG/s320/ColumnStore1.png&quot; height=&quot;377&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
On clicking the option, a screen will open asking to add the column(s) on which you want to create a column store index (FirstName, LastName).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpKiSWlhpjUE0FlVAYK4EPlxuZw73W9jXGhTVzeiHqtfgLaRUgYRQ-VA_oCVDFZWEF8rwgmEqgRvgVDgNGv8IqCwK-p8Dynm6yFsRKbi4bz69s8kuHSUIjnw-Y8kgvjE6tUy-Kc1LgpPIG/s1600/ColumnStore2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpKiSWlhpjUE0FlVAYK4EPlxuZw73W9jXGhTVzeiHqtfgLaRUgYRQ-VA_oCVDFZWEF8rwgmEqgRvgVDgNGv8IqCwK-p8Dynm6yFsRKbi4bz69s8kuHSUIjnw-Y8kgvjE6tUy-Kc1LgpPIG/s320/ColumnStore2.png&quot; height=&quot;225&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Leave rest of the properties to default. Click OK button to add the index.&lt;br /&gt;
&lt;br /&gt;
Now, question is how the data will be stored? We have two types of data storge in sql server, RowStore and Column Store. Assume you have a tabel as&lt;br /&gt;
&lt;br /&gt;
RNO &amp;nbsp; &amp;nbsp; &amp;nbsp; NAME &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FNAME&lt;br /&gt;
1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Atif &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Sheikh&lt;br /&gt;
2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Asif &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ahmed&lt;br /&gt;
3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Imran &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Khan&lt;br /&gt;
&lt;br /&gt;
In RowStore index, the data will be saved as;&lt;br /&gt;
&lt;br /&gt;
Atif,Sheikh&lt;br /&gt;
Asif,Ahmed&lt;br /&gt;
Imran,Khan&lt;br /&gt;
&lt;br /&gt;
The above data will be saved as a row in the 8k page.&lt;br /&gt;
&lt;br /&gt;
And this will go on until the 8k page is complete.&lt;br /&gt;
&lt;br /&gt;
In case of Columnstore index, the data will be stored as a segment of its respective column. Each segment have only one column. This goes for all the columns in the index. A Column can span on multiple segments and a segment may have multiple data pages. As for above example the data will be stored as;&lt;br /&gt;
&lt;br /&gt;
Col1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Col2&lt;br /&gt;
&lt;br /&gt;
Atif &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Sheikh &lt;br /&gt;
Asif &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ahmed&lt;br /&gt;
Imran &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Khan&lt;br /&gt;
&lt;br /&gt;
These columns are just like pointers in the 8k page of the index. One page can have multiple columns&lt;br /&gt;
&lt;br /&gt;
Now if you will query with NAME or FNAME in your WHERE condition, the data search and retrieval will be very fast as each condition will have to check one single column. You can check this with Statistics and Execution plans on you tables.</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/1096404594665872459/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/columnstore-indexes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/1096404594665872459'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/1096404594665872459'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/columnstore-indexes.html' title='Columnstore Indexes'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUkHqQ2GJi6k2hrbEGhSpp5q3493lgbH4qA6dRqCAlEOS9sJnjVNMquzssKwnFBycfYQB2AFIZ_8dJarddi5K1E1oIlb54FwK5oC9EDCLj4gqc9-xvWhHzv2xkMff-V_mtAgAZEvscNUUG/s72-c/ColumnStore1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6571655444622533369.post-7544911798006316303</id><published>2013-11-13T06:37:00.002-08:00</published><updated>2013-11-28T23:43:27.984-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MS SQL Server 2012"/><category scheme="http://www.blogger.com/atom/ns#" term="Paging"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><category scheme="http://www.blogger.com/atom/ns#" term="Query optimization"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><title type='text'>Paging in SQL Server 2012</title><content type='html'>As we all know that MS has given us the FETCH NEXT clause in the query to apply paging. Let me explain this feature by adding a temp table of 1 million records.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;wcte&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;as &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;Row_number&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;over &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;order&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;by&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;RNO&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: green;&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;columns&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;columns&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;columns&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;c&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;rno&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#39;Name: &#39;&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;rno&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;10&lt;span style=&quot;color: grey;&quot;&gt;))&lt;/span&gt;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;into&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;wcte&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;RNO&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;=&lt;/span&gt; 1000000&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Add primary key on RNO column through the designer. This will add a clustered index on this column.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Now, lets write the query for the SQL Server 2005 / 2008 / 2008 R2 using CTE;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;With&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;wcte&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;as &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: magenta;&quot;&gt;Row_Number&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;over &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;Order&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;by&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Rno&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Rno2&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;WHERE&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Not&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Null&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: Consolas; font-size: 9.5pt;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;Select&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;wcte&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;rno2&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;&amp;gt;&lt;/span&gt; 899979 &lt;span style=&quot;color: grey;&quot;&gt;and&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;rno2&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;&lt;/span&gt; 900000&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;by&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;rno&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&amp;nbsp;If you look at the execution plan of this query, it will be like this;&lt;/o:p&gt;&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4f7Lq9fnOHl6hLI5W_hAmbsKfQEpids2x-aYHmQwn0Jut8MmuIzNZTBVpJ2fhahHeK-VQkAENFR0J085BrCz0NU2UV7Swol_cnZERoPUyxi4v9XguRBnx6aDPYMLQ_KU7l1XFBG8wwbYC/s1600/Paging+ExecPlan+2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4f7Lq9fnOHl6hLI5W_hAmbsKfQEpids2x-aYHmQwn0Jut8MmuIzNZTBVpJ2fhahHeK-VQkAENFR0J085BrCz0NU2UV7Swol_cnZERoPUyxi4v9XguRBnx6aDPYMLQ_KU7l1XFBG8wwbYC/s1600/Paging+ExecPlan+2.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now lets write the query for SQL Server 2012 paging;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vPageNo&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vOffset&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Declare&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vPageSize&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vPageNo&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; 45000&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vPageSize&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt; 20&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Set&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vOffset&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;@vPageNo&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;-&lt;/span&gt;1&lt;span style=&quot;color: grey;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vPageSize&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: grey;&quot;&gt;*&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;tblTest&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: teal;&quot;&gt;Name&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Not&lt;/span&gt; &lt;span style=&quot;color: grey;&quot;&gt;Null&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;ORDER&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;BY&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;rno&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: teal;&quot;&gt;OFFSET&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vOffset&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;ROWS&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;FETCH&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;NEXT&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;@vPageSize&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;ROWS&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;ONLY&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
I have added the variables for passing OFFSET and PAGESIZE. This gives an additional hint for passing these from the front end as Input parameters of stored procedure.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;The execution plan for this query is;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvUALnkzAOdkA_kkGWfWKyFzQfu3Z0w6REjgnh9WKvYdgzXQW3oWc6f2eBMFYTd__yC5rN61BK269_mYnzT71LON11mKnqrOczAyL4g-Gz4OjLUzo2Yy51zjNDLHVqQgV85xqZUjESc0AH/s1600/Paging+ExecPlan+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvUALnkzAOdkA_kkGWfWKyFzQfu3Z0w6REjgnh9WKvYdgzXQW3oWc6f2eBMFYTd__yC5rN61BK269_mYnzT71LON11mKnqrOczAyL4g-Gz4OjLUzo2Yy51zjNDLHVqQgV85xqZUjESc0AH/s1600/Paging+ExecPlan+1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;Now, it is very clear that the paging query of SQL Server 2012 performed very limited functions and performed 100% index scan. The SQL Server 2008 query performed many additional functions which makes it a bit smaller with my 2 column table.&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Results might be different if you apply the same scenario directly on the clustered indexed column (RNO of tbltest in my case) instead of applying Row_Number() function. This is not the real time case as you never have IDs in sequence in you db tables as sequences break when you delete or migrate. More importantly, you apply paging on queries with WHERE clause. And you cannot use ID columns for paging in any case with WHERE Clause.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://atifullahsheikh.blogspot.com/feeds/7544911798006316303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/paging-in-sql-server-2012.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7544911798006316303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6571655444622533369/posts/default/7544911798006316303'/><link rel='alternate' type='text/html' href='http://atifullahsheikh.blogspot.com/2013/11/paging-in-sql-server-2012.html' title='Paging in SQL Server 2012'/><author><name>Atif</name><uri>http://www.blogger.com/profile/04513915063697385945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4f7Lq9fnOHl6hLI5W_hAmbsKfQEpids2x-aYHmQwn0Jut8MmuIzNZTBVpJ2fhahHeK-VQkAENFR0J085BrCz0NU2UV7Swol_cnZERoPUyxi4v9XguRBnx6aDPYMLQ_KU7l1XFBG8wwbYC/s72-c/Paging+ExecPlan+2.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>