oracle建表性别检查约束,oracle创建表(约束)

--没有任何约束条件

create table bookinfo{

bookid int,

bookname char,

publish varchar2(20),

pubdata varchar2(20),

price decimal,

author char(40),

store int,

reader int,

remarks varchar2(50)

};

--指定了默认值:price store

create table bookinfo{

bookid int,

bookname char,

publish varchar2(20),

pubdata varchar2(20),

price decimal(7,2) default 0.0,

author char(40),

store int default 0 not null,

reader int,

remarks varchar2(50)

};

--检查约束:price

create table bookinfo{

bookid int,

bookname char,

publish varchar2(20),

pubdata varchar2(20),

price decimal,

author char,

store int,

reader int,

remarks varchar2(50),

constraint ck_price check (price>=10 and price<=100)

};

--非空约束:bookid bookname

create table bookinfo{

bookid int not null,

bookname char not null,

publish varchar2(20),

pubdata varchar2(20),

price decimal,

author char,

store int,

reader int,

remarks varchar2(50)

};

--唯一约束:bookname

create table bookinfo{

bookid int,

bookname char,

publish varchar2(20),

pubdata varchar2(20),

price decimal,

author char,

store int,

reader int,

remarks varchar2(50),

constraint un_bookname unique(bookname)

};

--外键约束 publish

create table publishinfo{

publishid varchar2(20) primary key,

publishname varchar(30)

}

create table bookinfo{

bookid int,

bookname char;

publish varchar2(20),

pubdata varchar2(20),

price decimal,

author char,

store int,

reader int,

remarks varchar2(50),

constraint fk_publish foreign key (publish) references publishinfo(publishid)

};

--创建一个含有多个约束的表

create table bookinfo{

bookid int,

bookname char,

publish varchar2(20) not null,

pubdata varchar2(20),

price decimal,

author char,

store int,

reader int,

remarks varchar2(50),

constraint ck_price check (price<=100),

constraint un_bookname unique (bookname)

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值