SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating a Primary Key over an existing Unique, Clustered Index


Creating a Primary Key over an existing Unique, Clustered Index

Author
Message
Lawrence M. Meklemburg
Lawrence M. Meklemburg
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1033 Visits: 156
I have 7 tables all associated with what a Primary Key on a table called Person. The column for the Primary Key is called Person_ID.

The problem is when I restored the database from a SQL 2000 backup to SQL 2005 Enterprise Edition DBCC CheckDB reported errors in the database associated the Person table. I noticed that in error someone had made the Person_ID a non-clustered index (PK_PersonID), so I scripted a query to drop the index and create a new unique, clustered index over Person_ID. That fixed my DBCC CHECKDB error, but left me without a Primary Key on the Person table. How do I create the primary key on Person_ID for the Person table?

Thanks,
Larry
Lawrence M. Meklemburg
Lawrence M. Meklemburg
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1033 Visits: 156
Dropped all the Foreign Keys that were associated with the Person primary key.
Dropped the Unique Clustered Index over Person.
Created the Primary Key as Clustered over Person_ID
Added the Foreign key constraints back.

Just wanted you to know.

Thanks,
Larry
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search