且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

合并主键-级联更新

更新时间:2023-02-03 07:53:38

没有自动方法,但是有两种选择,您可以手动编写这些过程,或者您可以代码定期生成合并,也可以在运行时动态生成合并。为此,您可以使用 INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS INFORMATION_SCHEMA.KEY_COLUMN_USAGE INFORMATION_SCHEMA。 TABLE_CONSTRAINTS INFORMATION_SCHEMA.COLUMNS和INFORMATION_SCHEMA.TABLES 来动态构建过程。

There's no automatic way to do it, but you have a couple options, you can manually write the procedures, or you can either code generate the merge on a regular basis or dynamically generate it at run-time. To do this, you can use the INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS and INFORMATION_SCHEMA.KEY_COLUMN_USAGE and INFORMATION_SCHEMA.TABLE_CONSTRAINTS and INFORMATION_SCHEMA.COLUMNS and INFORMATION_SCHEMA.TABLES to build the procedure dynamically.

您还可以简单地将整个操作包装在一个事务中(无论如何是个好主意)。最后一步是从中删除要合并的客户,因此,如果您从未添加过的表上存在RI并尝试进行合并,则它将失败,因为您不能从其中删除要合并的客户,因为表中的记录(尚未添加到合并过程中)。

You can also simply wrap the entire operation in a transaction (a good idea anyway). The last step will be to remove the customer being merged out of, so if there is RI on a table you never added and you try to do a merge, it will fail because you cannot remove the customer being merged out of since there are dependent records in a table which wasn't already added to the merge procedure.