<?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; Ling&#039;s Note</title>
	<atom:link href="https://www.chunho-ling.com/category/computing/database/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.chunho-ling.com</link>
	<description>Everything related IT, and me.</description>
	<lastBuildDate>Fri, 30 Nov 2018 06:41:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
<site xmlns="com-wordpress:feed-additions:1">104401516</site>	<item>
		<title>[SQL Server] 利用batch 備份資料庫</title>
		<link>https://www.chunho-ling.com/sql-server-%e5%88%a9%e7%94%a8batch-%e5%82%99%e4%bb%bd%e8%b3%87%e6%96%99%e5%ba%ab/</link>
					<comments>https://www.chunho-ling.com/sql-server-%e5%88%a9%e7%94%a8batch-%e5%82%99%e4%bb%bd%e8%b3%87%e6%96%99%e5%ba%ab/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Fri, 30 Nov 2018 06:41:47 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[DOS]]></category>
		<category><![CDATA[Infrastructure 基建]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">https://www.chunho-ling.com/?p=1144</guid>

					<description><![CDATA[備份資料庫除了利用內部 SQL Server Agent 的schedule job 外, 還可以透過指令檔進行. 這樣的好處是可以透過中央化管理的形式去管理排程工作.建立Batch 檔案並命名為 databaseBackup.bat. echo off REM File name : databaseBackup.bat REM Author : Ling REM Description : Backup SQL server in file format. REM Syntax : databaseBackup <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-%e5%88%a9%e7%94%a8batch-%e5%82%99%e4%bb%bd%e8%b3%87%e6%96%99%e5%ba%ab/" title="[SQL Server] 利用batch 備份資料庫">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>備份資料庫除了利用內部 SQL Server Agent 的schedule job 外, 還可以透過指令檔進行. 這樣的好處是可以透過中央化管理的形式去管理排程工作.<span id="more-1144"></span>建立Batch 檔案並命名為 databaseBackup.bat.</p>
<pre class="lang:default decode:true " title="databaseBackup.bat">echo off 
REM File name	: databaseBackup.bat
REM Author		: Ling
REM Description	: Backup SQL server in file format.
REM Syntax		: databaseBackup &lt;&lt;user_name&gt;&gt; &lt;&lt;password&gt;&gt; &lt;&lt;serverName&gt;&gt; &lt;&lt;databaseName&gt;&gt;

REM Initial settings.
set currentDateTime=%date:~6,4%%date:~3,2%%date:~0,2%%time:~0,2%%time:~3,2%%time:~3,2%
set userName=%1
set password=%2
set serverName=%3
set databaseName=%4

set BACKUPFILENAME=%databaseName%-%currentDateTime%.bak
set logFilePath=C:\DBBackup\log\%currentDateTime%_%serverName%_%databaseName%.log

echo %date% database backup start, file name: %BACKUPFILENAME%
echo %date% database backup start, file name: %BACKUPFILENAME% &gt;&gt; %logFilePath%
sqlcmd -U %userName% -P %password% -S %serverName% -Q "BACKUP DATABASE [%databaseName%] TO DISK = '%BACKUPFILENAME%' WITH FORMAT" -b &gt;&gt; %logFilePath%
if %ERRORLEVEL% EQU 0 (
	echo %date% backup success. 
	echo %date% backup success. &gt;&gt; %logFilePath%
	echo log located in %logFilePath%
) ELSE (
	echo %date% backup failure.
	echo %date% backup failure. &gt;&gt; %logFilePath%
	echo log located in %logFilePath%
	exit /b 1
)</pre>
<p>值得一提是在指令sqlcmd 中, -b 是指將結果以errorlevel 傳回, 以確定結果能否順利執行, 否則全部都會得到0.</p>
<p>而 exit 中, /b &lt;&lt;error_level_number&gt;&gt; 結束執行時傳回的errorlevel. 以讓執行的program 知道其結果.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-%e5%88%a9%e7%94%a8batch-%e5%82%99%e4%bb%bd%e8%b3%87%e6%96%99%e5%ba%ab/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1144</post-id>	</item>
		<item>
		<title>[SQL server] 解決 rename database 時出現exclusive lock 問題</title>
		<link>https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba-rename-database-%e6%99%82%e5%87%ba%e7%8f%beexclusive-lock-%e5%95%8f%e9%a1%8c/</link>
					<comments>https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba-rename-database-%e6%99%82%e5%87%ba%e7%8f%beexclusive-lock-%e5%95%8f%e9%a1%8c/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Thu, 19 Jul 2018 01:37:43 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database Design 數據庫設計]]></category>
		<category><![CDATA[Infrastructure 基建]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=1076</guid>

					<description><![CDATA[當rename database 時, 有時會出現elusive lock 問題. 這是因為執行時有其他user 正在使用而令database locked. 解決這個問題, 除了offline database 再rename名, 還可以把database 轉為single user mode 後再 rename, 有關的 SQL command 如下: USE master; --Set the database to single mode. ALTER DATABASE &#60;&#60;dbName&#62;&#62; SET <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba-rename-database-%e6%99%82%e5%87%ba%e7%8f%beexclusive-lock-%e5%95%8f%e9%a1%8c/" title="[SQL server] 解決 rename database 時出現exclusive lock 問題">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>當rename database 時, 有時會出現elusive lock 問題. 這是因為執行時有其他user 正在使用而令database locked. <span id="more-1076"></span>解決這個問題, 除了offline database 再rename名, 還可以把database 轉為single user mode 後再 rename, 有關的 SQL command 如下:</p>
<pre class="lang:tsql decode:true ">USE master;
--Set the database to single mode.
ALTER DATABASE &lt;&lt;dbName&gt;&gt;
SET SINGLE_USER WITH ROLLBACK IMMEDIATE

--Try to rename the database.
ALTER DATABASE &lt;&lt;dbName&gt;&gt; MODIFY NAME = &lt;&lt;NewDBName&gt;&gt;

--Set the database to Multiuser mode.
ALTER DATABASE &lt;&lt;NewDBName&gt;&gt;
SET MULTI_USER WITH ROLLBACK IMMEDIATE</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba-rename-database-%e6%99%82%e5%87%ba%e7%8f%beexclusive-lock-%e5%95%8f%e9%a1%8c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1076</post-id>	</item>
		<item>
		<title>[SQL server] 解決將資料庫 Offline 時出現的錯誤</title>
		<link>https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba%e5%b0%87%e8%b3%87%e6%96%99%e5%ba%ab-offline-%e6%99%82%e5%87%ba%e7%8f%be%e7%9a%84%e9%8c%af%e8%aa%a4/</link>
					<comments>https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba%e5%b0%87%e8%b3%87%e6%96%99%e5%ba%ab-offline-%e6%99%82%e5%87%ba%e7%8f%be%e7%9a%84%e9%8c%af%e8%aa%a4/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Tue, 23 Jan 2018 06:10:42 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=829</guid>

					<description><![CDATA[有時進行維護時, 總會須要將系統offline. 但有時會出現錯誤指TABLE 被Lock. 這是因為執行ALTER TABLE 時, 會見到有process 仍在執行.若要檢查是什麼process, 可以執行以下SQL server 指令. EXEC sp_who2; 之後再檢查欄DBName, 找出相對應的SPID, 之後再執行KILL 指令. kill &#60;&#60;SPID&#62;&#62;; 通常有關的SPID 都不只一個, 若要批量形式 KILL 的話, 可以利用SQL script 如下 declare @DBName varchar(60); declare @killCommand varchar(60); declare <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba%e5%b0%87%e8%b3%87%e6%96%99%e5%ba%ab-offline-%e6%99%82%e5%87%ba%e7%8f%be%e7%9a%84%e9%8c%af%e8%aa%a4/" title="[SQL server] 解決將資料庫 Offline 時出現的錯誤">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>有時進行維護時, 總會須要將系統offline. 但有時會出現錯誤指TABLE 被Lock. 這是因為執行ALTER TABLE 時, 會見到有process 仍在執行.<span id="more-829"></span>若要檢查是什麼process, 可以執行以下SQL server 指令.</p>
<pre class="lang:default decode:true ">EXEC sp_who2;</pre>
<p>之後再檢查欄DBName, 找出相對應的SPID, 之後再執行KILL 指令.</p>
<pre class="lang:default decode:true ">kill &lt;&lt;SPID&gt;&gt;;</pre>
<p>通常有關的SPID 都不只一個, 若要批量形式 KILL 的話, 可以利用SQL script 如下</p>
<pre class="lang:default decode:true  ">declare @DBName varchar(60);
declare @killCommand varchar(60);
declare @id int;

set @DBName='&lt;&lt;TargetDataBase&gt;&gt;';

declare processIdCursor cursor for
select P.spid
FROM master..sysprocesses P,
master..sysdatabases D
WHERE
D.dbid = P.dbid
and d.NAME=@DBName
;
open processIdCursor
FETCH NEXT FROM processIdCursor INTO @id 
WHILE @@FETCH_STATUS = 0
begin
	set @killCommand = 'KILL ' + convert(varchar(8) ,@id)+';';
	print @killCommand;
	exec(@killCommand);
	FETCH NEXT FROM processIdCursor INTO @id 
END   
CLOSE processIdCursor   
DEALLOCATE processIdCursor</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-%e8%a7%a3%e6%b1%ba%e5%b0%87%e8%b3%87%e6%96%99%e5%ba%ab-offline-%e6%99%82%e5%87%ba%e7%8f%be%e7%9a%84%e9%8c%af%e8%aa%a4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">829</post-id>	</item>
		<item>
		<title>[SQL Server] 如何為Instance重新命名</title>
		<link>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e7%82%bainstance%e9%87%8d%e6%96%b0%e5%91%bd%e5%90%8d/</link>
					<comments>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e7%82%bainstance%e9%87%8d%e6%96%b0%e5%91%bd%e5%90%8d/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Fri, 24 Mar 2017 09:26:40 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Infrastructure 基建]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=614</guid>

					<description><![CDATA[當Server Sysprep 完 OOBE (Out-of-Box Experience)後, GUID 通常都會重新分派, 但如果之前安裝了SQL server 的話, Instance 名因為儲了在master DB 內, 故有機會與Seed image 同名. 要檢查的話, 可以執行以下SQL statement 去查看現在的Instance 名稱. SELECT @@SERVERNAME AS 'Server Name'; 若要修改的話, 則要執行以下SQL script. sp_dropserver '&#60;&#60;Old Server Name&#62;&#62;'; <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e7%82%bainstance%e9%87%8d%e6%96%b0%e5%91%bd%e5%90%8d/" title="[SQL Server] 如何為Instance重新命名">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>當Server Sysprep 完 OOBE (Out-of-Box Experience)後, GUID 通常都會重新分派, 但如果之前安裝了SQL server 的話, Instance 名因為儲了在master DB 內, 故有機會與Seed image 同名.<span id="more-614"></span></p>
<p>要檢查的話, 可以執行以下SQL statement 去查看現在的Instance 名稱.</p>
<pre class="lang:tsql decode:true ">SELECT @@SERVERNAME AS 'Server Name';</pre>
<p>若要修改的話, 則要執行以下SQL script.</p>
<pre class="lang:tsql decode:true ">sp_dropserver '&lt;&lt;Old Server Name&gt;&gt;';
GO
sp_addserver '&lt;&lt;New Server Name&gt;&gt;', local;
GO</pre>
<p>Restart SQL server 後, 再執行上便的Select statement 確定結果.</p>
<p>Reference</p>
<p><a href="https://blog.dhampir.no/content/renaming-an-mssql-instance-invalid-urn-filter-on-server-level" target="_blank">boltblog,&nbsp;https://blog.dhampir.no/content/renaming-an-mssql-instance-invalid-urn-filter-on-server-level</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e7%82%bainstance%e9%87%8d%e6%96%b0%e5%91%bd%e5%90%8d/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">614</post-id>	</item>
		<item>
		<title>[SQL server] 加入Oracle 作 Linked server</title>
		<link>https://www.chunho-ling.com/sql-server-%e5%8a%a0%e5%85%a5oracle-%e4%bd%9c-linked-server/</link>
					<comments>https://www.chunho-ling.com/sql-server-%e5%8a%a0%e5%85%a5oracle-%e4%bd%9c-linked-server/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Fri, 10 Mar 2017 10:07:42 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=590</guid>

					<description><![CDATA[當做系統整合時, 將不同database 接駁是其中一項平常事. SQL server 之間接駁沒啥難度, 然而, SQL server 接駁Oracle卻大有學問, 在這裡, 會示範如何在SQL server 中制作Oracle Link Database. 先下載及安裝Oracle Client. 於Option 中選擇 Runtime only 便可; 64 bit &#160;http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html 32 Bit&#160; http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html 安裝後開啟SQL Server Management Studio (SSMS), 用sa <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-%e5%8a%a0%e5%85%a5oracle-%e4%bd%9c-linked-server/" title="[SQL server] 加入Oracle 作 Linked server">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>當做系統整合時, 將不同database 接駁是其中一項平常事. SQL server 之間接駁沒啥難度, 然而, SQL server 接駁Oracle卻大有學問, 在這裡, 會示範如何在SQL server 中制作Oracle Link Database.<span id="more-590"></span></p>
<ol>
<li>先下載及安裝Oracle Client. 於Option 中選擇 Runtime only 便可;
<ul>
<li>64 bit<br />
&nbsp;<a href="http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html" target="_blank">http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html</a></li>
<li>32 Bit&nbsp;<br />
<a href="http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html" target="_blank">http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html</a></li>
</ul>
</li>
<li>安裝後開啟SQL Server Management Studio (SSMS), 用sa 權限登入後, 打開Server Objects &gt; Linked Servers &gt; Providers, 確定Oracle Data Provider 已經安裝.<br />
<img data-recalc-dims="1" fetchpriority="high" decoding="async" class="alignnone size-medium wp-image-591" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_21_17-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C288&#038;ssl=1" alt="" width="300" height="288" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_21_17-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C288&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_21_17-Microsoft-SQL-Server-Management-Studio-Administrator.png?w=304&amp;ssl=1 304w" sizes="(max-width: 300px) 100vw, 300px" /></li>
<li>設定在SQL server 中使用 Provider, 令它可以存取相關的Providor dll files.<br />
在OraOLEDB.Oracle 中右鍵&gt;Property, ;在 General &gt; Provider Option 中剔取Allow Inprocess<br />
<img data-recalc-dims="1" decoding="async" class="alignnone size-medium wp-image-592" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_23_36-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C250&#038;ssl=1" alt="" width="300" height="250" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_23_36-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C250&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_23_36-Microsoft-SQL-Server-Management-Studio-Administrator.png?w=709&amp;ssl=1 709w" sizes="(max-width: 300px) 100vw, 300px" /></li>
<li>開始建立Oracle Linked Server.<br />
在Linked Server 中右鍵, 選取New Linked Server.<img data-recalc-dims="1" decoding="async" class="alignnone size-medium wp-image-593" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_24_20-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C251&#038;ssl=1" alt="" width="300" height="251" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_24_20-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C251&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_24_20-Microsoft-SQL-Server-Management-Studio-Administrator.png?w=316&amp;ssl=1 316w" sizes="(max-width: 300px) 100vw, 300px" /></li>
<li>在Oracle 中, 設定如下:
<ol>
<li>Linked Name: Linked Server 的名字</li>
<li>Provider: Oracle Provide for OLE DB</li>
<li>Product Name: Oracle</li>
<li>Data Source: tnsname 的名字, 可以在%ORACLE_HOME%\client_1\NETWORK\ADMIN\tnsname.ora 中找到.<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-594" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_25_48-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C251&#038;ssl=1" alt="" width="300" height="251" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_25_48-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C251&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_25_48-Microsoft-SQL-Server-Management-Studio-Administrator.png?w=708&amp;ssl=1 708w" sizes="auto, (max-width: 300px) 100vw, 300px" /></li>
</ol>
</li>
<li>選取Security, 選取Be made using this security context, 並在此輸入預設的Credential.&nbsp;<br />
<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-595" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_27_17-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C248&#038;ssl=1" alt="" width="300" height="248" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_27_17-Microsoft-SQL-Server-Management-Studio-Administrator.png?resize=300%2C248&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_27_17-Microsoft-SQL-Server-Management-Studio-Administrator.png?w=710&amp;ssl=1 710w" sizes="auto, (max-width: 300px) 100vw, 300px" /></li>
<li>執行SQL statement 進行測試, 若有column 傳回表示測試成功.<br />
<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-596" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-09_33_27-SQLQuery1.sql-10.30.12.191.master-sa-55_-Microsoft-SQL-Server-Management.png?resize=286%2C185&#038;ssl=1" alt="" width="286" height="185"></li>
</ol>
<p>有時除了table 外, 若要執行Oracle 的 store procedure /package function, 則須要再另外設定如下:</p>
<ol>
<li>在安裝Oracle Client 時, 選擇Custom Install 並剔取Oracle Services For Microsoft Transaction Server.<br />
<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-598" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-16_41_24-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?resize=300%2C235&#038;ssl=1" alt="" width="300" height="235" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-16_41_24-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?resize=300%2C235&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-09-16_41_24-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?w=663&amp;ssl=1 663w" sizes="auto, (max-width: 300px) 100vw, 300px" /></li>
<li>開啟SQL server 的Component Services, 選取Component Services &gt; Computers &gt; My Computer &gt; Distributed Transaction Coordinator &gt;Local DTC, 右鍵選取Properties<br />
<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-601" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-09_07_57-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?resize=300%2C221&#038;ssl=1" alt="" width="300" height="221" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-09_07_57-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?resize=300%2C221&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-09_07_57-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?resize=80%2C60&amp;ssl=1 80w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-09_07_57-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?w=422&amp;ssl=1 422w" sizes="auto, (max-width: 300px) 100vw, 300px" /></li>
<li>開啟Security Tag, 剔取Network DTC Access, Allow Remote Client, Allow Inbount 和Allow Outbound 後按OK, 之後會重新啟動MSDTC.<br />
<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-602" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-09_08_09-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?resize=278%2C300&#038;ssl=1" alt="" width="278" height="300" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-09_08_09-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?resize=278%2C300&amp;ssl=1 278w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-09_08_09-10.30.12.191-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A.png?w=469&amp;ssl=1 469w" sizes="auto, (max-width: 278px) 100vw, 278px" /></li>
</ol>
<p>Reference</p>
<ul>
<li><a href="http://sqlmag.com/sql-server/connecting-sql-server-and-oracle-using-linked-servers" target="_blank">Connecting SQL Server and Oracle Using Linked Servers, Michael Otey, SQL Server Pro, http://sqlmag.com/sql-server/connecting-sql-server-and-oracle-using-linked-servers</a></li>
<li><a href="https://blogs.msdn.microsoft.com/psssql/2015/07/31/how-to-get-up-and-running-with-oracle-and-linked-servers/" target="_blank">How to get up and running with Oracle and Linked Servers, psssql, Microsoft,&nbsp;https://blogs.msdn.microsoft.com/psssql/2015/07/31/how-to-get-up-and-running-with-oracle-and-linked-servers/</a></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-%e5%8a%a0%e5%85%a5oracle-%e4%bd%9c-linked-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">590</post-id>	</item>
		<item>
		<title>[SQL Server] 如何 join 不同 Codec 的 tables</title>
		<link>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95-join-%e4%b8%8d%e5%90%8c-codec-%e7%9a%84-tables/</link>
					<comments>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95-join-%e4%b8%8d%e5%90%8c-codec-%e7%9a%84-tables/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Fri, 10 Mar 2017 08:20:13 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=606</guid>

					<description><![CDATA[利用SQL statement做Report時, join table 是無可避免的. 但如果join 不同database 的 table 時, 有機會出現錯誤信息如下: Msg 468, Level 16, State 9, Line 11 Cannot resolve the collation conflict between &#8220;Chinese_Taiwan_Bopomofo_BIN&#8221; and &#8220;Chinese_Hong_Kong_Stroke_90_CI_AS&#8221; in the equal to operation. 這是因為不同 database <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95-join-%e4%b8%8d%e5%90%8c-codec-%e7%9a%84-tables/" title="[SQL Server] 如何 join 不同 Codec 的 tables">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>利用SQL statement做Report時, join table 是無可避免的. 但如果join 不同database 的 table 時, 有機會出現錯誤信息如下:</p>
<p>Msg 468, Level 16, State 9, Line 11<br />
Cannot resolve the collation conflict between &#8220;Chinese_Taiwan_Bopomofo_BIN&#8221; and &#8220;Chinese_Hong_Kong_Stroke_90_CI_AS&#8221; in the equal to operation.<span id="more-606"></span></p>
<p>這是因為不同 database 的collate setting 不同而令join table 時出現問題. 若想知道自己database, 可以於SSMS 中的database 中右鍵 &gt; Properties, 在General 中會見到其相對應的 Collate.<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-608" src="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-16_11_32-SQLQuery3.sql-10.30.12.191.AAS-sa-53_-Microsoft-SQL-Server-Management-St.png?resize=300%2C272&#038;ssl=1" alt="" width="300" height="272" srcset="https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-16_11_32-SQLQuery3.sql-10.30.12.191.AAS-sa-53_-Microsoft-SQL-Server-Management-St.png?resize=300%2C272&amp;ssl=1 300w, https://i0.wp.com/www.chunho-ling.com/wp-content/uploads/2017/03/2017-03-10-16_11_32-SQLQuery3.sql-10.30.12.191.AAS-sa-53_-Microsoft-SQL-Server-Management-St.png?w=696&amp;ssl=1 696w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>要解決的話, 最直接的方法就是在join table 時加入&nbsp;COLLATE database_default, 使SQL server join table 預設用預設的collate. 用法如下:</p>
<pre class="lang:tsql decode:true ">SELECT User.*
FROM User U, [RemoteDatabase].[Authorization].dbo.Privilege P
WHERE U.UserID=P.UserID COLLATE Database_Default
;</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95-join-%e4%b8%8d%e5%90%8c-codec-%e7%9a%84-tables/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">606</post-id>	</item>
		<item>
		<title>[SQL Server] 如何修改user / login 的mapping</title>
		<link>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9user-login-%e7%9a%84mapping/</link>
					<comments>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9user-login-%e7%9a%84mapping/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Sat, 28 Jan 2017 01:30:05 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=576</guid>

					<description><![CDATA[有時搬SQL server 時, 正路的方法, 當然是於新DB server 建立schema及相關user privilage, 再透過ETL 將data full load 過去, 然後再從application level 修改 connection string 指往新DB server. 但有時只有一個bak file, restore 後再建立login 時, 會出現user group already existed的錯誤訊息. 這是因為與DB user name 的名字相同所致. 若在須要保留相同user name <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9user-login-%e7%9a%84mapping/" title="[SQL Server] 如何修改user / login 的mapping">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>有時搬SQL server 時, 正路的方法, 當然是於新DB server 建立schema及相關user privilage, 再透過ETL 將data full load 過去, 然後再從application level 修改 connection string 指往新DB server. 但有時只有一個bak file, restore 後再建立login 時, 會出現user group already existed的錯誤訊息. 這是因為與DB user name 的名字相同所致.<span id="more-576"></span></p>
<p>若在須要保留相同user name 下, 便須要執行SP sp_change_users_login 指回正確的user / login.</p>
<p>語法如下:</p>
<pre class="lang:tsql decode:true  ">EXEC sp_change_users_login 'Update_One', '&lt;&lt;user name&gt;&gt;', '&lt;&lt;login name&gt;&gt;';</pre>
<p>Reference</p>
<ul>
<li><a href="https://technet.microsoft.com/en-us/library/ms174378%28v=sql.110%29.aspx?f=255&amp;MSPPError=-2147217396" target="_blank">sp_change_users_login (Transact-SQL), Microsoft TechNet</a></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9user-login-%e7%9a%84mapping/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">576</post-id>	</item>
		<item>
		<title>[Entity Framework] 如何加入SQL server Function</title>
		<link>https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/</link>
					<comments>https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Wed, 02 Nov 2016 09:35:20 +0000</pubDate>
				<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=155</guid>

					<description><![CDATA[有時寫code時, 有需要call 到SQL server 內的Function 但卻不能順利進行. 除了DataContext.ExecuteCommand()進行外, 還可以透過DbFunctionAttribute使用. 使用時EntityFramework 會直接call SQL server function 並return 其value. [DbFunction("hkcfDataModel.Store", "GetDonorName")] public string GetDonorName(string nvchCompanyName, string nvchTcFirstName, string nvchTcLastName, string nvchTcPrefix, string vchEnFirstName, string vchEnLastName, string vchEnPrefix, string vchLang) <a class="mh-excerpt-more" href="https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/" title="[Entity Framework] 如何加入SQL server Function">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>有時寫code時, 有需要call 到SQL server 內的Function 但卻不能順利進行. 除了DataContext.ExecuteCommand()進行外, 還可以透過DbFunctionAttribute使用.</p>
<p><span id="more-155"></span>使用時EntityFramework 會直接call SQL server function 並return 其value.</p>
<pre class="lang:c# decode:true " title="DbFunctionExmaple">[DbFunction("hkcfDataModel.Store", "GetDonorName")]
public string GetDonorName(string nvchCompanyName, string nvchTcFirstName, string nvchTcLastName, string nvchTcPrefix, string vchEnFirstName, string vchEnLastName, string vchEnPrefix, string vchLang)
{
    throw new NotSupportedException("Direct call does not supported.");
}</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">155</post-id>	</item>
		<item>
		<title>[SQL Server] Backup / Restore 特定 tables</title>
		<link>https://www.chunho-ling.com/sql-server-backup-restore-%e7%89%b9%e5%ae%9a-tables/</link>
					<comments>https://www.chunho-ling.com/sql-server-backup-restore-%e7%89%b9%e5%ae%9a-tables/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Thu, 29 Sep 2016 02:29:40 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=152</guid>

					<description><![CDATA[當進行測試時, 有時為了測試不同程式是否得到相同結果(如Regression Test), 重覆restore DB 會是其中一個手段. 然而DBA 與developer 不是同一人時, 便會令測試變得麻煩. 故在測試時backup 指定table, 事後再restore 會是更快的方法. 在SQL server 中, 可以利用bcp command 進行table level 的backup / restore. 做法如下. ## Backup pledge table. ensure user have proper privilege. bcp <a class="mh-excerpt-more" href="https://www.chunho-ling.com/sql-server-backup-restore-%e7%89%b9%e5%ae%9a-tables/" title="[SQL Server] Backup / Restore 特定 tables">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>當進行測試時, 有時為了測試不同程式是否得到相同結果(如Regression Test), 重覆restore DB 會是其中一個手段. 然而DBA 與developer 不是同一人時, 便會令測試變得麻煩. 故在測試時backup 指定table, 事後再restore 會是更快的方法.</p>
<p><span id="more-152"></span></p>
<p>在SQL server 中, 可以利用bcp command 進行table level 的backup / restore. 做法如下.</p>
<pre class="lang:default decode:true">## Backup pledge table. ensure user have proper privilege.
bcp "select * from [DB_NAME].dbo.[TABLE_NAME]" queryout "[BKUP_FILE_NAME].bcp" -N -S &lt;&lt;Server Name&gt;&gt; -T -E -k

## Restore
bcp "[DB_NAME].dbo.[TABLE_NAME]" in "[BKUP_FILE_NAME].bcp" -N -S &lt;&lt;Server Name&gt;&gt; -T -E -b 10000</pre>
<p>然而, 在restore 前, 但它有部份限制:</p>
<ul>
<li>會被key constrain 限制restore.</li>
<li>須要Truncate table 才能夠進行restore.</li>
</ul>
<p>當然, 如果只用作backup 又restore到不同table 的話, 還有更快的方法:</p>
<pre class="lang:tsql decode:true">SELECT * INTO [NEW_TABLE_NAME] FROM [ORIGINAL_TABLE_NAME]</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/sql-server-backup-restore-%e7%89%b9%e5%ae%9a-tables/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">152</post-id>	</item>
	</channel>
</rss>
