472,143 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

insert into table-Primary key error

I'm trying to do multiple insert statements. The table looks like
this:

CREATE TABLE $table (CNTY_CNTRY_CD char(3),ST char(2),
CNTY_CNTRY_DESCR varchar(50),CNTY_CNTRY_IND char(1),
HOME_CNTRY_IND char(1),
CONSTRAINT cnty_key PRIMARY KEY (CNTY_CNTRY_CD, ST))
I'm using 2 fields for the primary key constraint

My insert statement looks like this:

INSERT INTO $table
(CNTY_CNTRY_CD,ST,CNTY_CNTRY_DESCR)
VALUES(?,?,?)

I've been through the list of values and none have both the same
CNTY_CNTRY_CD and ST and yet, this is the error message I'm getting:

DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver][SQL
Server]Vio
lation of PRIMARY KEY constraint 'cnty_key'. Cannot insert duplicate
key in obje
ct 'event_CNTY_CNTRY_CD'. (SQL-23000)
[Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been
terminated
.. (SQL-01000)(DBD: st_execute/SQLExecute err=-1)

Why is it looking for unique in just the one column instead of
referencing both? What do I need to do to get this to work? Help!
Jul 20 '05 #1
1 9792

"Cliff" <cl***@walkacrossfire.com> wrote in message
news:54**************************@posting.google.c om...
I'm trying to do multiple insert statements. The table looks like
this:

CREATE TABLE $table (CNTY_CNTRY_CD char(3),ST char(2),
CNTY_CNTRY_DESCR varchar(50),CNTY_CNTRY_IND char(1),
HOME_CNTRY_IND char(1),
CONSTRAINT cnty_key PRIMARY KEY (CNTY_CNTRY_CD, ST))
I'm using 2 fields for the primary key constraint

My insert statement looks like this:

INSERT INTO $table
(CNTY_CNTRY_CD,ST,CNTY_CNTRY_DESCR)
VALUES(?,?,?)

I've been through the list of values and none have both the same
CNTY_CNTRY_CD and ST and yet, this is the error message I'm getting:

DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver][SQL
Server]Vio
lation of PRIMARY KEY constraint 'cnty_key'. Cannot insert duplicate
key in obje
ct 'event_CNTY_CNTRY_CD'. (SQL-23000)
[Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been
terminated
. (SQL-01000)(DBD: st_execute/SQLExecute err=-1)

Why is it looking for unique in just the one column instead of
referencing both? What do I need to do to get this to work? Help!


Why do you think it's only looking one column? The error says the object (ie
the table) is called "event_CNTY_CNTRY_CD", so perhaps you're confusing that
with the column "CNTY_CNTRY_CD"? Or perhaps that wasn't the table name you
intended to use?

In any case, the error certainly indicates duplicate data - you could try
modifying your script to print out each INSERT statement for debugging
purposes, to be sure that you're really sending the values you think you
are. Or use Profiler to view the SQL sent to the server.

Simon
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by John A. | last post: by
3 posts views Thread by Cylix | last post: by
1 post views Thread by quartz | last post: by
6 posts views Thread by lenygold via DBMonster.com | last post: by
reply views Thread by =?Utf-8?B?ZndoaWx0b24=?= | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.