<?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>Another My Program &#187; SQL Server</title>
	<atom:link href="http://tim.diary.tw/tag/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://tim.diary.tw</link>
	<description>just another my program</description>
	<lastBuildDate>Sun, 29 Jan 2012 10:40:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://tim.diary.tw/?pushpress=hub'/>
		<item>
		<title>SQL Server的Replication中的Article必須要有Primary Key</title>
		<link>http://tim.diary.tw/2011/05/06/sql-server%e7%9a%84replication%e4%b8%ad%e7%9a%84article%e5%bf%85%e9%a0%88%e8%a6%81%e6%9c%89primary-key/</link>
		<comments>http://tim.diary.tw/2011/05/06/sql-server%e7%9a%84replication%e4%b8%ad%e7%9a%84article%e5%bf%85%e9%a0%88%e8%a6%81%e6%9c%89primary-key/#comments</comments>
		<pubDate>Fri, 06 May 2011 09:54:22 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[Primary Key]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/?p=158</guid>
		<description><![CDATA[這個是朋友請我查的資料, 其實邏輯上還蠻容易的, 因為 SQL Server的Transactional Replication是參考table的primary key來進行新增刪除修改的, 若是該table沒有primary key的話, 是沒有辦法加入到publication的article裡的. 資料可以參考這裡: http://msdn.microsoft.com/en-US/library/ms152559%28v=SQL.90%29.aspx 其中的: Limitations on Publishing Objects The maximum number of articles and columns that can be published differs by publication type. For more information, see the "Replication Objects" section of Maximum Capacity Specifications for SQL Server 2005. Stored procedures, views, triggers, and user-defined functions [...]]]></description>
			<content:encoded><![CDATA[<p>這個是朋友請我查的資料, 其實邏輯上還蠻容易的, 因為 SQL Server的Transactional Replication是參考table的primary key來進行新增刪除修改的, 若是該table沒有primary key的話, 是沒有辦法加入到publication的article裡的.</p>
<p>資料可以參考這裡:</p>
<p><a href="http://msdn.microsoft.com/en-US/library/ms152559%28v=SQL.90%29.aspx">http://msdn.microsoft.com/en-US/library/ms152559%28v=SQL.90%29.aspx</a></p>
<p>其中的:</p>
<blockquote>
<h3>Limitations on Publishing Objects</h3>
<ul>
<li> The maximum number of articles and columns that can be  published differs by publication type. For more information, see the  "Replication Objects" section of Maximum Capacity Specifications for SQL Server 2005.</li>
<li> Stored procedures, views, triggers, and user-defined functions that are defined as <strong>WITH ENCRYPTION</strong> cannot be published as part of SQL Server replication.</li>
<li> XML schema collections can be replicated but changes are not replicated after the initial snapshot.</li>
<li> <span style="color: #ff0000">Tables published for transactional replication must have a  primary key.</span> If a table is in a transactional replication publication,  you cannot disable any indexes that are associated with primary key  columns. These indexes are required by replication. To disable an index,  you must first drop the table from the publication.</li>
<li> Bound defaults created with sp_bindefault (Transact-SQL) are not replicated (bound defaults are deprecated in favor of defaults  created with the DEFAULT keyword of ALTER TABLE or CREATE TABLE).</li>
</ul>
</blockquote>
<p>&nbsp;</p>
<p>上面紅字部分就是說明這個限制.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2011/05/06/sql-server%e7%9a%84replication%e4%b8%ad%e7%9a%84article%e5%bf%85%e9%a0%88%e8%a6%81%e6%9c%89primary-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Optimization</title>
		<link>http://tim.diary.tw/2010/11/09/sql-server-optimization/</link>
		<comments>http://tim.diary.tw/2010/11/09/sql-server-optimization/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 05:46:05 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/?p=136</guid>
		<description><![CDATA[這篇文章寫得十分有用, 建議有在做資料庫效能調校的朋友們可以讀一下. http://msdn.microsoft.com/en-us/library/aa964133%28SQL.90%29.aspx 其中最後有還蠻精要的整理, 也就是這段落: Optimization Rules of Thumb 對於 index 等的設計都有蠻好的解說及經驗, 利用執行計劃 (execution plan) 的數據資料來檢視索引建立的狀況是否良好, 而且也應該適時更新統計資料(statistics), 利用這個指令: update statistics &#60;TableName&#62;, 更新好統計資料的 table , 再來檢視執行計劃, 會更準確. 另外查詢時, 儘量不要對資料欄位進行操作, 也就是以原本的資料來做比對及判斷, 查詢引擎才會使用對應的索引, 若利用了函數或一些轉型, 讓原始欄位改變的查詢條件, 查詢引擎就沒有辦法使用索引帶來的好處了, 如文章中舉的例子, 像是: cast(DateField as varchar(20)) = @dateString 應該調整為 @dateString 轉型成為 DateField 的型態, 再來進行查詢, 肯定效果會更好, 另外還有這個例子(不是文章中提到的)也是很經典, 像是 Left(VarCharField, 1) = &#8216;k&#8217; 應該要改為 VarCharField [...]]]></description>
			<content:encoded><![CDATA[<p>這篇文章寫得十分有用, 建議有在做資料庫效能調校的朋友們可以讀一下.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa964133%28SQL.90%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/aa964133%28SQL.90%29.aspx</a></p>
<p>其中最後有還蠻精要的整理, 也就是這段落: Optimization Rules of Thumb</p>
<p>對於 index 等的設計都有蠻好的解說及經驗, 利用執行計劃 (execution plan) 的數據資料來檢視索引建立的狀況是否良好, 而且也應該適時更新統計資料(statistics), 利用這個指令: update statistics &lt;TableName&gt;, 更新好統計資料的 table , 再來檢視執行計劃, 會更準確.</p>
<p>另外查詢時, 儘量不要對資料欄位進行操作, 也就是以原本的資料來做比對及判斷, 查詢引擎才會使用對應的索引, 若利用了函數或一些轉型, 讓原始欄位改變的查詢條件, 查詢引擎就沒有辦法使用索引帶來的好處了, 如文章中舉的例子, 像是:</p>
<p>cast(DateField as varchar(20)) = @dateString</p>
<p>應該調整為 @dateString 轉型成為 DateField 的型態, 再來進行查詢, 肯定效果會更好, 另外還有這個例子(不是文章中提到的)也是很經典, 像是</p>
<p>Left(VarCharField, 1) = &#8216;k&#8217;</p>
<p>應該要改為</p>
<p>VarCharField like &#8216;k%&#8217;</p>
<p>這樣也是較函數來得佳, 都是可以改善查詢效能的.</p>
<p>試看看, 應該都有空間可以再精進!</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2010/11/09/sql-server-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 中的 Pivot 語法</title>
		<link>http://tim.diary.tw/2010/07/07/sql-server-pivo/</link>
		<comments>http://tim.diary.tw/2010/07/07/sql-server-pivo/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 04:02:20 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[程式技術]]></category>
		<category><![CDATA[資料庫]]></category>
		<category><![CDATA[pivot]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/?p=122</guid>
		<description><![CDATA[從 SQL Server 2005 起, 支援了 Pivot 語法及 UnPivot 語法. 利用 Pivot 語法, 可以做出一些轉置及特殊報表使用的查詢結果(對於要分析資料時特別有用). 先來建立範例資料, 這個資料表是一個流水號(logid, 一個會員編號 userno, 一個投票標的號 voteid, 一個時間欄位 createtime), 為能將資料表模擬真實的狀況, 建立一些資料來供應用, script 如下: CREATE TABLE VOTELOG (logid int identity(1,1), userno int, voteid int, createtime datetime default getdate()) insert into VOTELOG (userno, voteid, createtime) values (1, 1, &#039;2010/7/1 1:15&#039;) insert into VOTELOG (userno, [...]]]></description>
			<content:encoded><![CDATA[<p>從 SQL Server 2005 起, 支援了 Pivot 語法及 UnPivot 語法.</p>
<p>利用 Pivot 語法, 可以做出一些轉置及特殊報表使用的查詢結果(對於要分析資料時特別有用).</p>
<p>先來建立範例資料, 這個資料表是一個流水號(logid, 一個會員編號 userno, 一個投票標的號 voteid, 一個時間欄位 createtime), 為能將資料表模擬真實的狀況, 建立一些資料來供應用, script 如下:</p>
<pre class="brush: sql">

CREATE TABLE VOTELOG (logid int identity(1,1), userno int, voteid int, createtime datetime default getdate())
insert into VOTELOG (userno, voteid, createtime) values (1, 1, &#039;2010/7/1 1:15&#039;)
insert into VOTELOG (userno, voteid, createtime) values (2, 1, &#039;2010/7/1 3:27&#039;)
insert into VOTELOG (userno, voteid, createtime) values (4, 2, &#039;2010/7/1 3:29&#039;)
insert into VOTELOG (userno, voteid, createtime) values (15, 2, &#039;2010/7/1 16:31&#039;)
insert into VOTELOG (userno, voteid, createtime) values (35, 1, &#039;2010/7/1 17:31&#039;)
insert into VOTELOG (userno, voteid, createtime) values (24, 1, &#039;2010/7/1 17:38&#039;)
insert into VOTELOG (userno, voteid, createtime) values (8, 2, &#039;2010/7/1 20:18&#039;)
insert into VOTELOG (userno, voteid, createtime) values (7, 2, &#039;2010/7/2 2:22&#039;)
insert into VOTELOG (userno, voteid, createtime) values (32, 1, &#039;2010/7/2 2:36&#039;)
insert into VOTELOG (userno, voteid, createtime) values (9, 1, &#039;2010/7/2 10:09&#039;)
insert into VOTELOG (userno, voteid, createtime) values (25, 2, &#039;2010/7/2 13:35&#039;)
insert into VOTELOG (userno, voteid, createtime) values (19, 2, &#039;2010/7/2 18:19&#039;)
insert into VOTELOG (userno, voteid, createtime) values (16, 2, &#039;2010/7/2 19:28&#039;)
insert into VOTELOG (userno, voteid, createtime) values (6, 1, &#039;2010/7/2 23:06&#039;)
insert into VOTELOG (userno, voteid, createtime) values (36, 2, &#039;2010/7/3 0:42&#039;)
insert into VOTELOG (userno, voteid, createtime) values (18, 2, &#039;2010/7/3 2:19&#039;)
</pre>
<p>假如現在我們需要分時的每日投票狀況的報表, 可以使用如下的 pivot查詢:</p>
<pre class="brush: sql">

select dates, [0],[1],[2],[3],[4],[5],[6],[7], [8],[9],[10],[11],[12],[13],[14],[15], [16],[17],[18],[19],[20],[21],[22],[23]
from (select convert(varchar, createtime, 111) as dates, datepart(hh, createtime) as hours from votelog ) as cum
pivot (count(hours) for hours in ( [0],[1],[2],[3],[4],[5],[6],[7], [8],[9],[10],[11],[12],[13],[14],[15], [16],[17],[18],[19],[20],[21],[22],[23] )) as pv
</pre>
<p>查詢結果如下:</p>
<p><img class="alignnone size-full wp-image-123" title="result" src="http://tim.diary.tw/files/2010/07/result.png" alt="" width="483" height="73" /></p>
<p>這樣可以很清楚地呈現出, 每日分時的統計狀況, 當然, 若是要查的是分開兩個候選人的結果, 僅需要在中間的子查詢(cum)的裡面多加入 where 條件即可.</p>
<p>另外多提一個部分, 這樣的查詢, 可以在子查詢先做集總, 再進行 pivot, 效果會更好(尤其在資料量愈大時), 語法如下:</p>
<pre class="brush: sql">

select dates, [0],[1],[2],[3],[4],[5],[6],[7], [8],[9],[10],[11],[12],[13],[14],[15], [16],[17],[18],[19],[20],[21],[22],[23]
from (select convert(varchar, createtime, 111) as dates, datepart(hh, createtime) as hours, count(*) as counts from votelog group by convert(varchar, createtime, 111), datepart(hh, createtime) ) as cum
pivot (count(counts) for hours in ( [0],[1],[2],[3],[4],[5],[6],[7], [8],[9],[10],[11],[12],[13],[14],[15], [16],[17],[18],[19],[20],[21],[22],[23] )) as pv
</pre>
<p>也就是在子查詢中(cum), 先 group 好, 再進行 pivot 的查詢(但記得要用sum前面count結果), 這樣的效果會更有效率.</p>
<p>pivot 及 unpivot 語法可以參考以下資料:</p>
<p>使用 PIVOT 和 UNPIVOT: <a href="http://technet.microsoft.com/zh-tw/library/ms177410%28SQL.90%29.aspx" target="_blank">http://technet.microsoft.com/zh-tw/library/ms177410%28SQL.90%29.aspx</a></p>
<p>另外有人整理好的 cross-table stored procedure也很方便, 可以參考這篇: <a href="http://www.sqlteam.com/article/dynamic-cross-tabs-pivot-tables" target="_blank">http://www.sqlteam.com/article/dynamic-cross-tabs-pivot-tables</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2010/07/07/sql-server-pivo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server中的索引離散狀況</title>
		<link>http://tim.diary.tw/2010/02/25/sql-server-index-fragmen/</link>
		<comments>http://tim.diary.tw/2010/02/25/sql-server-index-fragmen/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 06:56:37 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[fragment]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/?p=107</guid>
		<description><![CDATA[SQL Server 資料庫中的索引是用來加速查詢效率的一種方式, 利用了空間換取時間的方法來將查詢的速度增加. 既然是利用空間換取時間的方法, 代表著該存放的空間, 資料的排列狀況就會隨著時間的過去, 有資料的新增, 刪除, 修改時, 造成的索引離散狀況, 若是索引離散時, 代表著存取這些索引的 IO 量會增加, 也代表著效率會下降的狀況會發生. 如何查詢這個資料, 可以參考這篇文章: http://sharedderrick.blogspot.com/2010/02/index-fragmentation.html 有詳細的說明, 利用該查詢指令, 若是要查找特定 table 的話, 可以這樣下(SQL Server 2005以上版本): SELECT sch.name N&#8217;結構描述&#8217;, obj.name N&#8217;資料表&#8217;, inx.name AS N&#8217;索引名稱&#8217;, index_type_desc N&#8217;索引類型&#8217;, avg_fragmentation_in_percent &#8216;片段(%)&#8217;, avg_page_space_used_in_percent N&#8217;頁面飽和度(%)&#8217;, fragment_count, avg_fragment_size_in_pages, page_count FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(&#8216;TABLE_NAME&#8217;),NULL, NULL, &#8216;SAMPLED&#8217;) AS phy INNER JOIN sys.indexes [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Server 資料庫中的索引是用來加速查詢效率的一種方式, 利用了空間換取時間的方法來將查詢的速度增加.</p>
<p>既然是利用空間換取時間的方法, 代表著該存放的空間, 資料的排列狀況就會隨著時間的過去, 有資料的新增, 刪除, 修改時, 造成的索引離散狀況, 若是索引離散時, 代表著存取這些索引的 IO 量會增加, 也代表著效率會下降的狀況會發生.</p>
<p>如何查詢這個資料, 可以參考這篇文章: <a href="http://sharedderrick.blogspot.com/2010/02/index-fragmentation.html" target="_blank">http://sharedderrick.blogspot.com/2010/02/index-fragmentation.html</a> 有詳細的說明, 利用該查詢指令, 若是要查找特定 table 的話, 可以這樣下(SQL Server 2005以上版本):</p>
<p>SELECT sch.name N&#8217;結構描述&#8217;, obj.name N&#8217;資料表&#8217;,<br />
inx.name AS N&#8217;索引名稱&#8217;,<br />
index_type_desc N&#8217;索引類型&#8217;,<br />
avg_fragmentation_in_percent &#8216;片段(%)&#8217;,<br />
avg_page_space_used_in_percent N&#8217;頁面飽和度(%)&#8217;,<br />
fragment_count,<br />
avg_fragment_size_in_pages,<br />
page_count<br />
FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(&#8216;TABLE_NAME&#8217;),NULL, NULL, &#8216;SAMPLED&#8217;) AS phy<br />
INNER JOIN sys.indexes AS inx ON phy.object_id = inx.object_id AND phy.index_id = inx.index_id<br />
INNER JOIN sys.objects AS obj ON phy.object_id = obj.object_id<br />
INNER JOIN sys.schemas AS sch ON obj.schema_id = sch.schema_id<br />
WHERE index_type_desc &lt;&gt; &#8216;HEAP&#8217;  AND fragment_count IS NOT NULL AND avg_fragment_size_in_pages IS NOT NULL<br />
ORDER BY 5 DESC</p>
<p>利用了 OBJECT_ID() 函數, 把 table 的 object id 找出來, 便能指定查找特定 table 中的索引離散狀況.</p>
<p>根據微軟官方的資料: <a href="http://technet.microsoft.com/zh-tw/library/ms189858.aspx" target="_blank">http://technet.microsoft.com/zh-tw/library/ms189858.aspx</a> , 離散狀況在 5% 以下不需要調整, 在 5% ~ 30%之間, 可以利用 ALTER INDEX REORGNIZE 來進行重組, 而大於 30% 時, 可以使用 ALTER INDEX REBUILD (ONLINE = ON) 來進行索引重建.</p>
<p>不過若系統效能允許的狀況下, 其實也是可以直接使用 DROP INDEX, CREATE INDEX 的方式來重建的.</p>
<p>其他相關文章一併整理如下:</p>
<p>Microsoft SQL Server 2000 Index Defragmentation Best Practices<br />
<a href="http://technet.microsoft.com/zh-tw/library/cc966523%28en-us%29.aspx" target="_blank"></a><a href="http://technet.microsoft.com/en-us/library/cc966523.aspx" target="_blank">http://technet.microsoft.com/en-us/library/cc966523.aspx</a></p>
<p>sys.dm_db_index_physical_stats (Transact-SQL)<br />
<a href="http://technet.microsoft.com/zh-tw/library/ms188917.aspx" target="_blank">http://technet.microsoft.com/zh-tw/library/ms188917.aspx</a></p>
<p>ALTER INDEX (Transact-SQL)<br />
<a href="http://msdn.microsoft.com/en-us/library/ms188388.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms188388.aspx</a></p>
<p>Table and Index size in SQL Server<br />
<a href="http://stackoverflow.com/questions/316831/table-and-index-size-in-sql-server" target="_blank">http://stackoverflow.com/questions/316831/table-and-index-size-in-sql-server</a></p>
<p>SQL Server Indexes<br />
<a href="http://odetocode.com/articles/70.aspx" target="_blank">http://odetocode.com/articles/70.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2010/02/25/sql-server-index-fragmen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server全文檢索資料庫的復原</title>
		<link>http://tim.diary.tw/2009/10/22/fulltext-catalog-restor/</link>
		<comments>http://tim.diary.tw/2009/10/22/fulltext-catalog-restor/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 05:49:30 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[FullText]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/?p=95</guid>
		<description><![CDATA[一般資料庫我們備份後, 由於全文檢索技術, 和資料庫引擎不同, 是使用檔案及全文檢索引擎架構的一種方式, 所以在回復到異地後, 資料庫上線了, 但 fulltext catalog 內的資全文檢索資料不能用的問題, 這時候, 只需要再做一次 rebuild 即可, 因為所有的資料庫及相關欄位等設定其實都在, 但路徑上及檔案結構上的問題, 導致會有無法讀取的狀況. 這時候, 於 restore 資料庫後, 做一次 fulltext catalog 的 rebuild, 問題就能順利解決了. 若是原地復原, 則沒有這個問題.]]></description>
			<content:encoded><![CDATA[<p>一般資料庫我們備份後, 由於全文檢索技術, 和資料庫引擎不同, 是使用檔案及全文檢索引擎架構的一種方式, 所以在回復到異地後, 資料庫上線了, 但 fulltext catalog 內的資全文檢索資料不能用的問題, 這時候, 只需要再做一次 rebuild 即可, 因為所有的資料庫及相關欄位等設定其實都在, 但路徑上及檔案結構上的問題, 導致會有無法讀取的狀況. 這時候, 於 restore 資料庫後, 做一次 fulltext catalog 的 rebuild, 問題就能順利解決了.</p>
<p>若是原地復原, 則沒有這個問題.</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2009/10/22/fulltext-catalog-restor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server如何新增article到publication</title>
		<link>http://tim.diary.tw/2009/02/27/adding-articles-to-existing-publications/</link>
		<comments>http://tim.diary.tw/2009/02/27/adding-articles-to-existing-publications/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 04:46:17 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/2009/02/27/sql-server%e5%a6%82%e4%bd%95%e6%96%b0%e5%a2%9earticle%e5%88%b0publication/</guid>
		<description><![CDATA[在使用 Replication 時, 若是使用 Transaction 的方式, 若有要新增 article 到 publication 時, 其實很容易. 基本上就只要在原來的 publication 的 property 裡的 articles, 多加上需要 replication 出來的article, 完成後, 他不會自動進行後續, 接下來的動作就是做 snapshot 就行了, 這裡比較討厭的是若是原來的publication資料多, 而加入的 article資料少, 其實很不划算, 不過做完 snapshot 後, replication 機制會開始將該新發行的article schema傳給 subscriber, 讓 subscriber 將沒有的資料寫入, 這樣就完成了. 其實只會做新的部分, 不過因為還是要一個 schema及起始資料, 所以還是得做一個 snapshot 是比較吃資源的地方, 和 alter table的狀況又不太一樣了. 不過操作上還是很直覺也很方便! 參考SQL Server 2005 help [...]]]></description>
			<content:encoded><![CDATA[<p>在使用 Replication 時, 若是使用 Transaction 的方式, 若有要新增 article 到 publication 時, 其實很容易.</p>
<p>基本上就只要在原來的 publication 的 property 裡的 articles, 多加上需要 replication 出來的article, 完成後, 他不會自動進行後續, 接下來的動作就是做 snapshot 就行了, 這裡比較討厭的是若是原來的publication資料多, 而加入的 article資料少, 其實很不划算, 不過做完 snapshot 後, replication 機制會開始將該新發行的article schema傳給 subscriber, 讓 subscriber 將沒有的資料寫入, 這樣就完成了.</p>
<p>其實只會做新的部分, 不過因為還是要一個 schema及起始資料, 所以還是得做一個 snapshot 是比較吃資源的地方, 和 alter table的狀況又不太一樣了. 不過操作上還是很直覺也很方便!</p>
<p>參考SQL Server 2005 help 資料: <a href="http://msdn.microsoft.com/en-us/library/ms152493(SQL.90).aspx">http://msdn.microsoft.com/en-us/library/ms152493(SQL.90).aspx</a></p>
<p>其中比較重要的是這段:</p>
<blockquote><p>After adding an article to a publication, you must create a new snapshot for the publication (and all partitions if it is a merge publication with parameterized filters). The Distribution Agent or Merge Agent then copies the schema and data for the new article to the Subscriber (it does not reinitialize the entire publication).</p></blockquote>
<p>也就是說, 新增完了之後, 要做一次 snapshopt, 不過 agent 會將新的 article 送到 subscriber, 而不會整個 reinitialize!</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2009/02/27/adding-articles-to-existing-publications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Replication下的異動資料表</title>
		<link>http://tim.diary.tw/2008/09/23/sql-server-replication-table-modify/</link>
		<comments>http://tim.diary.tw/2008/09/23/sql-server-replication-table-modify/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 07:41:17 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[Alter Table]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/2008/09/23/sql-server-replication%e4%b8%8b%e7%9a%84%e7%95%b0%e5%8b%95%e8%b3%87%e6%96%99%e8%a1%a8/</guid>
		<description><![CDATA[若是SQL Server已設定完成Replication的Article時, 進行資料表異動, 其實會透過 DDL 傳送的方式, 將異動的指令也透過複寫的方式送出, 並進行同步. 可以參考相關文章: http://www.replicationanswers.com/AlterSchema2005.asp 不過若是異動的欄位是 Primary Key時, 將會觸發 exception, 發出如下的訊息: Msg 4929, Level 16, State 1, Line 2 Cannot alter the table &#8216;tbltest&#8217; because it is being published for replication. 如此一來便無法使用這種 ddl 傳遞的方式將 Replicated Table 的異動送出. 若是要執行這樣的異動需求, 得先解除掉發行及訂閱此 table, 才能進行調整, 調整完成後才能再重新設定回發行及訂閱, 接下來再做 snap shot 進行遞送出去.]]></description>
			<content:encoded><![CDATA[<p>若是SQL Server已設定完成Replication的Article時, 進行資料表異動, 其實會透過 DDL 傳送的方式, 將異動的指令也透過複寫的方式送出, 並進行同步. 可以參考相關文章: <a href="http://www.replicationanswers.com/AlterSchema2005.asp">http://www.replicationanswers.com/AlterSchema2005.asp</a></p>
<p>不過若是異動的欄位是 Primary Key時, 將會觸發 exception, 發出如下的訊息:</p>
<p>Msg 4929, Level 16, State 1, Line 2<br />
Cannot alter the table &#8216;tbltest&#8217; because it is being published for replication.</p>
<p>如此一來便無法使用這種 ddl 傳遞的方式將 Replicated Table 的異動送出. 若是要執行這樣的異動需求, 得先解除掉發行及訂閱此 table, 才能進行調整, 調整完成後才能再重新設定回發行及訂閱, 接下來再做 snap shot 進行遞送出去.</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2008/09/23/sql-server-replication-table-modify/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Transactional Replication注意參數(max text repl size)</title>
		<link>http://tim.diary.tw/2007/08/24/sql-server-max-text-repl-size/</link>
		<comments>http://tim.diary.tw/2007/08/24/sql-server-max-text-repl-size/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 09:40:02 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/2007/08/24/sql-server-max-text-repl-size/</guid>
		<description><![CDATA[在使用 SQL Server Replication 發行資料時, 有個重要的參數必須要特別注意的地方, 就是 max text repl size, (在 SQL 2005也會影響 varchar(MAX) 這種型態的欄位). 參考這篇 最大文字覆寫大小選項 的設定方法來進行調整(利用 sp_configure). 另外在這篇 交易式複寫考量 也有說明在使用 Replication 時, 要注意覆寫資料的 size 上限, 若是在寫入資料大於該設定的 size 時, 將會發生 error, 內容如下: Length of LOB data (??????) to be replicated exceeds configured maximum 65536 如此一來便會造成寫入失敗而無法成功寫入資料, 這在沒有使用 交易式複寫 時不會發生的問題. 這在使用交易式複寫時要特別注意的地方!]]></description>
			<content:encoded><![CDATA[<p>在使用 SQL Server Replication 發行資料時, 有個重要的參數必須要特別注意的地方, 就是 max text repl size, (在 SQL 2005也會影響 varchar(MAX) 這種型態的欄位).</p>
<p>參考這篇 <a href="http://msdn2.microsoft.com/zh-tw/library/ms186225.aspx" target="_blank">最大文字覆寫大小選項</a> 的設定方法來進行調整(利用 sp_configure).</p>
<p>另外在這篇 <a href="http://msdn2.microsoft.com/zh-tw/library/ms151254.aspx">交易式複寫考量</a> 也有說明在使用 Replication 時, 要注意覆寫資料的 size 上限, 若是在寫入資料大於該設定的 size 時, 將會發生 error, 內容如下:</p>
<p>Length of LOB data (??????) to be replicated exceeds configured maximum 65536</p>
<p>如此一來便會造成寫入失敗而無法成功寫入資料, 這在沒有使用 <strong>交易式複寫</strong> 時不會發生的問題. 這在使用交易式複寫時要特別注意的地方!</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2007/08/24/sql-server-max-text-repl-size/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Replication預設不會複製nonclustered index</title>
		<link>http://tim.diary.tw/2007/08/10/sqlserver-replication-nonclustered-indexes/</link>
		<comments>http://tim.diary.tw/2007/08/10/sqlserver-replication-nonclustered-indexes/#comments</comments>
		<pubDate>Fri, 10 Aug 2007 02:03:41 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://tim.diary.tw/2007/08/10/sql-server-replication%e9%a0%90%e8%a8%ad%e4%b8%8d%e6%9c%83%e8%a4%87%e8%a3%bdnoncluster-index/</guid>
		<description><![CDATA[在使用 SQL Server Replication 機制時, 要特別注意有關複寫參數的部分, 由於預設是不會複製 noclustered indexes的, 所以在使用上要特別注意這點. 這樣的預設有好有壞, 好處是複寫出來到訂閱者資料庫的彈性相當大, 可以依需要再進行 index 設計及應用, 壞處是若管理人員或使用人員沒有發現, 在使用上將會有某種影響訂閱者資料庫的效能! 基本上, 使用複寫資料庫有可能是做分散負載使用, 也有可能是供後端報表查詢, 但無論如何, 得特別注意這個部分, 避免在複寫時造成使用上影響. 下面是在設定複寫表的屬性對話盒, 其中 copy nonclustered indexes 預設是 false 的哦!]]></description>
			<content:encoded><![CDATA[<p>在使用 SQL Server Replication 機制時, 要特別注意有關複寫參數的部分, 由於<strong>預設是不會複製 noclustered indexes</strong>的, 所以在使用上要特別注意這點. 這樣的預設有好有壞, 好處是複寫出來到訂閱者資料庫的彈性相當大, 可以依需要再進行 index 設計及應用, 壞處是若管理人員或使用人員沒有發現, 在使用上將會有某種影響訂閱者資料庫的效能!</p>
<p><span id="more-13"></span> 基本上, 使用複寫資料庫有可能是做分散負載使用, 也有可能是供後端報表查詢, 但無論如何, 得特別注意這個部分, 避免在複寫時造成使用上影響. 下面是在設定複寫表的屬性對話盒, 其中 copy nonclustered indexes 預設是 <strong>false</strong> 的哦!</p>
<p><img src="http://tim.diary.tw/files/2007/08/2.png" alt="articles properties" /></p>
]]></content:encoded>
			<wfw:commentRss>http://tim.diary.tw/2007/08/10/sqlserver-replication-nonclustered-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

