Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating a table with multiple field PK
Message
From
26/08/2002 11:23:51
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00693482
Message ID:
00693680
Views:
23
Hi Mike,

I am having trouble inserting data from the field into the home server. I get messages like

Server: Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'conphonePK'. Cannot insert duplicate key in object 'conphone'.
The statement has been terminated.

The costrain conphonePK is

conphonePK clustered, unique, primary key located on PRIMARY conuniq, phnnumber

So I am first trying to delete the rows in the target table that are in the source table to eliminate PK conflicts and put fresh data into the target table.

I have more than one row in my source table that have the same conuniq and phnnumber PK values. This is supposed to be resolved soon.

So for now what would the best way be to transfer rows from the source table
that would not be a PK conflict in my target table

Thanks
Jim

>>Will this accomplish my goal?
>
>Don't know. What is your goal?
>
>>DELETE FROM conphone WHERE conuniq in (SELECT conuniq FROM cisconphone) and phnnumber in (SELECT phnnumber FROM cisconphone).
>
>WATCH THIS!!!! This will delete all the rows in conphone where conuniq is stored in any row in cisconphone AND phnnumber is stored in any row in cisconphone AND THERE IS NO REQUIRED THAT IT IS THE SAME ROW.
>
>Is this what you want?
>
>-Mike
>
>
>>
>>Will this accomplish my goal?
>>
>>INSERT INTO conphone
>>SELECT * FROM cisconphone
>>WHERE conuniq not in (
>> SELECT conuniq
>> FROM cisconphone
>> GROUP BY conuniq
>> HAVING (COUNT(conuniq) > 1)
>> )
>>AND
>>
>>phnnumber not in
>> (
>> SELECT phnnumber
>> FROM cisconphone
>> GROUP BY phnnumber
>> HAVING (COUNT(phnnumber) > 1)
>> )
>>
>>
>>Thanks
>>Jim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform