在oracle sql

我有一张与此类似的表。

CREATE TABLE customers (
    customer_id NUMber(7,0) NOT NULL,customer_name VARCHAR2(50) NOT NULL,CONSTRAINT customers_pk PRIMARY_KEY (customer_id)
);

在表中有一些值。

我想将主键customer_id的数据类型更改为NUMber(10,0)。那么在执行ALTER命令之前我们应该遵循什么步骤? (此列在任何表中均未作为外键引用)

具体地说,

默认情况下,在oracle SQL中,主列上有一个索引。那么我们应该删除主键约束,然后执行ALTER命令吗? 还有我们需要考虑的其他事项吗?

iCMS 回答:在oracle sql

对于像您这样的情况,您无需执行任何操作-只需执行

SQL> create table customers (
  2  customer_id number(7,0),3  customer_name varchar2(50),4  constraint customer_pk primary key (customer_id));

Table created.

SQL> insert into customers
  2  select 1234566,'Little' from dual union all
  3  select 98876,'Foot'   from dual;

2 rows created.

SQL> alter table customers modify customer_id number(8,0);

Table altered.

SQL> select constraint_name from user_constraints where table_name = 'CUSTOMERS';

CONSTRAINT_NAME
------------------------------
CUSTOMER_PK

SQL>

但是,如果您不得不将列缩小或修改其数据类型-那是另一回事了。幸运的你,不是你的。

本文链接:https://www.f2er.com/2122792.html

大家都在问