Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating a table with multiple field PK
Message
De
26/08/2002 13:58:02
 
 
À
26/08/2002 12:45:33
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00693482
Message ID:
00693747
Vues:
23
Hi Mike,

Outstanding!

Thank You Very Much
Jim

>TSQL has as an extension to the DELETE statement that will make this much easier. DELETE FROM:
>
>DELETE FROM conphone
>FROM
> conphone
> INNER JOIN cisconphone ON conphone.conuniq = cisconphone.conuniq AND conphone.phnnumber cisconphone.phnnumber
>
>Your insert is similar:
>
>INSERT INTO conphone (columnlist)
>SELECT (columnlist)
>FROM
> cisconphone
> LEFT OUTER JOIN conphone ON conphone.conuniq = cisconphone.conuniq AND conphone.phnnumber cisconphone.phnnumber
>WHERE
> conphone.conuniq IS NULL
>
>-Mike
>
>
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform