Oracel 修改约束命令


增加修改列的约束:
alter table dep_1
modify
(Dep_id number(5) default 8 constraint dep_1_id_nn not  null

                                                                                             --非空约束                               

修改表的约束
(例如设置主键)
alter table dep_1
add constraint Dep_1_id_pk Primary key(Dep_id)

alter table dep_1
modify
(constraint Dep_1_id_pk Primary key(Dep_id))



(设置外键)
alter table GRADE_1
add constraint grade_dep_1_fk foreign key(DEP) references DEP_1(DEP_ID)
ON DELETE CASCADE
                                                                                                                           --当父表记录删除,对应子表记录都删除
alter table GRADE_1
add constraint grade_dep_1_fk foreign key(DEP) references DEP_1(DEP_ID)
ON DELETE SET NULL
                                                                                                                          --当父表记录删除,对应子表记录外键置null
(自定义约束check)
alter table dep_1
add constraint Dep_1_nm_len check(length(dep_name) >= 2)


删除表的约束
alter table dep_1
drop
constraint Dep_1_id_pk cascade
 
                                       --删除主键,若此主键是其他表的外键,要用cascade参数将那张表的外键一齐删除。

转载于:https://www.cnblogs.com/nvd11/archive/2013/04/02/2996850.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值