This Oracle tutorial explains how to disable a overseas key in Oracle with syntax and examples.
Description
Once you have created a foreign key in Oracle, you may come upon a situation where you are required to disable the overseas key. You can do this using the ALTER TABLE statement in Oracle.
Syntax
The syntax to disable a foreign key in Oracle/PLSQL is:
ALTER TABLE table_name
DISABLE CONSTRAINT constraint_name;
Example
If you had created a foreign key as follows:
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)
);
In this example, we’ve created a primary key on the supplier table called supplier_pk. It consists of solely one field – the supplier_id field. Then we’ve created a foreign key called fk_supplier on the merchandise table that references the provider desk based on the supplier_id field.
If we then wanted to disable the foreign key referred to as fk_supplier, we may want to execute the following command:
ALTER TABLE products
DISABLE CONSTRAINT fk_supplier;
Leave a Review