日期:2014-05-16 浏览次数:20579 次
Oracle培训(三十)——Oracle 11g 第十章知识点总结——约束
知识点预览
复习
约束
复习
--主键
primarykey
--(非空+唯一)
--唯一能够标识表里的一条记录
--非空
not null
--唯一性约束
unique
--检查约束
check(gender in('男','女'))
--外键
--当前表里的这个外键是另外一张表里的主键
--必须和哪个主键的数据类型和长度保持一致
--删除表
drop table table_name
--产生乱码
purge table "BIN$2RcRpY2KSLy+FONALkCBUw==$0";
purge table t_tes;--错误
--DBA
--创建表
--分类表
--基表
create tablecategory (
idnumber(3) primary key,
namevarchar2(20) not null
);
--产品表
--从表
create table product(
idnumber(10) primary key,
namevarchar2(20) not null,
cidnumber(3),
constraintscott_product_cid_FK foreign key(cid) references category(id)
);
insert into categoryvalues(1,'电脑');
insert into productvalues(1,'IBM',1);
insert into categoryvalues(2,'食品');
insert into productvalues(2,'牛肉干',2);
--删除
--先删除从表数据
--后删主表数据
delete category where id=1;
约束
1. 什么是约束
a) 约束是表级的强制规定
b) 约束放置在表中删除有关联关系的数据
c) 有以下五种约束:
i. NOT NULL
ii. UNIQUE
iii. PRIMARY KEY