表基本信息修改

示例操作如下

--班级信息表
create table t_class_info( 
 classno number(3) primary key, 
 classname varchar2(10), 
 classplace varchar2(13) 
); 

--学生信息表
create table t_student_info( 
 stuno number(3),
 classno number(3), 
 stuname varchar2(10), 
 stusex char(1),
 stucontect number(11), 
 stuadd varchar2(50), 
 studetailinfo varchar2(100) 
);

--重命名表
alter table t_class_infot rename to t_class_info

--修改列名 
alter table t_class_info rename column classplace to location; 

--添加主键约束 
alter table t_student_info add constraint pk_stu_no primary key(stuno); 


--添加外键约束
alter table t_student_info add constraint fk_classno foreign key(classno) references t_class_info(classno); 

--添加check约束
alter table t_student_info add constraint ck_stu_info check (stusex in ('f','m'));

alter table ttt add constraint index_age check (age>0 and age<50)

--添加not null约束 
alter table t_student_info modify stucontect constraint not_null_info not null;

--添加unique约束 
alter table t_student_info add constraint uq_stu_contect unique(stucontect); 

--添加default约束
alter table t_student_info modify stusex char(2) default'm';

--增加列
alter table t_student_info add stuid varchar2(18); 
alter table t_student_info add stuage date default sysdate not null;

--删除列 
alter table t_student_info drop column studetailinfo;

--修改列的长度,长度只能由小改成大,如果要改小,则要删除该字段下的值 
alter table t_class_info modify classplace varchar2(50); 

--修改列的精度 
alter table t_student_info modify stuno number(2); 

--修改列的数据类型 
alter table t_student_info modify stusex char(2); 

--修改列的默认值 
alter table t_student_info modify stuage default sysdate+1;

--禁用约束 
alter table t_student_info disable fk_classno; 

--启用约束 
alter table t_student_info enable fk_classno; 

--删除约束,如果有外键约束则要先删除外键表中的
alter table t_student_info drop fk_classno; 

--延迟约束 
alter table t_student_info add constraint fk_classno foreign key(classno) 
references t_class_info(classno) 
deferrable initially deferred;

--向表中添加注释 
comment on table t_student_info is '学生表';
 
--向列添加注释 
comment on column t_student_info.stuname is '学生姓名'; 
comment on column t_class_info.classname is '班级'; 

--清除表中所有数据 
truncate table t_student_info; 
--删除表 
drop table t_student_info; 


--删除表不经过回收站
drop table t_student_info purge;


--闪回被删除的表
flashback table t_student_info to before drop;


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值