Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to update alternate key

Author  Topic 

KapilNaker
Starting Member

1 Post

Posted - 2007-03-02 : 01:35:49
Hi,

I have one table called InventorInfo and it has composite primarykey
PK(Patentnumber,Inventorname)

Now i want to update inventorname in my program through the query but it doesn't allow me to update

I have fired this query to update the inventorname

Update inventorinfo set inventorname='Liu Chih-Ping' ,
inventorcountry= 'United States' where patentnumber ='US6982081'
and typeofpatent='i'

I got the below error:

Violation of PRIMARY KEY constraint 'PK_inventorinfo'. Cannot insert duplicate key in object 'inventorinfo'.
The statement has been terminated.

Is it possible to update any of the ulternate key in composite primary key??

Any small help will be appreciated

Kapil Naker

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-02 : 01:39:26
1. Updating primary key is bad idea, IMHO
2. You can certainly update it provided you don't introduce duplicates in the process

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-03-02 : 02:05:31
3. and provided it's not referenced by an existing FK row.

most likely your update failed because there is more than one inventor on that particular patent. your statement would try to set the name on both of them to the same value, which would create a dupe.


www.elsasoft.org
Go to Top of Page

Jumoke
Starting Member

2 Posts

Posted - 2007-03-02 : 05:02:00
try to see if there are any duplicate 'inventorname' sharing that name and also check if there is any clustered index on 'inventorname and patentnumber' or remove the primary key on that column because you cant have duplicate values for a primary key.
Go to Top of Page
   

- Advertisement -