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/