<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Programming on Andy M Mallon - AM²</title><link>https://am2.co/tag/programming/</link><description>Recent content in Programming on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 11 Nov 2024 17:21:05 -0500</lastBuildDate><atom:link href="https://am2.co/tag/programming/index.xml" rel="self" type="application/rss+xml"/><item><title>Migrating my Stack Overflow answers to blog posts (Sorry for the spam)</title><link>https://am2.co/2024/11/11/migrating-my-stack-overflow-answers-to-blog-posts-sorry-for-the-spam/</link><pubDate>Mon, 11 Nov 2024 17:21:05 -0500</pubDate><guid>https://am2.co/2024/11/11/migrating-my-stack-overflow-answers-to-blog-posts-sorry-for-the-spam/</guid><description>&lt;p&gt;&lt;a href="https://am2.co/wp-content/uploads/stackoverflow-icon.webp"&gt;&lt;img src="https://am2.co/wp-content/uploads/stackoverflow-icon-300x300.webp" alt="" width="300" height="300" class="alignright size-medium wp-image-55224" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;For a while, I have been thinking about using &lt;a href="https://am2.co/category/stack-exchange/" rel="noopener" target="_blank"&gt;my Stack Overflow answers&lt;/a&gt; (and answers on other sites on the Stack Exchange Network), and storing a copy of them here, on my blog as well. All posts on the Stack Exchange network are covered under the &lt;a href="https://creativecommons.org/licenses/by-sa/4.0/deed.en" rel="noopener" target="_blank"&gt;Creative Commons BY-SA license&lt;/a&gt;. When Stack Overflow was created, this license was chosen to ensure that Q&amp;amp;A data remained an open data repository. Posts can be freely reused, re-published, etc, so long as attribution is provided (who is the post &lt;code&gt;BY&lt;/code&gt;, and where it was published), and derivative versions are also shared under the same license (ie, &lt;code&gt;S&lt;/code&gt;hare &lt;code&gt;A&lt;/code&gt;like).&lt;/p&gt;</description></item><item><title>Enforce a specific constraint to be checked first?</title><link>https://am2.co/2023/10/06/enforce-a-specific-constraint-to-be-checked-first/</link><pubDate>Fri, 06 Oct 2023 21:09:33 -0400</pubDate><guid>https://am2.co/2023/10/06/enforce-a-specific-constraint-to-be-checked-first/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/77247392/1948808"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have the following SQL Server table :&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;-- column names with their data types and properties&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;identity&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;primary&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;User&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Job&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;-- table limitations&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;constraint&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;UniqueUserPerAccount&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;unique&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;User&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;constraint&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;UniqueJobPerAccount&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;unique&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Job&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For the two constraints I listed the more important constraint first hoping that if both constraints are violated, the first one would be triggered and displayed to the user. However, it appears the constraints are declared alphabetically by column name and therefore if both constraints fail, the &lt;code&gt;UniqueJobPerAccount&lt;/code&gt; error, and only this error, is stated to have been violated.&lt;/p&gt;</description></item><item><title>How to convert from nchar to decimal in SQL?</title><link>https://am2.co/2021/05/10/how-to-convert-from-nchar-to-decimal-in-sql/</link><pubDate>Mon, 10 May 2021 18:29:23 -0400</pubDate><guid>https://am2.co/2021/05/10/how-to-convert-from-nchar-to-decimal-in-sql/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/67475843/1948808"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have 2 tables(source and destination) which are respectively &lt;code&gt;NOR_LABOR&lt;/code&gt; and &lt;code&gt;ALL_LABOR_DETAILS&lt;/code&gt;. In the source table(&lt;code&gt;NOR_LABOR&lt;/code&gt;) there is a column &lt;code&gt;feet_produced&lt;/code&gt; with the data type &lt;code&gt;nchar(10)&lt;/code&gt;. In the destination table(&lt;code&gt;ALL_LABOR_DETAILS&lt;/code&gt;) there&amp;rsquo;s a column &lt;code&gt;labor_feet_produced&lt;/code&gt; with the data type &lt;code&gt;decimal(18,4)&lt;/code&gt;. I want to convert the &lt;code&gt;feet_produced&lt;/code&gt; from &lt;code&gt;nchar(10)&lt;/code&gt; to &lt;code&gt;decimal(18,4)&lt;/code&gt; and paste it in the &lt;code&gt;ALL_LABOR_DETAILS&lt;/code&gt; table&amp;rsquo;s &lt;code&gt;labor_feet_produced&lt;/code&gt; column.&lt;/p&gt;</description></item><item><title>Restoring a SQL Server 2012 database in high availability</title><link>https://am2.co/2014/11/12/restoring-a-sql-server-2012-database-in-high-availability/</link><pubDate>Wed, 12 Nov 2014 14:42:35 -0500</pubDate><guid>https://am2.co/2014/11/12/restoring-a-sql-server-2012-database-in-high-availability/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/26889631/1948808"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a database which is in always-on high availability mode synchronized with another database on a different instance. How can I restore from a &lt;code&gt;.bak&lt;/code&gt; file into the primary database using T-SQL?&lt;/p&gt;&#10;&lt;p&gt;I&amp;rsquo;m new to high availability and I&amp;rsquo;ve been advised that I need to take the database out of high availability before I can do a restore and then put it back in high availability again but I&amp;rsquo;m not sure.&lt;/p&gt;</description></item></channel></rss>