且构网

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

SQL Server中的Oracle删除约束级联等效

更新时间:2022-06-09 22:19:54

您正在考虑与实际DELETE语句有关的FOREIGN KEY约束的CASCADE功能.

You are thinking of the CASCADE feature on FOREIGN KEY constraints, in relation to actual DELETE statements.

ALTER TABLE t2 add constraint FK_T2 foreign key(t_id) references t(id)
   ON DELETE CASCADE;

使用CASCADE删除约束不会删除任何行.

Dropping a constraint with CASCADE does not delete any rows.

如果您启用了ON DELETE CASCADE,则删除将删除行.

DELETE deletes rows, if you have enabled ON DELETE CASCADE.

删除约束只是删除约束(以及关联的索引和从属约束),而不是数据行.在SQL Server ALTER TABLE ...中,我不知道像在Oracle中那样有一个"CASCADE"选项.

Dropping the constraint simply drops the constraint (and associated indexes and dependent constraints), not data rows. In SQL Server ALTER TABLE ... I am not aware that there is a "CASCADE" option as in Oracle.

来自Oracle文档 http://docs.oracle .com/cd/B28359_01/server.111/b28286/statements_3001.htm#i2103845 用于ALTER TABLE语句:

From Oracle docs http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_3001.htm#i2103845 for the ALTER TABLE statement:

CASCADE如果您还希望删除所有其他依赖于丢弃的完整性约束的完整性约束,请指定CASCADE.

CASCADE Specify CASCADE if you want all other integrity constraints that depend on the dropped integrity constraint to be dropped as well.