Primary Key Voilation

  • Hi....

    I am tring to insert data in sql server 2005 database but i am getting erro as follows

    "Violation of PRIMARY KEY constraint 'PK_Call_Logs'. Cannot insert duplicate key in object 'dbo.Call_Logs'"

    Regards

    Amit

  • Amit

    That's interesting. Do you have a question?

    John

  • hi jhon,

    I am not able to solve this,

    you have any solution then share

    Regards

    Amit

  • Amit

    The row(s) you are inserting contain values that already exist in the table for the column(s) that make up your primary key. Search the internet for PRIMARY KEY if this is new to you - there's plenty of stuff out there.

    John

  • A primary key uniquely identifies a row. Let's say you make a primary key on the alphabet. You can insert a value for 'a', and another for 'b', and one more for 'r'. But if you try to insert a value for 'a' again, you can't because one is already there.

    Your table has a primary key value that already exists which is why you're getting the error.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • There is so much stuff out there for questions like this. Should really start with Books online and try to understand why you are getting the error rather than just posting up for a solution. Understanding Primary Keys should be a fundamental aspect of a DBA or someone who is looking after databases. It wont be the first time youve come across PK's and it definitely wont be the last.

    See here: http://msdn.microsoft.com/en-us/library/ms191236(v=sql.90).aspx

    If you want to delve a little further into it then see the following:

    Find All PKs in a database[/url]

    Enforcing Data Integrity

    My DBA Ramblings - SQL Server | Oracle | MySQL | MongoDB | Access[/url]

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

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