<?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>charset &#8211; acm&#039;s blog</title>
	<atom:link href="https://blog.acm.idv.tw/tag/charset/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.acm.idv.tw</link>
	<description>技術與生活隨筆</description>
	<lastBuildDate>Sat, 10 Sep 2022 09:47:02 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>

<image>
	<url>https://blog.acm.idv.tw/wp-content/uploads/2022/06/cropped-logo_kaffa9-3-32x32.png</url>
	<title>charset &#8211; acm&#039;s blog</title>
	<link>https://blog.acm.idv.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>SSMS匯出指令碼以UTF16LE編碼問題</title>
		<link>https://blog.acm.idv.tw/2022/09/10/ssms%e5%8c%af%e5%87%ba%e6%8c%87%e4%bb%a4%e7%a2%bc%e4%bb%a5utf16le%e7%b7%a8%e7%a2%bc%e5%95%8f%e9%a1%8c/</link>
					<comments>https://blog.acm.idv.tw/2022/09/10/ssms%e5%8c%af%e5%87%ba%e6%8c%87%e4%bb%a4%e7%a2%bc%e4%bb%a5utf16le%e7%b7%a8%e7%a2%bc%e5%95%8f%e9%a1%8c/#respond</comments>
		
		<dc:creator><![CDATA[kaffa9]]></dc:creator>
		<pubDate>Sat, 10 Sep 2022 09:47:02 +0000</pubDate>
				<category><![CDATA[技術]]></category>
		<category><![CDATA[系統維運]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[UTF16BE]]></category>
		<category><![CDATA[UTF16LE]]></category>
		<category><![CDATA[UTF8]]></category>
		<guid isPermaLink="false">https://kaffa9.com/?p=624</guid>

					<description><![CDATA[前文說到，最近在進行一些SQL Server資料庫轉移工作，而有些資料庫是以SQL script方式進行移轉，其中有些資料庫因資料量巨大，匯出的SQL scri...<p class="read-more"><a class="btn btn-default" href="https://blog.acm.idv.tw/2022/09/10/ssms%e5%8c%af%e5%87%ba%e6%8c%87%e4%bb%a4%e7%a2%bc%e4%bb%a5utf16le%e7%b7%a8%e7%a2%bc%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資料庫轉移工作，而有些資料庫是以SQL script方式進行移轉，其中有些資料庫因資料量巨大，匯出的SQL script奇大無比，高達數十GB。在第一次轉移時，使用sqlcmd發生不明原因導致作業中斷，懷疑是SQL script太大導致，因此打算進行檔案切割。</p>



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



<p>Windows環境裡，不若Linux或MacOS，有方便的工具指令如split可以切割檔案，所幸Git安裝時順帶了一套MinGW Bash環境，便在此環境進行切割。</p>



<p>以3,000,000行為單位進行切割：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">split -l 3000000 scripts.sql</pre>



<p>為了確保切割過的每一個檔都能正常插入資料，寫了bash shell script幫每個檔的頭和尾各補了USE [xxx]; 、SET IDENTITY_INSERT ON; 以及 SET IDENTITY_INSERT OFF; ，當然還有很多GO。</p>



<p>沒想到一餵給sqlcmd跑就掛了，出師不利 XD</p>



<p>搞了一套能開大檔的文字編輯器emedtior，一揭開這秘密不得了！大変だ！把問題盤點下來：</p>



<ul class="wp-block-list"><li>SQL Server產生指令碼預設以UTF16LE格式編碼</li><li>MinGW bash指令預設以UTF8編碼處理檔案<ul><li>split一遇到 newline 就切下去，把本來該被當成同一個字元的下一個位元組 0x00 留給下一個檔，這讓第1個檔以外的其他檔案實際上變成了UTF16BE編碼（囧）</li><li>bash shell script補上的header、footer讓檔案成了一個UTF16LE、UTF8混合的四不像</li></ul></li></ul>



<p>後來怎麼處理呢？用了笨方法，先轉成UTF8吧：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">iconv -f UTF-16LE -t UTF-8 scripts.sql</pre>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.acm.idv.tw/2022/09/10/ssms%e5%8c%af%e5%87%ba%e6%8c%87%e4%bb%a4%e7%a2%bc%e4%bb%a5utf16le%e7%b7%a8%e7%a2%bc%e5%95%8f%e9%a1%8c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
