维护数据的完整性4-删除约束

删除约束
当不再需要某个约束时,可以删除。
alter table 表名 drop constraint 约束名称;

在删除主键约束的时候,可能有错误,比如:
alter table 表名 drop primary key;

这是因为如果在两张表存在主从关系,那么在删除主表的主键约束时,必须带上cascade选项

比如:
alter table 表名 drop primary key cascade;

显示约束信息
1.显示约束信息
通过查询数据字典视图user_constraints,可以显示当前用户所有的约束的信息。
select constraint_name,constraint_type,status,validated from user_constraints where table_name='表名';

2.显示约束列
通过查询数据字典视图user_cons_columns,可以显示约束所对应的表列信息。
select column_name,position from user_cons_columns where constraint_name='约束名';

3.当然也有更容易的方法,直接用pl/sql developer查看即可。

注意:在上面的代码中的约束名和表名都需要大写输入

猜你喜欢

转载自1124117571.iteye.com/blog/2286529