oracle的alter table,Oracle ALTER TABLE语句

本文概述

在Oracle中, ALTER TABLE语句指定如何添加, 修改, 删除或删除表中的列。它也用于重命名表。

如何在表格中添加列

句法:

ALTER TABLE table_name

ADD column_name column-definition;

例:

考虑已经存在的表客户。现在, 在表customers中添加新列customer_age。

ALTER TABLE customers

ADD customer_age varchar2(50);

现在, 将在客户表中添加一个新列” customer_age”。

如何在现有表中添加多个列

句法:

ALTER TABLE table_name

ADD (column_1 column-definition, column_2 column-definition, ...

column_n column_definition);

例子

ALTER TABLE customers

ADD (customer_type varchar2(50), customer_address varchar2(50));

Now, two columns customer_type and customer_address will be added in the table customers.

如何修改表的列

句法:

ALTER TABLE table_name

MODIFY column_name column_type;

例:

ALTER TABLE customers

MODIFY customer_name varchar2(100) not null;

Now the column column_name in the customers table is modified

to varchar2 (100) and forced the column to not allow null values.

如何修改表格的多列

句法:

ALTER TABLE table_name

MODIFY (column_1 column_type, column_2 column_type, ...

column_n column_type);

例:

ALTER TABLE customers

MODIFY (customer_name varchar2(100) not null, city varchar2(100));

This will modify both the customer_name and city columns in the table.

如何删除表的列

句法:

ALTER TABLE table_name

DROP COLUMN column_name;

例:

ALTER TABLE customers

DROP COLUMN customer_name;

This will drop the customer_name column from the table.

如何重命名表的列

句法:

ALTER TABLE table_name

RENAME COLUMN old_name to new_name;

例:

ALTER TABLE customers

RENAME COLUMN customer_name to cname;

This will rename the column customer_name into cname.

如何重命名表格

句法:

ALTER TABLE table_name

RENAME TO new_table_name;

例:

ALTER TABLE customers

RENAME TO retailers;

This will rename the customer table into "retailers" table.

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值