主键创建期间重复记录错误! ! [英] Duplicate records error during primary key creation! !
问题描述
大家好
我有一张表,其中记录是唯一的,但由于与其属性相关的更改,它们可能会多次出现。因此我有ProdID和StartDate col,产品的价格已经发生了变化。但是当把prodId作为主键时,SQl Server会抛出错误!!那我该怎么解决这个问题?
错误: -
Hi All
I have a table where there records are unique, however they might be present multiple times, due to changes associated with their attributes. Accordingly I have ProdID and StartDate col, there had been changes made in the price of the products.But while making that prodId as primary key, SQl Server throws error!!Then how do i resolve this??
Error:-
'EffectiveDate' table
- Unable to create index 'PK_EffectiveDate'.
The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.EffectiveDate' and the index name 'PK_EffectiveDate'. The duplicate key value is (PCOS103).
Could not create constraint. See previous errors.
The statement has been terminated.
我尝试过:
我仍然不确定,但是后来如何将某些类似的表存储在某些数据库中作为主键的某些记录?或者我错过了什么!!
What I have tried:
I am still unsure, but then how some of the similar tables are stored with certain records as primary keys in certain databases?Or Am I missing something!!
推荐答案
根据错误,有两个选项:您是否真的有重复数据,或者您没有为约束定义正确的列。
如果想法是单个ProdID
可以存在多次但不能完全相同的StartDate
然后确保你创建一个包含两列的键。一个SQL语句可能是这样的:
Based on the error there are two options: Either you really have duplicate data or you haven't defined correct columns for the constraint.
If the idea is that a singleProdID
can exist several times but not for the exact sameStartDate
then ensure that you create a key which contains both columns.An SQL statement could be something like:
ALTER TABLE EffectiveDate ADD PRIMARY KEY (ProdID, StartDate);
>
这篇关于主键创建期间重复记录错误! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!