如果父外键已删除,则将子 Table 中的外键列设置为空
Set Foreign Key Column In Child Table To Null If Parent Foreign Key Deleted
我有一个 SQLite 数据库。
我已经学会了如何插入外键,现在我想这样做:
1.删除父级中包含外键的行table
2. 将引用该外键的任何其他 table 设置为空。
我读过有关级联删除的内容,但它似乎删除了任何具有该外键的行。相反,我只想将任何具有引用外键的列值的 table 中的值设为 null。
你能告诉我该怎么做吗?或许术语是什么?
对于MySQL,听起来您想声明外键约束
ON DELETE SET NULL
参考:http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
我对 sqllite 不太熟悉,但是 ON DELETE SET NULL
在...
中提到
ON DELETE SET NULL
在创建外键约束的地方添加这个
我有一个 SQLite 数据库。
我已经学会了如何插入外键,现在我想这样做: 1.删除父级中包含外键的行table 2. 将引用该外键的任何其他 table 设置为空。
我读过有关级联删除的内容,但它似乎删除了任何具有该外键的行。相反,我只想将任何具有引用外键的列值的 table 中的值设为 null。
你能告诉我该怎么做吗?或许术语是什么?
对于MySQL,听起来您想声明外键约束
ON DELETE SET NULL
参考:http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
我对 sqllite 不太熟悉,但是 ON DELETE SET NULL
在...
ON DELETE SET NULL
在创建外键约束的地方添加这个