在student 表添加一列:
alter table student add cla_id number;
把它设置为非空的:
alter table student modify cla_id not null;
设置为非空弹出错误窗口提示:
[img]http://dl.iteye.com/upload/attachment/0083/1677/a2db3682-fac3-33e2-a61f-741b8c1633d9.jpg[/img]
在student 表添加一列:
alter table student add cla_id number;
把它设置为非空的:
alter table student modify cla_id not null;
设置为非空弹出错误窗口提示:
[img]http://dl.iteye.com/upload/attachment/0083/1677/a2db3682-fac3-33e2-a61f-741b8c1633d9.jpg[/img]
在student 表添加一列:
alter table student add cla_id number;
此时,cla_id这列都是空值。
把它设置为非空的:
alter table student modify cla_id not null;
由于上面你添加的列为空,而此时设置为非空,肯定报错了。
alter table的语法如下:
[code="java"]
alter table tablename add (column datatype [default value][null/not null],….);
[/code]
所以,你应该设置默认值:
alter table student add cla_id number default 0;