[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL 2005 Primary Key Error

Posted on 2007-10-09
6
Medium Priority
?
155 Views
Last Modified: 2010-05-18
I have a table, t_Month, that I needed to refresh with data from our development box.  The primary key on this table is Month_ID so I removed the key, re-imported the data, and then tried to add the key back on.  When I try to save the table I get the following error:

't_Month' table
- Unable to create index 'PK_t_Month'.  
CREATE UNIQUE INDEX terminated because a duplicate key was found for object name 'dbo.t_Month' and index name 'PK_t_Month'.  The duplicate key value is (1).
Could not create constraint. See previous errors.
The statement has been terminated.

I can't find another index called PK_t_Month anywhere.  Not really sure what to do here, even went so far as to bounce the server on the chance that the key was stuck in memory somewhere.  

Thanks in advance,

N
0
Comment
Question by:stretch73
6 Comments
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20041172
this link will fix you up

http://support.microsoft.com/kb/139444
0
 
LVL 27

Expert Comment

by:ptjcb
ID: 20041176
The pk_t_month index is in the dbo.t_month table.
0
 
LVL 5

Accepted Solution

by:
Crag earned 2000 total points
ID: 20041177
Not sure how you created the values but you have rows in the table that have the same value for Month_ID and this is not allowed by the index - unique

You can either create a non unique index or find the rows with duplicate Month_ID and change/remove them.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20041178
> can't find another index called PK_t_Month anywhere
It is not the problem with the existance of another index, it is the problem with the data, your column contain some duplicate values, that is why it is failing, you can create it by skinpping the existing data (there is an option )
0
 

Author Comment

by:stretch73
ID: 20041216
Crag,

Good call, for whatever reason it never occurred to me to check the actual data.  I must not have it "delete existing values" on the import.

Thanks for the suggestion,

N
0
 
LVL 27

Expert Comment

by:ptjcb
ID: 20041226
As aneeshattingal and crag point out, look at your data. You have duplicate values in the primary key. That is not allowed.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question