Oracle drop constraint cascade equivalent in Sql Server

假装没事ソ 提交于 2019-12-13 05:48:08

问题


In Oracle, to drop the constraint PK_SAI I use the syntax:

ALTER TABLE "SAISIE" 
    DROP CONSTRAINT "PK_SAI" CASCADE;

What is the equivalent of this in SQL Server?


回答1:


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;

Dropping a constraint with CASCADE does not delete any rows.

DELETE deletes rows, if you have enabled ON DELETE 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.

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

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



来源:https://stackoverflow.com/questions/26760547/oracle-drop-constraint-cascade-equivalent-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!