oracle辅导(3--1)

约束

 

非空约束(not null)这是一个列级约束

在建表时,在数据类型的后面加上 not null ,也就是在插入时不允许插入空值。

 

例:create table student(id number primary key,name varchar2(32) not null,address varchar2(32));

 

unique 唯一约束

 

唯一约束,是会忽略空值的,唯一约束,要求插入的记录中的值是为一的。

 

例:create table student(id numbername varchar2(32),address varchar2(32),primary key (id),unique (address));

 

check约束

 

检查约束,可以按照指定条件,检查记录的插入。check中不能使用尾列,不能使用函数,不能引用其他字段。

 

例:create table sal (a1 number , check(a1>1000));

 

创建脚本

 

例:见课本相应章节

 

一对一建表语句

student tabel  (学生表)         

Id

(PK)

 

Name

Addesss

 

 

 

 

xueshengzheng table(学生证表)

X_id

(FK,PK)

 

desc

Xuhao

 

 

 

 

 

 

student table

 

create table student(

     id number,

     name varchar2(32),

     address varchar2(32)

     primary key(id)

);

 

xueshengzheng table

 

create tabel xueshengzheng(

     X_id number primary key,

     num number unique not null,

     foreign key (x_id) references student(id)

);

 

一对多

class table(班级表)

 

C_id

(PK)

 

class_num

class_desc

 

 

 

 

student table (学生表)                     

Id

(PK)

 

name

address

C_id

(FK)

 

 

 

 

 

class table

create table class(

        cid number,

        class_num number,

        desc varchar2(32),

        primary key(cid)

);

 

student table

create table student(

     id number,

     name varchar2(32),

     address varchar2(32)

     class_id number,

     primary key(id),foreign key (class_id) references class(cid)

);

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值