﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Luke Campbell  / Change Tracking and Database Refactoring / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 06:49:09 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Nice article - I like this approach and will definitely experiment with it the next time I have a change on a large table.I think you can improve the conciseness and robustness of your synch proc by leveraging the PARSENAME(...) function for the object name manipulation near the top.Good job.TroyK</description><pubDate>Thu, 11 Aug 2011 10:13:55 GMT</pubDate><dc:creator>cs_troyk</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Hi Rick.  That's still a viable option but we wanted to avoid locking the table and minimize downtime during these changes.</description><pubDate>Thu, 11 Aug 2011 09:41:05 GMT</pubDate><dc:creator>Luke C</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Very cool ssandler!  I didn't even think of using merge.</description><pubDate>Thu, 11 Aug 2011 09:39:31 GMT</pubDate><dc:creator>Luke C</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Great suggestion Thomas!  I may do that in the near future.</description><pubDate>Thu, 11 Aug 2011 09:38:41 GMT</pubDate><dc:creator>Luke C</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Whatever happened to alter table alter column?</description><pubDate>Thu, 11 Aug 2011 09:30:12 GMT</pubDate><dc:creator>rick.lane</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Great Article! I used almost the exact same method about 3 months ago to change the clustered index on our largest table (which gets hit by hundreds of transactions per second) and it went off without a hitch. Change tracking is a great addition to SQL, I also use it to incrementally apply changes to hundreds of tables from several SQL servers to one Netezza data warehouse.  The change I would make is that instead of doing inserts, updates, and deletes separately, you can do them all at once using the MERGE statement. This will sync up the data roughly twice as fast. For the below code sample, I generate the various &amp;lt;columnslists&amp;gt; using several UDFs that took the table name as a parameter and used syscolumns, sysobjects, INFORMATION_SCHEMA.TABLE_CONSTRAINTS, INFORMATION_SCHEMA.KEY_COLUMN_USAGE to get the intended field lists (with aliases hard coded in).[code="sql"]MERGE NewTable AS p   USING (SELECT &amp;lt;ColumnList&amp;gt; FROM CHANGETABLE(CHANGES OldTable, @last_sync_version) c	LEFT OUTER JOIN OldTable o ON &amp;lt;o.PkList = c.PkList&amp;gt;	WHERE c.SYS_CHANGE_VERSION &amp;lt; @CurrentVersion ) AS CT   ON &amp;lt;CT.PkList = p.PkList&amp;gt;  WHEN MATCHED AND CT.SYS_CHANGE_OPERATION = 'D'    	THEN DELETE    WHEN MATCHED AND CT.SYS_CHANGE_OPERATION IN ('I', 'U')    THEN 	UPDATE SET &amp;lt;UpdateFieldList&amp;gt;WHEN NOT MATCHED BY TARGET AND CT.SYS_CHANGE_OPERATION IN ('I', 'U') THEN    	INSERT (&amp;lt;InsertFieldList) VALUES (&amp;lt;ValuesFieldList&amp;gt;)   OUTPUT $action;[/code]In practice, I actually put the results of the SELECT into a temp table first since it seemed to help with blocking, and put the results of the output clause into another table for logging purposes.</description><pubDate>Thu, 11 Aug 2011 08:02:57 GMT</pubDate><dc:creator>ssandler</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Get formatting and explanation in the article. For a followup article, maybe you could go into more detail about where the changed data is located internally in SQL Server:FROM [person].[person] source INNER JOIN CHANGETABLE(CHANGES [person].[person], 0) ctON source.BusinessEntityID = ct.BusinessEntityID WHERE ct.SYS_CHANGE_OPERATION = 'I' AND ct.SYS_CHANGE_VERSION &amp;lt;=4Explain the CHANGETABLE(CHANGES [person].[person], 0) forus.Thanks,Thomas</description><pubDate>Thu, 11 Aug 2011 07:50:03 GMT</pubDate><dc:creator>Thomas LeBlanc</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Hi Dan.  In this example we are going from nvarchar data types to varchar.  The Person.Person_nonunicode table contains these changes.</description><pubDate>Thu, 11 Aug 2011 06:44:51 GMT</pubDate><dc:creator>Luke C</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Hi Luke,Great article! Thanks very much for sharing.I was a little curious though... given that the CRUD statements are done automatically by your stored proc, where do you do the actual data refactoring (i.e. converting from non-unicode to unicode)? Did I miss something?Cheers,Dan</description><pubDate>Thu, 11 Aug 2011 05:53:38 GMT</pubDate><dc:creator>danere</dc:creator></item><item><title>RE: Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Edit.  Step 3 at the bottom of the article states "Add all constraints to the new table and all referencing Foreign Keys. These were added with the "no check" option and then enabled. This avoided a lengthy recheck of all keys.".  Although this method is fast, the foreign key will be in an "untrusted" state.  More on that [url=http://www.simple-talk.com/sql/database-administration/foreign-keys-and-their-states/]here[/url].  In the future we'll be creating the FK with the check option instead of no check.</description><pubDate>Thu, 11 Aug 2011 04:37:18 GMT</pubDate><dc:creator>Luke C</dc:creator></item><item><title>Change Tracking and Database Refactoring</title><link>http://www.sqlservercentral.com/Forums/Topic1158200-1239-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/Change+Tracking/74397/"&gt;Change Tracking and Database Refactoring&lt;/A&gt;[/B]</description><pubDate>Thu, 11 Aug 2011 00:10:55 GMT</pubDate><dc:creator>Luke C</dc:creator></item></channel></rss>