完整性约束
1.非空约束 NK
create table member(
id varchar2(38),
name varchar2(100) not null,
)
2.唯一性约束 UK
create table member(
id varchar2(38),
name varchar2(100),
constraint uk_name unique (name),
);
3.主键约束 PK
create table member(
id varchar2(38),
name varchar2(100),
constraint pk_id primary key (id)
);
4.检查约束 CK
create table member(
id varchar2(38),
name varchar(100),
age number,
constraint ck_age check(age between 0 and 200)
);
5,主_外键约束
create table member(
id varchar2(38),
name varchar2(100),
constraint pk_id primary key(id)
);
create table advice(
id varchar2(38),
content varchar2(100),
mid varchar2(38),
constraint pk_id primary key (id),
constraint fk_mid foreign key(mid) references member(id) on delete cascade 外键包含级联删除 (constraint fk_mid foreign key (mid) references member(id) on delete set null 外键包含级联更新)
);
6.查看约束
查看那些表上存在约束
select constraint_name,constraint_type,table_name from user_constraints;
查看那些列上存在约束
select * from user_cons_columns;
7.修改约束
(1)添加约束
alter table 表名称 add constraint 约束名称(约束字段)
(2)启动、禁用约束
alter table 表名称 disable constraint 约束名称;
alter table 表名称 enadble constraint 约束名称;
(3)删除约束
alter table 表名称 drop constraint 约束名称;