oracle主键插入重复数据

前端之家收集整理的这篇文章主要介绍了oracle主键插入重复数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

问题

发现oracle中已经设置了主键,但是还能插入重复数据,也是奇葩,后来发现主键虽然设置,但是没有启动,这才导致可以插入重复主键数据

解决办法

查询出没有启用主键的表

select a.constraint_name,b.column_name,a.table_name,a.status from user_constraints a,user_cons_columns b where a.constraint_type = 'P' and a.status='DISABLED' and b.column_name='ID';

启用SYS_CONFIG 表主键

alter table SYS_CONFIG enable primary key;

停用SYS_CONFIG 表主键

alter table SYS_CONFIG disable primary key;

批量启用主键

select 'alter table '||table_name|| ' enable primary key;' from (select a.constraint_name,user_cons_columns b where a.constraint_type = 'P' and a.status='DISABLED' and b.column_name='ID');

修改失败查询是哪个数据已经重复了

select * from (select count(*) num,id from SYS_CONFIG group by id )where num>1

猜你在找的Oracle相关文章