Chinaunix首页 | 论坛 | 博客
  • 博客访问: 929996
  • 博文数量: 358
  • 博客积分: 8185
  • 博客等级: 中将
  • 技术积分: 3751
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:27
个人简介

The views and opinions expressed all for my own,only for study and test, not reflect the views of Any Company and its affiliates.

文章分类

全部博文(358)

文章存档

2012年(8)

2011年(18)

2010年(50)

2009年(218)

2008年(64)

我的朋友

分类:

2008-12-22 16:07:33

oracle中使用alter table来增加、删除、修改列的语法
2008-06-14 10:36

alter table tablename add (column datatype [default value][null/not null],….);

alter table tablename modify (column datatype [default value][null/not null],….);

alter table tablename drop (column);

这里分别是使用alter table 来增加、删除和修改一个列。

下面是具体的例子:
create table test1
(id varchar2(20) not null);

alter table test1
add (name varchar2(30) default ‘无名氏’ not null);

alter table test1
modify (name varchar2(16) default ‘unknown’);

alter table test1
drop column name;

以上分别建立一个表,增加,更改,删除一个列。其中需要注意的是如果某一列中已经存在值,如果你要修改的为比这些值还要窄的列宽这样将会出现一个错误。

例如前面如果我们插入一个值
insert into test1
values (’1′,’我们很爱你’);

然后曾修改列: alter table test1
modify (name varchar2(8));
将会得到以下错误:
ERROR 位于第 2 行:
ORA-01441: 无法减小列长度, 因为一些值过大

阅读(577) | 评论(0) | 转发(0) |
0

上一篇:ORA-00604 & ORA-02429

下一篇:建用户和schema

给主人留下些什么吧!~~