Drop the foreign key : Drop Foreign Key « Constraints « Oracle PL / SQL






Drop the foreign key

 


SQL>     CREATE TABLE supplier
  2      (      supplier_id     numeric(10)     not null,
  3             supplier_name   varchar2(50)    not null,
  4             contact_name    varchar2(50),
  5             CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
  6      );

Table created.

SQL>
SQL>
SQL>     CREATE TABLE products
  2      (      product_id      numeric(10)     not null,
  3             supplier_id     numeric(10)     not null,
  4             CONSTRAINT fk_supplier
  5               FOREIGN KEY (supplier_id)
  6               REFERENCES supplier(supplier_id)
  7      );

Table created.

SQL>
SQL>
SQL> -- If we then wanted to drop the foreign key called fk_supplier, we could execute the following command:
SQL>
SQL>     ALTER TABLE products
  2      drop CONSTRAINT fk_supplier;

Table altered.

SQL>
SQL>    drop table supplier cascade constraint;

Table dropped.

SQL>    drop table products cascade constraint;

Table dropped.

SQL>
           
         
  








Related examples in the same category

1.Foreign key with cascade delete
2.Disable foreign key