December 6, 2016 at 7:12 am
I've table where Primery Key was not applied before now i want to apply primary key in this table.
The Data showing in the table is in below pic. it shows inconsistency in primary key column.. key column starting from 1 again later. and at the start of the key is starting from 239 and after starting from 1 again..
take a look at below pic how my data is showing in the table right now
I checked all the id's but i did'nt find any duplicate key in column.but when i try to apply Primary Key it shows following error to me.
- Unable to create index 'PK_Governance'.
The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.Governance' and the index name 'PK_Governance_00_03'. The duplicate key value is (239).
Could not create constraint. See previous errors.
The statement has been terminated.
As in the error it's saying 239 is duplicate. i did'nt find it duplicate but when i deleted 239 row then it showed me error of 240 key row.
look below
kindly tell me how can i solve this error
December 6, 2016 at 7:25 am
What are you doing to get the above pictures. It doesn't look like you have any ordering applied (considering your number go ...336, 337, 338, 1, 2... in your image).
I would firstly ensure your SELECT statement has an ORDER BY clause:
SELECT *
FROM dbo.Governance G
ORDER BY G.Id_Num;
Secondly, to get your duplicates:
SELECT *
FROM dbo.Governance G
WHERE G.Id_Num IN (SELECT sq.ID_num
FROM dbo.Governance sq
GROUP BY sq.Id_Num
HAVING COUNT(sq.Id_Num) > 1);
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply