DROP 不可为空的列

DROP a not nullable column

我使用 ORACLE,我知道您不能删除具有非空约束的列。

您必须先将其更改为可为空,然后才能删除它。

如果该列不是主键或外键,为什么我不能删除它?

有人可以解释这种行为的原因吗?

I use ORACLE and i know that you cannot DROP a column which has a not null constraint.

不,你错了。您可以删除 NOT NULL 列。

If the column is not a primary key or foreign key , why cant i just drop it?

是的,你可以。

参见:

SQL> CREATE TABLE t(a number, b varchar2(10) not null);

Table created.

SQL>
SQL> INSERT INTO t(A, b) VALUES(1, 'one');

1 row created.

SQL>
SQL> SELECT * FROM t;

         A B
---------- ----------
         1 one

SQL>
SQL> ALTER TABLE t DROP COLUMN b;

Table altered.

SQL>
SQL> DESC t;
 Name                                      Null?    Type
 ----------------------------------------- -------- ------
 A                                                  NUMBER

SQL>
SQL> SELECT * FROM t;

         A
----------
         1

SQL>