Foreign key SQL SET NULL

0

Good people, let's go to one more question, I hope you can help me.

I have the following problem:

When I create a foreign key linking to another field in another table I always define it as CASCADE . But when I enter a field (say in this table I have foreign keys attached to it and one of them can be NULL ) I can not successfully register the table for the fact it does not find in the other referenced table value.

I think it's because it's using the CASCADE type and SET NULL would allow this field to exist with the NULL value.

Defining my foreign key as SET NULL will solve my problem?

    
asked by anonymous 08.04.2016 / 03:40

1 answer

2

Names of oxen

The A table has a foreign key to the B table.

The solution

Set the A field to NULL .

The explanation

The CASCATE foreign keys are triggered when changes occur in the referenced table, not referring table. In this case, a CASCATE SET NULL will make the A field become when is deleted from B .

This is a different case. You want records in A to be born without a referrer in B . This has nothing to do with CASCATE , but rather as the definition itself in A .

    
08.04.2016 / 04:25