codecamp

Oracle 怎么禁用外键

我们创建外键后,可能有时会遇到要禁用外键的情况,那么在Oracle中,我们如何对外键进行禁用呢?

语法

在Oracle中,我们要禁用外键可以使用以下语法:

ALTER TABLE table_name
DISABLE CONSTRAINT constraint_name;

示例:

我们先通过以下代码创建一个名为fk_supplier的外键:

CREATE TABLE supplier
( supplier_id numeric(10) not null,
  supplier_name varchar2(50) not null,
  contact_name varchar2(50),
  CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);

CREATE TABLE products
( product_id numeric(10) not null,
  supplier_id numeric(10) not null,
  CONSTRAINT fk_supplier
    FOREIGN KEY (supplier_id)
    REFERENCES supplier(supplier_id)

在这个例子中,在supplier表上创建了一个名为supplier_pk的主键。 它只包含一个字段 - supplier_id字段。 然后,我们在products表上创建了一个名为fk_supplier的外键,products表的supplier_id字段引用supplier表的supplier_id字段。

如果想禁用这个外键,可以执行以下命令:

ALTER TABLE products
DISABLE CONSTRAINT fk_supplier;


Oracle 怎么删除外键
Oracle 启用外键
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }