前端之家收集整理的这篇文章主要介绍了
Oracle-约束小结,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/*create table emp2(
id number(10) constraint emp2_id_nn not null,name varchar2(20) not null,salary number(10,2)
)*/
/*create table emp4(
id number(10) constraint emp4_id_nn not null,name varchar2(20) constraint emp4_name_nn not null,email varchar2(20),2),
constraint emp4_id_uk unique(id),constraint emp4_email_uk unique(email)
)*/
/*create table emp4(
id number(10) constraint emp4_id_pk primary key,constraint emp4_email_uk unique(email)
)*/
/*create table emp5(
id number(10) constraint emp5_id_pk primary key,department_id number(20),constraint emp5_email_uk unique(email),
constraint emp5_dept_id_fk foreign key(department_id) references departments(department_id) on delete set null
)/*departments 为父表,emp5为子表*/
/*on delete cascade 级联删除,当父表中的列被删除时,子表中相对应的列也被删除*/
/*on delete set null 级联置空 ,。。。子表中相应的列置空*/
create table emp7(
id number(10) constraint emp7_id_pk primary key,name varchar2(20) constraint emp7_name_nn not null,2) constraint emp7_salary_ck check(salary>1500),constraint emp7_email_uk unique(email),
)
alter table emp5
add constraint emp5_name_uk unique
modify (salary number(10,2) not null)
drop constraint SYS_C005484
disable constraint emp5_name_uk
enable constraint emp5_name_uk
select constraint_name,constraint_type,search_condition,column_name
from user_constraints where table_name = 'employees'