“Violation of PRIMARY KEY constraint” when Inserting

I'm getting the above error when running an insert into on one of our tables.

The AdmFormData has 3 primary keys, FormType, KeyField and FieldName.

Would anyone have any ideas what I'm doing wrong?

    set rowcount 0
    go



    INSERT INTO  AdmFormData
    (
    [FormType]
      ,[KeyField]
      ,[FieldName]
      ,[AlphaValue]
      ,[NumericValue]
      ,[DateValue]
    )
    SELECT
     'CUS' AS [FormType]
      ,Customer as [KeyField]
      ,'SAL001' AS [FieldName]
      ,[Customer Territory] AS [AlphaValue]
      ,NULL AS [NumericValue]
      ,NULL AS [DateValue]
    FROM
    dgl_territory a
    LEFT OUTER JOIN AdmFormData f
    on f.FormType = 'CUS' and f.FieldName = 'SAL001' and f.KeyField = a.Customer
    WHERE f.FormType IS NULL

Answers


The error is telling you that you already have a record in the AdmFormData table that has the primary key you are trying to INSERT

If your primary key on the table contains FormType, KeyField and FieldName then you already have a record with the values:

'CUS' AS [FormType]
,Customer as [KeyField]
,'SAL001' AS [FieldName]

You cannot have more that one record with the same primary key, they are unique.


Need Your Help

Is there a way to specify a mandatory array key/index via PHPDoc?

php comments phpdoc

If a function requires an incoming array to have a specific key/index, is there an eloquent way to express it via comments, specifically PHPDoc?

Passing a list of objects to JavaScript from Controller method using Ajax

javascript ajax json asp.net-mvc-4

I have a controller method GetNearbyUsers which returns a list of users as a JsonResult. I am trying to call the method using the following ajax function:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.