创建非唯一索引时的唯一索引错误 - SQL Server

2022-11-14数据库问题
2

本文介绍了创建非唯一索引时的唯一索引错误 - SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我尝试对 SQL Server 2005 中的表创建非唯一索引.尝试创建它时出现以下错误.

I trying to and a non-unique index to a table table in SQL Server 2005. I am getting the following error when I try to create it.

消息 1505,级别 16,状态 1,第 1 行CREATE UNIQUE INDEX 语句终止,因为找到了对象名称dbo.oe_pick_ticket"和索引名称idx_pick_ticket_popup_wmms"的重复键.重复键值为 (1093066, N, N, N, , FBF, 100001, 1074359, 1118930).

Msg 1505, Level 16, State 1, Line 1 The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.oe_pick_ticket' and the index name 'idx_pick_ticket_popup_wmms'. The duplicate key value is (1093066, N, N, N, , FBF, 100001, 1074359, 1118930).

我的create语句如下:

My create statement is as follows:

CREATE NONCLUSTERED INDEX idx_pick_ticket_popup_wmms 
ON oe_pick_ticket (invoice_no, delete_flag, direct_shipment, auxiliary, oe_pick_ticket_type_cd, company_id, location_id, order_no)

我尝试重建聚集/唯一/主键索引,但没有任何改变.有谁知道我为什么会收到此错误以及如何解决它?

I have tried rebuilding the clustered/unique/primary key index and that didn't change anything. Does anyone know why I am getting this error and how to resolve it?

推荐答案

事实证明,我能够自己解决这个问题.我在桌子上运行了一个 DBCC CHECKTABLE,结果不一致.之后,我使用 REBUILD_REPAIR 选项再次运行它并修复了主键不一致的问题.

It turns out that I was able to figure this out on my own. I ran a DBCC CHECKTABLE on the table and there was an inconsistency. After that I ran it again with the REBUILD_REPAIR option and it fixed the primary key inconsistency.

这篇关于创建非唯一索引时的唯一索引错误 - SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End
SQLServer

相关推荐

将可变参数列表传递给 SqlServer2008 存储过程的理智/快速方法
Sane/fast method to pass variable parameter lists to SqlServer2008 stored procedure(将可变参数列表传递给 SqlServer2008 存储过程的理智/快速方法)...
2023-10-26 数据库问题
1

为什么SqlServer select语句会选择匹配的行和匹配并带有尾随空格的行
Why would SqlServer select statement select rows which match and rows which match and have trailing spaces(为什么SqlServer select语句会选择匹配的行和匹配并带有尾随空格的行)...
2023-10-08 数据库问题
3

SQLSERVER 中的 ListAGG
ListAGG in SQLSERVER(SQLSERVER 中的 ListAGG)...
2023-07-18 数据库问题
7

相当于 mySQL 中的 SQLServer 函数 SCOPE_IDENTITY()?
The equivalent of SQLServer function SCOPE_IDENTITY() in mySQL?(相当于 mySQL 中的 SQLServer 函数 SCOPE_IDENTITY()?)...
2023-04-28 数据库问题
59

使用 spark sql 在 sqlserver 上执行查询
execute query on sqlserver using spark sql(使用 spark sql 在 sqlserver 上执行查询)...
2023-04-04 数据库问题
8

Debezium 如何使用 Kafka Connect 正确注册 SqlServer 连接器 - 连接被拒绝
Debezium How do I correctly register the SqlServer connector with Kafka Connect - connection refused(Debezium 如何使用 Kafka Connect 正确注册 SqlServer 连接器 - 连接被拒绝)...
2023-04-03 数据库问题
3