Voilation of primarykeyconstarint,cannot insert duplicate value.

  • Dear friends,

    Good afternoon,

    any one can help me to find out solution for the following issue.

    issue is:-

    Table consist of 12 columns out of this 6 columns consists of composte primary key.

    the 6 colums of the table like this

    AL_ALIDAL_ALTYP AL_PROJ AL_AGID AL_AGTY PAL_CITID

    121131

    121231

    121132

    121235

    Till here its working fine,after inserting this row it dispalying the error mesaage like

    Error source:-.Netsqlclientdataprovider

    errormessage:-Voilation of primarykey constarint,cannot insert duplicate value.

    the new row is

    221131

    Thanks & Regards

    rclgoriparthi

  • Maybe I'm wrong, but it looks like the first row already in your table.

    Am I missing something?

    -- Gianluca Sartori

  • First make sure that your table indeed has the columns you want to be in the pk as the pk columns:

    SELECT i.name

    , ic.index_column_id

    , c.name

    FROM sys.indexes i

    JOIN sys.index_columns ic ON i.[object_id] = ic.[object_id]

    AND i.index_id = ic.index_id

    JOIN sys.columns c ON ic.[object_id] = c.[object_id]

    AND ic.column_id = c.column_id

    WHERE i.object_id = OBJECT_ID('mytable')

    AND i.is_primary_key = 1

    ORDER BY key_ordinal

    Then, have a look at your insert statement. Are you specifying the columns that should be inserted. Is the order of these the same as the order of the data values? Try selecting from the table the columns in the same order as in your insert statement column listing.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • difference between the first row and last row is except first column,

    both the rows are same except first column

    Rgds,

    rclgoriparthi

  • You may need to post your code because that should work fine. As one of the previous posts said, you may have your PK improperly defined.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

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

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