oracle数据库删除某一列,如何删除已经有数据表中的列?

本文介绍了Oracle 8i中新增的列删除功能,包括直接删除未使用的列和先标记为未使用再后续删除。还演示了如何使用ALTER TABLE语句进行操作,以及如何通过CASCADE CONSTRAINTS处理约束。重点在于如何标记大型表中的未使用列以便资源管理。
摘要由CSDN通过智能技术生成

Prior to Oracle8i, the only way to remove a column was to re-create the table

without the column name. In Oracle8i, you have the much awaited option of

dropping a column. You can drop a column that is not used immediately, or

you can mark the column as not used and drop it later.

Here is the syntax for dropping a column:

ALTER TABLE [schema.]table_name

DROP {COLUMN column_name |(column_names)}[CASCADE

CONSTRAINTS ]

DROP COLUMN drops the column name specified from the table. You can pro-vide

more than one column name separated by commas inside parentheses. The

indexes and constraints on the column are also dropped. You must specify

CASCADE CONSTRAINTS if the dropped column is part of a multicolumn con-straint;

the constraint will be dropped.

The syntax for marking a column as unused follows:

ALTER TABLE [schema.]table_name

SET UNUSED {COLUMN column_name |(column_names)}[CASCADE

CONSTRAINTS ]

You usually mark a column as unused and not dropped if the table is very

large and takes a lot of resources at peak hours. In such cases, you would

mark the column as unused and drop it later. Once the column is marked as

unused, you will not see it as part of the table definition. Let’s mark the

UPDATE_DT column in the ORDERS table as unused:

SQL>ALTER TABLE orders SET UNUSED COLUMN update_dt;

Table altered.

SQL>DESCRIBE orders

Name Null?Type

-------------------------------------------------------

ORDER_NUMBER NOT NULL NUMBER(8)

STATUS VARCHAR2(15)

ORDER_DATE DATE

QUANTITY NUMBER(10,3)

SQL>

The syntax for dropping a column already marked as unused is

ALTER TABLE [schema.]table_name

DROP {UNUSED COLUMNS |COLUMNS CONTINUE}

Use the COLUMNS CONTINUE clause to continue a DROP operation that was

previously interrupted. To clear data from the UPDATE_DT column from

the ORDERS table, do this:

ALTER TABLE orders DROP UNUSED COLUMNS;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值