--没有任何约束条件
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)
};