| re: insert into table-Primary key error
"Cliff" <cliff@walkacrossfire.com> wrote in message
news:54dc6fb1.0402061003.56613e93@posting.google.c om...[color=blue]
> 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![/color]
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 |