zoukankan      html  css  js  c++  java
  • 十三、修改表时添加约束

    a) 创建主表clazz

    create table clazz (

           cno number(3) primary key,

           cname varchar2(20) not null,

           croom number(3)

    );

    b) 创建从表student

    create table student (

           sno number(4),

           sname varchar2(12) not null,

           gender char(3) default '男',

           age number(3),

           sdate date,

           email varchar2(50),

           cno number(3)

    );

    c) 给student表添加约束

    -- 主键约束

    alter table student add constraints pk_student primary key (sno);

    -- 唯一约束

    alter table student add constraints uk_student_email unique (email);

    -- 检查约束

    alter table student add constraints ck_student_age check (age between 18 and 30);

    alter table student add constraints ck_student_gender check (gender in ('男','女'));

    -- 外键约束

    alter table student add constraints fk_student_cno foreign key (cno) references clazz (cno);

  • 相关阅读:
    77. Combinations
    319. Bulb Switcher
    222.Count Complete Tree Nodes
    842.Split Array into Fibonacci Sequence
    306.Additive Number
    747.Largest Number At Least Twice of Others
    并查集
    HDU-3371 Connect the Cities
    HDU-1863 畅通工程
    HDU-1879 继续畅通工程
  • 原文地址:https://www.cnblogs.com/qiaoxin11/p/12775369.html
Copyright © 2011-2022 走看看