<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Server &#8211; acm&#039;s blog</title>
	<atom:link href="https://blog.acm.idv.tw/tag/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.acm.idv.tw</link>
	<description>技術與生活隨筆</description>
	<lastBuildDate>Sat, 10 Sep 2022 09:13:38 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>

<image>
	<url>https://blog.acm.idv.tw/wp-content/uploads/2022/06/cropped-logo_kaffa9-3-32x32.png</url>
	<title>SQL Server &#8211; acm&#039;s blog</title>
	<link>https://blog.acm.idv.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Microsoft SQL Server語言定序問題</title>
		<link>https://blog.acm.idv.tw/2022/09/10/microsoft-sql-server%e8%aa%9e%e8%a8%80%e5%ae%9a%e5%ba%8f%e5%95%8f%e9%a1%8c/</link>
					<comments>https://blog.acm.idv.tw/2022/09/10/microsoft-sql-server%e8%aa%9e%e8%a8%80%e5%ae%9a%e5%ba%8f%e5%95%8f%e9%a1%8c/#respond</comments>
		
		<dc:creator><![CDATA[kaffa9]]></dc:creator>
		<pubDate>Sat, 10 Sep 2022 09:13:38 +0000</pubDate>
				<category><![CDATA[系統維運]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">https://kaffa9.com/?p=622</guid>

					<description><![CDATA[近日進行SQL Server資料庫轉移，由公司自有的雲環境搬遷到Azure混合雲中，沒想到一直以來都在繁體中文環境工作導致踩了個大雷。由於某些緣故，某資料庫在評...<p class="read-more"><a class="btn btn-default" href="https://blog.acm.idv.tw/2022/09/10/microsoft-sql-server%e8%aa%9e%e8%a8%80%e5%ae%9a%e5%ba%8f%e5%95%8f%e9%a1%8c/"> Read More<span class="screen-reader-text">  Read More</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p>近日進行SQL Server資料庫轉移，由公司自有的雲環境搬遷到Azure混合雲中，沒想到一直以來都在繁體中文環境工作導致踩了個大雷。由於某些緣故，某資料庫在評估後，決定使用SQL script方式進行移轉，沒想到該資料庫內有許多資料表的欄位使用VARCHAR型態、而非NVARCHAR型態來儲存中文資料，這導致許多中文資料不管是SSMS或是在實際上線的Web應用程式中都成了問號（？），原訂停機1天完成資料移轉，只得持續延長。</p>



<span id="more-622"></span>



<p>由於舊資料庫可以正常儲存中文，程式也都可以正常顯示中文，從過往使用MySQL的經驗來判斷，非常有可能是語系／文字編碼的問題造成的。</p>



<p>在SSMS裡，確認了一下SQL Server的collation，果不其然，可能因為Azure建立的Windows和SQL Server預設是SQL_Latin1_General_CP1_CI_AS，很可惜安裝完就無法輕易更改，除非進行SQL Server rebuild，考量到已經有別的資料庫已經移轉進來正在使用，暫時作罷。接著再進一步確認此次轉移的資料庫實體的collation，也是SQL_Latin1_General_CP1_CI_AS，運氣很好，這是可以調整的，然而調整成Chinese_Taiwan_Stroke_CI_AS後並沒有解決問題，這只會影響之後CREATE TABLE新建資料表時的預設collation。在Google上一番胡亂查找，發現已經建立的資料表，就得一一手動ALTER TABLE ALTER COLUMN進行欄位collation的修改（真是晴天霹靂）。</p>



<p>透過sys.databases、sys.columns的資料，我們可以檢查特定欄位的collation：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">SELECT name, collation_name FROM sys.columns WHERE name = N'&lt;insert character data type column name>';</pre>



<p>一陣操作之後，發現CHAR、NCHAR、VARCHAR、NVARCHAR、TEXT、NTEXT等文字欄位高達300個以上，要逐一確認是否應該該轉換為Chinese_Taiwan_Stroke_CI_AS實在太痛苦，便決定要將整個轉移程序重做一遍，唯一不同之處，就是在CREATE指令補上COLLATION，指定為Chinese_Taiwan_Stroke_CI_AS（其實先前已經在SSMS調整過COLLATION，所以不指定好像也行，但指定一下總是安心點）。</p>



<p>就在要執行前，又發現SSMS產生指令碼進階設定中，有一項「指令碼定序」，預設為false，於是改為true後，重新產生一批SQL script，這下COLLATION都幫我加好了！唉呀，真是相見恨晚～不過總算是順利解決這次危機。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.acm.idv.tw/2022/09/10/microsoft-sql-server%e8%aa%9e%e8%a8%80%e5%ae%9a%e5%ba%8f%e5%95%8f%e9%a1%8c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
