August 9, 2010 at 6:40 am
This PK has lots of foreign key constraints so I would like to not have to drop and recreate anything.
Is there a way to alter?
August 9, 2010 at 12:48 pm
Here is what MSDN said you can do:
http://msdn.microsoft.com/en-us/library/aa259130%28v=SQL.80%29.aspx
I'm not sure what you are trying to change about your primary key though (length of a column? which columns make up your pk?).
August 9, 2010 at 1:23 pm
blackbird (8/9/2010)
Here is what MSDN said you can do:http://msdn.microsoft.com/en-us/library/aa259130%28v=SQL.80%29.aspx
That link is for SQL 2000. Is it still relevant for SQL 2008?
I'm not sure what you are trying to change about your primary key though (length of a column? which columns make up your pk?).
From the title I would assume nonclustered index - clustered index
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 9, 2010 at 1:33 pm
Melissa, I suspect that you're going to have to script all the foreign keys, drop the constraint and then recreate the whole lot. I tried altering a pk using CREATE INDEX ... WITH DROP_EXISTING, but it threw an error:
Msg 1907, Level 16, State 1, Line 1
Cannot recreate index '<index name>'. The new index definition does not match the constraint being enforced by the existing index.
This was even if the index was exactly the same column and type as the old.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 9, 2010 at 2:05 pm
Yep, this is why I NEVER use PRIMARY KEY CLUSTERED even IF I intend to cluster on that column. I am willing to burn the index space and index the column twice -- once for the PK and once for the cluster. That way if I need to move the cluster to something else, I don't hit this problem.
August 9, 2010 at 2:08 pm
Just re-read the original question, I agree with Gail it's non-clustered to clustered. OK, if you have PRIMARY KEY NONCLUSTERED you are in my opinion where you want to be. Make a separate clustered index on the same column or columns. You can index the column twice, and you don't really want clustering tied to the referential integrity of the table IMO.
August 15, 2010 at 12:13 pm
Thank you. You answered my questions.
I didn't think so but you never know if someone has found a way around this.
Thanks again.
August 15, 2010 at 9:36 pm
jeff.mason (8/9/2010)
Yep, this is why I NEVER use PRIMARY KEY CLUSTERED even IF I intend to cluster on that column. I am willing to burn the index space and index the column twice -- once for the PK and once for the cluster. That way if I need to move the cluster to something else, I don't hit this problem.
Heh... Ironically, that's exactly why I almost always us PRIMARY KEY CLUSTERED... Once I build it, I want people to be able to change it only after great difficulty. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
August 16, 2010 at 5:29 am
Jeff Moden (8/15/2010)
jeff.mason (8/9/2010)
Yep, this is why I NEVER use PRIMARY KEY CLUSTERED even IF I intend to cluster on that column. I am willing to burn the index space and index the column twice -- once for the PK and once for the cluster. That way if I need to move the cluster to something else, I don't hit this problem.Heh... Ironically, that's exactly why I almost always us PRIMARY KEY CLUSTERED... Once I build it, I want people to be able to change it only after great difficulty. 🙂
Building scripts for foreign keys and constraints is not an issue for experienced DBA or dev. I agree with Jeff here, I wouldn't want to allow moving cluster too easy task for everyone. I prefer people consult with DBA (or responsible senior dev) before making such changes for LIVE db.
August 16, 2010 at 7:22 am
Uh, why would you let anyone but an experienced DBA be in charge of changing an index from clustered to non-clustered? At that point your problem would be that your access is too open. If the system is locked down enough, that is not an issue.
I work in an environment where EVERYTHING on live is subject to change control, even adding an index. The fewer changes required to do something the better. And I can usually more easily get a clustered/nonclustered change approved more easily if I don't have to suspend the data integrity rules, even for a few seconds. The attitude would be "so what if an app made a mistake at just that minute?" Whereas changing the cluster doesn't risk data integrity in the least if I am just dropping an index.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply