Oracle中表字段相关操作举例

时间:2022-01-12 14:49:03
--创建测试表
create or replace table student
(
xh number(4), --学号
xm varchar2(10), --姓名
sex char(2), --性别
birthday date, --日期
sal number(7,2) --奖学金
); --添加一个字段
alter table student add (studentid number(10)); --添加多个字段
alter table student add
(
xh number(4), --学号
xm varchar2(10), --姓名
sex char(2), --性别
birthday date, --日期
sal number(7,2) --奖学金
); --删除一个字段
alter table student drop column xh; --修改一个字段
--1.修改长度
alter table student modify (sex char(5));
--2.修改字段的类型
alter table student modify (sex varchar2(5)); --给表改名字
rename student to stuinfo; --字段如何改名字
--1.先删除
alter table student drop column sal;
--2.再添加
alter table student add(salary varchar2(6));