oracle违反唯一约束

报错信息:nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

背景:修改原有的逻辑,取消掉某个字段的唯一约束。

框架:spring-data-jpa

1,查询所有的约束

select * from user_constraints

2,根据类型 constraint_type 过滤

Type Code Type Description Acts On Level
C Check on a table Column
O Read Only on a view Object
P Primary Key Object
R Referential AKA Foreign Key Column
U Unique Key Column
V Check Option on a view Object

//筛选唯一约束的类型

select * from user_constraints WHERE  constraint_type = 'U'

3,根据类型 constraint_type 和表名过滤

select * from user_constraints WHERE TABLE_name = '表名' AND constraint_type = 'U'

4,删除唯一约束

alter table 表名drop constraint 约束名;

约束名可从以下sql获取

select constraint_name from user_constraints WHERE TABLE_name = '表名' AND constraint_type = 'U'

 

你可能感兴趣的:(Oracle)