英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论