473,691 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_DESC R varchar(50),CNT Y_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_D ESCR)
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_CNT RY_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 9885

"Cliff" <cl***@walkacro ssfire.com> wrote in message
news:54******** *************** ***@posting.goo gle.com...
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_DESC R varchar(50),CNT Y_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_D ESCR)
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_CNT RY_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_CNT RY_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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6590
by: Gaz | last post by:
Hi, I need to have a table nested within another table. The tables are alongside each other visually speaking, and the nested table (on the right) can vary in size. My problem is that when the nested table has more rows than the first table, the first table (on the left) pads out its rows so that the table matches the height of the nested table. I don't want this it happen.. I just want the nested table to be longer than the first...
7
10440
by: John A. | last post by:
Hello all! I've got a big bunch of pages using tables for layout. Eventually I'll get them set up with more modernized code, but in the meantime I'd like to slip in a little quick holiday decoration. I'd like to insert a table cell with a fixed width (as much as such things can be fixed) and a repeating garland background so as to show up along the left side of the table, repeating down its length. Our site has a couple thousand...
2
2978
by: David Bradbury | last post by:
I currently have an iframe on a webpage into which users can insert content. They can further customise the text as I've included buttons such as Bold, Italic, Bullet point etc. This is done along the lines of <td><div class="cbtn" onClick="cmdExec('bold',idContent)" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);"> <img hspace="1" vspace=1 align=absmiddle...
3
1848
by: Cylix | last post by:
After search in the web, I found that, insertRow, insertCell, is a bug of Mac IE, Moreover, <table>, <tbody> seems doesn't support innerHTML, What is the solution to show dynamic table in Mac IE? Thank you
1
7762
by: MayOng | last post by:
Is it possible to insert a table or draw a table on rich text box like what ms word do? please give me some guideline, 10q :)
1
2490
by: quartz | last post by:
Hello, I have a txt file with names, years, days. How can I insert table using shell scripting??? Thenks a lot,
10
2988
by: lxfc97 | last post by:
Hi, I'm trying to use the DOM to insert a TABLE into a DIV tag. Can anyone tell me what I'm doing wrong here? The code looks straightforward, but it is not working. Thanks, Dave
6
3714
by: lenygold via DBMonster.com | last post by:
Hi everybody: What is the best way to I have 10 tables with similar INSERT requiremnts. INSERT INTO ACSB.VAATAFAE WITH AA(AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP) AS ( SELECT AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP FROM VAATAFAA WHERE AB_TP_ACNT_STAT_CD <0),
0
1025
by: =?Utf-8?B?ZndoaWx0b24=?= | last post by:
Hi, I have reference MSHTML.DLL. I can edit most of the WYSIWYG text when in DesignMode (EditMode). That works fine However, after reading an article on MSDN about the DHTML and TriEdit not being safe for Vista... How can I insert a table into the WYSIWYG mshtml control? :)
1
1393
by: visweswaran2830 | last post by:
Hi, I am having datagrid in that I have one column that should have table. Now I want to know that how can I include table in datagrid. My table values may differ from each rows in datagrid. So that also should be accomplished.
0
8599
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9079
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8791
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4322
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4550
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.