SQL 2005 Primary Key Error

Posted on 2007-10-09
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,

Question by:stretch73
    LVL 16

    Expert Comment

    this link will fix you up
    LVL 27

    Expert Comment

    The pk_t_month index is in the dbo.t_month table.
    LVL 5

    Accepted Solution

    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.
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    > 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 )

    Author Comment


    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,

    LVL 27

    Expert Comment

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

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Viewers will learn how the fundamental information of how to create a table.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now