Null Parent field when lookup item is deleted

huangapple go评论76阅读模式
英文:

Null Parent field when lookup item is deleted

问题

让我们假设我有一个父表和一个查找表。父表引用查找表。如果我从引用它的查找表中删除行,我希望能够将父字段设置为null。

在删除或级联上不起作用,或者我设置错了。我不想删除父行,只是在从查找表中删除项目时将引用字段更新为null。

英文:

Lets say I have a parent table and a lookup table. The parent table references the lookup table. I want to be able to set the parent field to null if I delete the row from the lookup table that it references.

On delete or on cascade isnt working, or I am setting it wrong. I don't want to delete the parent row just update the referenced field to null if I delete the item from the lookup table.

答案1

得分: 1

针对我更好的判断...我建议使用一个"触发器"。

当发生删除时,"更新"另一个表。

链接:https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-ver16

英文:

Against my better judgment... I recommend using a "trigger".

When a delete occurs, "update" the other table.

https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-ver16

huangapple
  • 本文由 发表于 2023年7月13日 22:44:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680690.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定