How to disable primary key constraint of an existing table?
meda Changed status to publish 16/07/2022
Oracle database constraints include but not limited to :
- Primary key
- Foreign key
- Unique key
- NOT NULL
- Check
on oracle, it is possible to disable constraints without re-creating and dropping them.
Here below is an example on how to add primary key constraints to an existing database table.
Example:
SQL> desc emp_sal; Name Null? Type ----------------------------------------- -------- ---------------------------- EMP_ID NUMBER SALARY NUMBER JOBTITLE VARCHAR2(12) SQL> alter table emp_sal add constraint pk_impID PRIMARY KEY(EMP_ID); Table altered. SQL>
Here is also an example on how to disable primary key constraint to an existing table.
SQL> alter table emp_sal disable constraint pk_impid; Table altered. SQL>
We can also enable primary key constraint of existing table using the below SQL command:
SQL> alter table emp_sal enable constraint pk_impid; Table altered. SQL>
meda Edited answer 22/02/2022