2

What I want to do is when I delete a row from the parent table to keep the data in the child table.

Meaning that if I have a table department, which is the parent table with two columns - depNo and depName, and a child table with three columns - emNo, emName and depNo (FK).

I want to be able to delete the row in the parent table, but to keep the one in the child table (in my case it is connected with licenses and is a good idea to keep track of it, even if the user is already deleted).

I guess ON DELETE NO ACTION won't work, because it will give me an error if I try to delete the row in the parent table.

CASCADE and SET NULL are not good in this case.

SET Default - it won't work because I can't make a default value - it could be different (and its 100% sure it will be).

Any ideas how to make it ?

4

1 回答 1

2

保持外键列仍包含原始值的子数据的唯一方法是删除外键约束,这可能会导致添加不一致数据的风险。

我建议创建一个没有外键约束的新表,并在删除之前将子行复制到其中。

于 2012-11-07T12:50:22.240 回答