1 Managing Schema Objects

1       Managing Schema Objects

1.1              Add and Modify Columns

1.11         Adding Columns

ALTER TABLE CRUISE_ORDERS ADD (ORDER_DATE VARCHAR2(20));

 

Notice the structure of this statement:

n  The required keywords ALTER TABLE

n  The name of the table we wish to alter

n  The required keyword ADD

n  The name of a new column, and its column specification, enclosed in parentheses

 

For each column, the clause specifies one or more of the following three elements:

n  Datatype and datatype specification—required

n  DEFAULT and default value—optional

n  CONSTRAINT definition—optional

 

syntactically wrong:

ALTER TABLE CRUISE_ORDERS

      ADD (WEATHER_CODE DEFAULT 0 NUMBER(2));

But this is syntactically correct:

ALTER TABLE CRUISE_ORDERS

      ADD (WEATHER_CODE NUMBER(2) DEFAULT 0);

 

1.12         Adding Not Null Columns

如果表已经存在行,不可添加not null的列:

01   ALTER TABLE CRUISE_ORDERS

02         ADD   FIRST_TIME_CUSTOMER VARCHAR2(5)

03               NOT NULL;

 

设置缺省值才可。//如果添加的列为not null,且原有表有行,必须添加default参数

01   ALTER TABLE CRUISE_ORDERS

02         ADD   FIRST_TIME_CUSTOMER VARCHAR2(5)

03               DEFAULT 'YES'

04               NOT NULL;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22327710/viewspace-763150/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22327710/viewspace-763150/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值