ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 1 Managing Schema Objects

1 Managing Schema Objects

原创 Linux操作系统 作者:piedra1130 时间:2013-06-05 23:57:20 0 删除 编辑

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博客 ” ,链接:https://blog.itpub.net/22327710/viewspace-763150/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 1212
请登录后发表评论 登录
全部评论

注册时间:2009-08-12

  • 博文量
    36
  • 访问量
    41610