Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Back to basics on foreign key constraint
Message
 
 
À
08/09/2013 08:33:02
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01582500
Message ID:
01582504
Vues:
25
Bill,

Must be misunderstanding. I didn't say that CLASS_PK is the primary key in the PARTS table. It is the primary key in the PART_CLASS table (new table). (the PARTS table does have the primary key which is not relevant to this).


>I must be missing something Dimity.
>
>Why is class_pk in the parts table a primary key?
>
>I'd expect the part number or something like to be the PK in that table.
>
>
>>Hi,
>>
>>I must be missing something simple. When I try to set the foreign key constraint, it fails. Here is the description:
>>1. I added new table PART_CLASS with primary column CLASS_PK (Int), Identity.
>>2. I added to PARTS table a column CLASS_PK (int), default 0
>>
>>I want to be sure that when/if the row/record in PART_CLASS is deleted, all referenced rows in PARTS set the value in columnd CLASS_PK to default (0).
>>
>>I think the constraint, when I set it up in SSMS, fails because table PARTS has many records and all of them have value 0 in the column CLASS_PK. But table PART_CLASS has no records. So SQL Server does not find a record in PART_CLASS of CLASS_PK value 0.
>>
>>How do you deal with this? TIA.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform