Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Violation of Primary Key Constraint

Status
Not open for further replies.

MikeMV

MIS
May 15, 2006
131
US
Hello,

I am working on trying to populate a SQL table with data from a free table. I created a program using Visual FoxPro 9.0 to do this, but
I am having a problem with a violation of primary key contraint.

The SQL table ArCustStkXref has 3 fields

Customer (c,7) PK
CustStockCode (c,30) PK
StockCode (c,30)

Keys: ArCustStkXrefKey

Indexes:
ArCustStkXrefIdxStk (Unique, Non-Clustered)
ArCustStkXrefKey (Clustered)

The purpose of this table is to provide a cross-reference between our part numbers and that of our customers.
During normal input from the application that handles this data the customer field can be dupplicated across many records, I can manually modify records
and input dupplicate customer numbers, but I am not being able to do this with FoxPro. I get the following error:

Violation of PRIMARY KEY contraint 'ArCustStkXrefKey'. Cannot insert dupplicate key in object 'dbo.ArCustStkXref'

The free table has 2 fields ssku (c,10) and stockcode (c,20)

I will greatly appreciate any feedback you can provide.

Mike.

* Program.: LpSKU.PRG V1.0
*
CLOSE ALL
CLEAR
SET DEFAULT TO C:\Projects\lpsku
SET NULL OFF
*
DELETE FILE C:\Projects\lpsku\vlpsku*.*
*
CREATE DATABASE vlpsku
CREATE SQL VIEW vlpsku;
REMOTE CONNECTION LocalSysPro;
AS select Customer, CustStockCode, StockCode FROM ArCustStkXref;
ORDER BY CustStockCode
*
DBSETPROP ("vlpsku", "View", "SendUpdates", .T.)
DBSETPROP("vlpsku" , "VIEW","WhereType",3)
*
DBSETPROP("vlpsku.Customer", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.Customer", "Field", "UpdateName", [ArCustStkXref.Customer])
DBSETPROP("vlpsku.Customer", "Field", "KeyField", .T.)
*
DBSETPROP("vlpsku.CustStockCode", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.CustStockCode", "Field", "UpdateName", [ArCustStkXref.CustStockCode])
DBSETPROP("vlpsku.CustStockCode", "Field", "KeyField", .T.)
*
DBSETPROP("vlpsku.StockCode", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.StockCode", "Field", "UpdateName", [ArCustStkXref.StockCode])
DBSETPROP("vlpsku.StockCode", "Field", "KeyField", .F.)
*
SELECT 1
USE vlpsku
*
SELECT 2
USE lpsku INDEX stock
*
GO TOP
SCATTER MEMVAR
*
DO WHILE .NOT. EOF()
*
SELECT 1
*
INSERT INTO vlpsku (Customer, CustStockCode, StockCode);
VALUES("39050",m.ssku,m.StockCode)
*
IF NOT TABLEUPDATE(1, .t., [vlpsku])
AERROR(laError)
MessageBox([Can not Update vlpsku ]+laError[1,2])
EXIT
ENDIF
*
SELECT 2
*
IF .NOT. EOF()
SKIP
SCATTER MEMVAR
LOOP
ENDIF
*
ENDDO
*
CLOSE DATABASES ALL
*
RETURN
 
Hi

The very definition of Primary Key is that it has to be unique. So you cannot duplicate the value in a primary key.

Make the field as regularindex type.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top