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参数将那张表的外键一齐删除。
posted @ 2013-04-02 00:55  Gateman  阅读(122)  评论(0编辑  收藏  举报