Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL update question
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01547388
Message ID:
01547393
Vues:
28
>Hi,
>
>I am struggling with creating the following SQL UPDATE:
>
>I have table PART_LIST with the PK field PART_PK (int) and unique field PART_NO (char).
>Another table is PART_AUDIT with FK PART_PK and FK PART_NO.
>I want to update PART_AUDIT column PART_PK with NULL for those records that do not have an entry of PART_NO in the PART_LIST. That is, before I can set the FK constraint on PART_PK I need to eliminate all the invalid keys.
>
>I would appreciate any suggestions or some sample code.
>
>This is my attempt at the code
>
>
>update PART_AUDIT set PART_PK = null where not exists (select PART_PK from PART_LIST where
> PART_LIST.PART_NO = PART_AUDIT.PART_NO)
>
Your code seems to be fine. Although I would name the field Part_FK in the Part_Audit as it's not a PK field there.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform