以下是ON DELETE的官方解释: ON DELETE
The ON DELETE clause indicates that when a DELETE is executed on a referenced row in the referenced table, one of the following actions will be executed upon the constrained column, as specified by action:
NO ACTION(default)
The NO ACTION clause produces an error if the reference is violated. This is the default if action is not specified. CASCADE The CASCADE keyword removes all rows which reference the deleted row. Exercise caution with this action. SET NULL
The SET NULL clause assigns a NULL value to all referenced column values.
ALTER TABLE foo ADD CONSTRAINT foo_bar_fk FOREIGN KEY (bar_id) REFERENCES
bar(bar_id) ON DELETE RESTRICT
- meaning: If someone tries to remove a row in bar which foo needs (for
referential integrity), the action is denied (in stead of cascaded as a
deletion in the foo table). See you DBMS's documentation for more on this.
RESTRICT can also be part of a command, like: DROP TABLE bar RESTRICT;
- meaning: Drop the "bar" table, unless the table is used as part of
referential integrity constraints in other tablesALTER TABLE foo ADD CONSTRAINT foo_bar_fk FOREIGN KEY (bar_id) REFERENCES
bar(bar_id) ON DELETE RESTRICT
- meaning: If someone tries to remove a row in bar which foo needs (for
referential integrity), the action is denied (in stead of cascaded as a
deletion in the foo table). See you DBMS's documentation for more on this.
RESTRICT can also be part of a command, like: DROP TABLE bar RESTRICT;
- meaning: Drop the "bar" table, unless the table is used as part of
referential integrity constraints in other tables