原文:https://blog.csdn.net/DaneLei/article/details/87986131
修改字段名語法:alter table tableName rename column oldCName to newCName;
例:alter table student rename column address to addr
添加字段的語法:alter table tablename add (column datatype [default value][null/not null],….);
例:alter table student add( grade number(3) default 99 not null) ;
修改字段的語法:alter table tablename modify (column datatype [default value][null/not null],….);
例:alter table student modify(grade varchar2(5));
刪除字段的語法:alter table tablename drop (column);
例:alter table student drop (grade);
※如果修改字段是字符串轉數值且原來有數據等其他特殊情況,可以建臨時字段過渡
/*修改原字段名grade為grade_tmp*/
alter table student rename column grade to grade_tmp;
/*增加一個和原字段名同名的字段grade*/
alter table student add grade number(3);
/*將原字段grade_tmp數據更新到增加的字段grade*/
update student set grade=trim(grade_tmp);
/*更新完,刪除原字段grade_tmp*/
alter table student drop column grade_tmp;
