<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>SQL</title><link>http://blog.blueshop.com.tw/josephlee/category/280.aspx</link><description>SQL</description><managingEditor>獨孤雲</managingEditor><dc:language>zh-TW</dc:language><generator>.Text Version 0.95.2004.101</generator><item><dc:creator>獨孤雲</dc:creator><title>Configuration commands</title><link>http://blog.blueshop.com.tw/josephlee/archive/2006/12/31/49011.aspx</link><pubDate>Sun, 31 Dec 2006 13:29:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2006/12/31/49011.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/49011.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2006/12/31/49011.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/49011.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/49011.aspx</trackback:ping><description>&lt;P&gt;sp_configuration (server configuration)&lt;/P&gt;
&lt;P&gt;sp_dboption (database configuration)&lt;/P&gt;
&lt;P&gt;set xxx on / off (connection configuration)&lt;/P&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/49011.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>列出該 FileGroup 有關的 Table &amp; Index</title><link>http://blog.blueshop.com.tw/josephlee/archive/2006/04/26/22999.aspx</link><pubDate>Wed, 26 Apr 2006 15:26:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2006/04/26/22999.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/22999.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2006/04/26/22999.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/22999.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/22999.aspx</trackback:ping><description>select TableNAME = o.name, ObjectName = i.name, i.indid, s.groupname&lt;BR&gt;from sysfilegroups s, sysindexes i, sysobjects o&lt;BR&gt;where i.id = o.id and o.type in ('S ','U ') and i.groupid = s.groupid and s.groupname = 'FG_ABC' &lt;BR&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/22999.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>Split User Defined Function</title><link>http://blog.blueshop.com.tw/josephlee/archive/2006/04/06/20786.aspx</link><pubDate>Thu, 06 Apr 2006 10:42:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2006/04/06/20786.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/20786.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2006/04/06/20786.aspx#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/20786.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/20786.aspx</trackback:ping><description>&lt;P&gt;alter FUNCTION fn_Split&lt;BR&gt;(&lt;BR&gt;&amp;nbsp;@RowData varchar(8000),&lt;BR&gt;&amp;nbsp;@SplitOn char(1)&lt;BR&gt;)&amp;nbsp; &lt;BR&gt;RETURNS @RtnValue table &lt;BR&gt;(&lt;BR&gt;&amp;nbsp;Data nvarchar(100)&lt;BR&gt;) &lt;BR&gt;AS&amp;nbsp; &lt;BR&gt;BEGIN &lt;BR&gt;&amp;nbsp;Declare @Cnt int&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Set @Cnt = 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;While (Charindex(@SplitOn,@RowData)&amp;gt;0)&lt;BR&gt;&amp;nbsp;Begin&lt;BR&gt;&amp;nbsp;&amp;nbsp;Insert Into @RtnValue Select ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))&lt;BR&gt;&amp;nbsp;&amp;nbsp;Set @Cnt = @Cnt + 1&lt;BR&gt;&amp;nbsp;End&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;Insert Into @RtnValue Select ltrim(rtrim(@RowData))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Return&lt;BR&gt;END&lt;BR&gt;&lt;/P&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/20786.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>MS DTC</title><link>http://blog.blueshop.com.tw/josephlee/archive/2005/05/22/4122.aspx</link><pubDate>Sun, 22 May 2005 15:45:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2005/05/22/4122.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/4122.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2005/05/22/4122.aspx#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/4122.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/4122.aspx</trackback:ping><description>&lt;P&gt;MS DTC：交易管理員，允許用戶端應用程式將許多不同來源的資料包含於一筆交易中。MS DTC 負責協調交易中編列的所有伺服器之間分散式交易的認可。&lt;/P&gt;
&lt;P&gt;Sample ：&lt;/P&gt;
&lt;P&gt;SET XACT_ABORT ON&lt;BR&gt;BEGIN DISTRIBUTED TRAN&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Update IA64.Northwind.dbo.Customers SET CompanyName='bbbb' WHERE CustomerID='alfki'&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Update Customers SET CompanyName='aaaaaaaaaaa' WHERE CustomerID='alfki'&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; INSERT Customers(CustomerID,CompanyName) VALUES('alfki','alfki')&lt;BR&gt;COMMIT TRAN&lt;/P&gt;
&lt;P&gt;在同一個 Transaction 中，有關連到多個 Source 的操作，如果發生 Rollback，則多個 Source 的操作可以一起 Rollback。&lt;/P&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/4122.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>DTS in SQL Server 64 Bit</title><link>http://blog.blueshop.com.tw/josephlee/archive/2005/05/22/4117.aspx</link><pubDate>Sun, 22 May 2005 14:33:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2005/05/22/4117.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/4117.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2005/05/22/4117.aspx#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/4117.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/4117.aspx</trackback:ping><description>&lt;P&gt;SQL Server 64 Bit 沒有 DTS 程式，所以 DTS Package 可以存在 SQL Server 64 Bit 裡面，但是在執行 DTS Package 時，實際上是在 32 Bit 的管理 Console 上面執行的。&lt;/P&gt;
&lt;P&gt;* SQL Server 64 Bit 本機沒有管理介面，必須由&amp;nbsp; 32 Bit 機器利用 Enterprise Manager 管理 SQL Server 64 Bit。&lt;/P&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/4117.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>當災害發生時，如何 restore database？</title><link>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4108.aspx</link><pubDate>Sat, 21 May 2005 15:15:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4108.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/4108.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4108.aspx#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/4108.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/4108.aspx</trackback:ping><description>&lt;P&gt;一、知道要 restore 何時之前的 Database：&lt;/P&gt;
&lt;P&gt;1. Backup Database&lt;/P&gt;
&lt;P&gt;backup database Northwind to disk='northwind.bak'&lt;/P&gt;
&lt;P&gt;2. 不小心下 Update 忘記下 where&lt;/P&gt;
&lt;P&gt;update northwind.dbo.[order details] set Quantity=14&lt;/P&gt;
&lt;P&gt;3. 把 Transaction Log Backup 下來&lt;/P&gt;
&lt;P&gt;backup log Northwind to disk='Nwind.log'&lt;/P&gt;
&lt;P&gt;4. Restore Database "with norecovery"&lt;/P&gt;
&lt;P&gt;restore database northwind from disk='Northwind.bak' with norecovery&lt;/P&gt;
&lt;P&gt;5. Restore Transaction Log 並設定 recovery 的時間點，即可救回 update 之前的資料&lt;/P&gt;
&lt;P&gt;restore log northwind from disk='Nwind.log' with stopat='2005/5/21 14:39:00', recovery&lt;/P&gt;
&lt;P&gt;二、不知道要 restore 何時的 Database ：&lt;/P&gt;
&lt;P&gt;下面兩個 SQL 重複執行，直到找到正確的時間。&lt;/P&gt;
&lt;P&gt;restore database northwind from disk='Northwind.bak' with norecovery&lt;/P&gt;
&lt;P&gt;restore log northwind from disk='nwind.log' with stopat='2005/5/21 14:39:00', recovery&lt;/P&gt;
&lt;P&gt;三、restore 某個 Transaction&lt;/P&gt;
&lt;P&gt;1. Transaction 必須帶 Mark ：&lt;/P&gt;
&lt;P&gt;begin tran ErrorTran with mark&lt;/P&gt;
&lt;P&gt;update northwind.dbo.[order details] set Quantity=14&lt;/P&gt;
&lt;P&gt;commit tran&lt;/P&gt;
&lt;P&gt;2. restore 某個 Mark 的 Transaction ：&amp;nbsp;&lt;/P&gt;
&lt;P&gt;restore log northwind from disk='nwind.log' with stopbeforemark='ErrorTran', recovery&lt;/P&gt;
&lt;P&gt;四、Restore 部分的資料：&lt;/P&gt;
&lt;P&gt;1. 建立一個新的 database ：&lt;/P&gt;
&lt;P&gt;restore database nwindbak from disk='c:\northwind.bak' with &lt;BR&gt;move 'northwind' to 'C:\Program Files\Microsoft SQL Server\MSSQL\data\nwnd_bak.mdf', &lt;BR&gt;move 'northwind_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL\data\nwind_bak.ldf'&lt;/P&gt;
&lt;P&gt;2. Update 需要修改的資料：&lt;/P&gt;
&lt;P&gt;update northwind.dbo.[order details] set Quantity=b.Quantity &lt;BR&gt;FROM northwind.dbo.[order details] o JOIN nwindbak.dbo.[order details] b ON o.OrderID=b.OrderID&lt;BR&gt;WHERE o.OrderID&amp;gt;10248&lt;/P&gt;
&lt;P&gt;* 注意：Database Mode 必須是 "Full Mode" 才可以救回。&lt;/P&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/4108.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>修改被訂閱 Table 的注意事項</title><link>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4107.aspx</link><pubDate>Sat, 21 May 2005 11:06:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4107.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/4107.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4107.aspx#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/4107.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/4107.aspx</trackback:ping><description>Transactional 和 Merge Replication 各自利用自動建立的 Stored Procedure 和 Trigger 執行 Replication，所以在修改被訂閱的 Table 時必須特別注意。目前 SQL Server 2000 在新增和刪除被訂閱的 Table 欄位時，系統會自動修改這些 Stored Procedure 和 Trigger；可是如果修改被訂閱 Table 欄位的 Type，系統不會自動修改這些 Stored Procedure 和 Trigger，因此需要手動進行修改，否則會發生 Replication Error。SQL Server 2005 則已經解決這些問題。&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/4107.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>Merge Replication</title><link>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4103.aspx</link><pubDate>Sat, 21 May 2005 10:30:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4103.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/4103.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4103.aspx#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/4103.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/4103.aspx</trackback:ping><description>Merge Replication 會在 Publisher 和 Subscriber 兩邊的 Table 裡面自動建立一個欄位 (uniqueidentifier)，所以會造成 Schema 的改變。&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/4103.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>distribution_admin</title><link>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4102.aspx</link><pubDate>Sat, 21 May 2005 10:27:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4102.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/4102.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2005/05/21/4102.aspx#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/4102.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/4102.aspx</trackback:ping><description>&lt;P&gt;建立 Replication 後，Publisher 和 Subscriber&amp;nbsp;的 Sql Server 會自動建立 distribution_admin 帳號，透過這個帳號進行 Replication。&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/4102.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>獨孤雲</dc:creator><title>SQL Server 備份技術</title><link>http://blog.blueshop.com.tw/josephlee/archive/2005/05/15/3940.aspx</link><pubDate>Sun, 15 May 2005 14:01:00 GMT</pubDate><guid>http://blog.blueshop.com.tw/josephlee/archive/2005/05/15/3940.aspx</guid><wfw:comment>http://blog.blueshop.com.tw/josephlee/comments/3940.aspx</wfw:comment><comments>http://blog.blueshop.com.tw/josephlee/archive/2005/05/15/3940.aspx#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://blog.blueshop.com.tw/josephlee/comments/commentRss/3940.aspx</wfw:commentRss><trackback:ping>http://blog.blueshop.com.tw/josephlee/services/trackbacks/3940.aspx</trackback:ping><description>&lt;P&gt;* 全部備份 :&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1. backup / Restore&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2. Log Shipping&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3. Detach / Attach&lt;/P&gt;
&lt;P&gt;* 局部備份 :&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1. BCP / Bulk Insert / Select Into&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2. Replication&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3. DTS&lt;/P&gt;&lt;img src ="http://blog.blueshop.com.tw/josephlee/aggbug/3940.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>