Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I could drop columns with constraints

Ahmed BarakaMay 17 2024

Hi guys,

It is Oracle 19c on Windows.

I am trying to try dropping columns with constraints from testing tables and I am surprised it works without using the CASCADE CONSTRAINTS option.

Here is what I tried.

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.22.0.0.0

SQL> CREATE TABLE emp AS SELECT * FROM employees;

Table created.

SQL> CREATE TABLE dept AS SELECT * FROM departments;

Table created.

SQL> ALTER TABLE emp ADD CONSTRAINT pk_employee_id PRIMARY KEY (EMPLOYEE_ID);

Table altered.

SQL> ALTER TABLE emp ADD (CONSTRAINT emp_id_chck check (EMPLOYEE_ID > 0));

Table altered.

SQL> ALTER TABLE dept ADD ( CONSTRAINT dept_PK PRIMARY KEY ( department_id ));

Table altered.

SQL> ALTER TABLE emp ADD (CONSTRAINT emp_fk_dept FOREIGN KEY (department_id) REFERENCES departments(department_id));

Table altered.

SQL>
SQL>
SQL> ALTER TABLE emp DROP COLUMN employee_id;

Table altered.

SQL>
SQL> ALTER TABLE emp DROP COLUMN department_id;

Table altered.

SQL>
SQL> DROP TABLE dept PURGE;

Table dropped.

SQL> DROP TABLE emp PURGE;

Table dropped.

Is that the expected behavior?

This post has been answered by Jonathan Lewis on May 17 2024
Jump to Answer
Comments
Post Details
Added on May 17 2024
2 comments
1,337 views