代码之家  ›  专栏  ›  技术社区  ›  johnstok

为什么这个“modify table”语句失败?

  •  1
  • johnstok  · 技术社区  · 15 年前

    我正在尝试向Oracle9中的列添加“not null”约束。

    ALTER TABLE user_roles modify group_id varchar2(36 char) set not null;
    

    但是,操作失败,错误为奇数:

    Error report:
    SQL Error: ORA-12987: cannot combine drop column with other operations
    12987. 00000 -  "cannot combine drop column with other operations"
    *Cause:    An attempt was made to combine drop column with other
               ALTER TABLE operations.
    *Action:   Ensure that drop column is the sole operation specified in
               ALTER TABLE.
    

    你知道为什么会失败吗?

    3 回复  |  直到 15 年前
        1
  •  2
  •   Quassnoi    15 年前

    去除 set :

    ALTER TABLE user_roles modify group_id varchar2(36 char) not null
    

    是的, Oracle 的错误可能非常误导人。

        2
  •  0
  •   johnstok    15 年前

    结果证明上述语句的语法是错误的。应该是:

    ALTER TABLE user_roles modify group_id varchar2(36 char) not null;
    

    然而,错误的“集合”的存在会导致一个非常奇怪的错误!

        3
  •  0
  •   APC    15 年前

    我正在尝试添加一个“not null” 对Oracle9中某列的约束。

    如果您真的尝试jsut使列不为空(即您不想同时更改数据类型),您只需要

    ALTER TABLE user_roles modify not null;