B
B
Bjornie2017-02-07 03:35:25
MySQL
Bjornie, 2017-02-07 03:35:25

Do I need to protect data in dependent tables with a Foreign Key?

For example, there are two tables, one has a list of something (an ancestor), the other has another list (a descendant), and one column refers to the primary key of the ancestor. If the data in the first table is deleted, then the second one will lose an important component.
Is it possible (necessary) to prescribe FOREIGN KEY (RESTRICT) in all such cases, when there are dependencies of one on the other. Although I admit that somewhere you can use the ON DELETE SET NULL constructs, and then the child will simply be set to NULL, and the data will hang out (remain unattached).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2017-02-07
@Rsa97

It is only you who can decide whether you need to maintain the referential integrity of the database.

I
Ivan, 2017-02-07
@LiguidCool

When it's relevant, it's easier to make a separate field for the ancestor, like boolean -> del_status (or something like that). Well, in fact, do not delete anything, but only exclude from the selection.
Or write a request that will arrange a massive "Holocaust" for children .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question