title: Change a Primary Key from Nonclustered to Clustered
body: <p>Suppose I have an SQL Server 2005 table, TableX, with 2 indexes on it:<br/></p>
  
  <p>PK_TableX = PRIMARY KEY NONCLUSTERED on FieldA<br/> 
  IX_TableX_FieldB = CLUSTERED on FieldB</p>
  
  <p>I want to switch the PK to be CLUSTERED, and the other index to be NONCLUSTERED.</p>
  
  <p>I have to assume that the database will be in use at the moment I try to change the indexes round - so my primary concern that I want to avoid, is that at some point in the process the PK constraint will not exist on the table. I want to be protected against any risk of duplicate keys being inserted.</p>
  
  <p>i.e. I can't just drop the primary key and recreate it.</p>
  
  <p>This process needs to be done via an SQL script, not via SSMS.</p>
  
  <p>I have an approach which I think will work (I'll post it as a potential answer), but would like to open it up in case I'm missing something or there is another/better way. Plus, it may prove useful for others in the future</p>