Reputation: 169
I have a table A with below structure
Contract_ID Parent_Contarct_ID Client_ID
--------------------------------------------------
CON_001 CON_001 CLNT_20001
CON_002 CON_002 CLNT_20002
CON_003 CON_003 CLNT_20003
CON_004 CON_004 CLNT_20004
Here the Contract_ID has duplicates and so I am unable to create the Primary key or unique key.
But I need to reference this contract_ID in some other tables. How to refer if I am not creating a foreign key?
I am using mysql
Upvotes: 0
Views: 101
Reputation: 5697
I think you're missing a fundemental understanding of your data. What does it mean to have duplicates? If you truly think the contract IDs should be unique and it is not then you have a data problem (and a bug in whatever software put that data there). If duplicates are ok then what does that mean?
Sure you can add an identity and link to that but that does nothing to fix your actual problem - you will just end up back here asking why you get too many rows back for a given contract!
So number one step is to understand your data. Then clean it if necessary. Only then can you put all your PK & FK constraints in the correct place with what ever columns make sense.
Upvotes: 1