Server: Msg 2627....Violation of PRIMARY KEY ....

  • For some tables (but not all) SQL Query analyzer output the follwing message:

    (This happen during update)

    Server: Msg 2627, Level 14, State 1, Line 4

    Violation of PRIMARY KEY constraint 'PK_BP_STEP_LINKS'. Cannot insert duplicate key in object 'tablename'.

    The statement has been terminated.

    I have added ALTER TABLE tablename NOCHECK CONSTRAINT ALL

    and

    ALTER TABLE krna_mcocore43Import.dbo.BP_STEP_LINKS CHECK CONSTRAINT ALL

    at the beginning and at the end of UPDATE statement

    How can I solve this problem?

  • Hi,

    The only constraints you can disable are the FOREIGN KEY constraint, and the CHECK constraint. PRIMARY KEY, UNIQUE, and DEFAULT constraints are always active.

    If you want to insert duplicates in this column, this means that it shouldn't be a primary key and you should drop the pk constraint. If you are sure that this should be a primary key, then your update statement is not correct. Check it and put the necessary conditions to avoid trying to update Primary Key to a value that already exists.


    Niki

  • Could you please post your DDL and data.

    check this web page

    http://www.aspfaq.com/etiquette.asp?id=5006

    HTH

    Mike 

  • I wouldn't think aboput how to disable an integrity constraint. This is just doing its job (and it does it quite well in your case ).

    You will have to verify the data you want to insert or if you absolutly need THOSE data to be inserted into your database you have to modify your primary key to fit to your needs



    Bye
    Gabor

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply