Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I knew the primary key constraint does not allow the duplicate values..but i seen that duplicate values in primary key column in my application old database...how is it possible?
Posted
Updated 2-Oct-21 3:42am

You can't have duplicate values in the primary key or else it wouldn't be a primary key.
 
Share this answer
 
Answer: No it is not possible.

The wording Primary Key imply non duplicate values, it is by design !

You can have duplicate values in Non Primary Key, it is the only way.
 
Share this answer
 
As stated in Solution 1, you cannot have actual duplicate values in the primary key.
HOWEVER, it may be possible to have primary keys which appear to be duplicates but aren't. For example, if the primary key was textual (nvarchar) then the following could happen:
ABC
ABC 
 ABC
The first two differ by a trailing space on the 2nd value. The 3rd has a leading space. If you don't look carefully at the actual values, they may appear to be duplicates.
 
Share this answer
 
Comments
Wendelius 8-Sep-15 14:33pm    
Good point!
Actually IT IS POSSIBLE, in my database I have a FORM linked to TABLE 1, containing a SUBFORM linked to TABLE 2.

TABLES 1 and 2 are linked by a primary key which does not allow duplicates.

Now my FORM is showing TWO RECORDS with same primary key...I can see them in the form, but there is no trace of the duplicate in the TABLES.

Of course I cannot delete the record in TABLE 1, because then both duplicates disappear from FORM.
And if I do, then input again the record... reappears the duplicate in the FORM.

It's a miracle...I don't really know how I manage to do it.

Anyone could help out?
 
Share this answer
 
Comments
CHill60 29-Oct-20 7:24am    
No it is NOT possible. What you are seeing is the results of a query that is returning two rows from one of the tables for a single row in the other.
This is not a solution to the original problem - if you have a question then use the red "Ask a Question" link at the top of this page - and be sure to include sample data and expected results for that data.
What I will say is that the tables are NOT linked by a primary key - one table has a FOREIGN KEY linked to the PRIMARY KEY of the other table

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900