博客信息

oracle中创建唯一,主键,外键,自定义约束;删除约束;使约束生效/失效;查询系统存在的约束

发布时间:『 2012-10-03 11:25』  博客类别:Oracle  阅读(1924) 评论(0)

/*创建唯一约束*/

alter table dept add constraints dept_id_uk unique(DNAME);

/*添加主键约束*/
alter table dept add constraint dept_no_pk primary key (deptno);

/*添加外键约束*/
alter table employees add constraint emp_dept_fk foreign key(department_id)
 references departments(department_id);
 
/*添加自定义约束*/
alter table employees add constraint emp_salary_min check (salary > 0);

/*删除约束*/
alter table employees drop constraint emp_manager_fk;

alter table departments drop primary key cascade;

/*使用约束生效/失效*/
alter table employees disable constraint emp_id_pk cascade;

alter table employees enable constraint emp_id_pk

 

/*查询系统中存在哪些约束 –查不出数据来*/
select constraint_name,constraint_type,search_condition
from user_constraints
where table_name=’dept’;;

关键字:   oracle  
评论信息
暂无评论
发表评论
验证码: 
Powered by IMZHANGJIE.CN Copyright © 2015-2025 粤ICP备14056181号