Oracle的约束

学习笔记:

##约束
    *概念:限定用户输入的内容。
    *案例:
        *练习
            * 1. 在score表的grade列添加CHECK约束,限制grade列的值在0到100之间。
                alter table score
                  add constraint ck_grade check(grade>=0 and grade<=100);
            * 2. 删除student表的sno列的primary key约束,然后再该列添加primary key约束。
                alter table student
                  drop constraint SYS_C009862;
                alter table student
                  add constraint pk_sno primary key(sno);
            * 3. 在score表的sno列添加foreign key约束,与student表中主键列创建表间参照关系。
                alter table score
                  add constraint fk_sno foreign key(sno) references student(sno);
                4.在course表中创建外键,与teacher表中主键列创建表间参照关系。
                alter table course
                  add constraint fk_tno foreign key(tno) references teacher(tno);

 

 

posted @ 2019-11-30 10:53  the_path_of_grace  阅读(357)  评论(0编辑  收藏  举报