1
I have a question about Foreign key in the following situation:
Tehno table UF, with 3 columns:
ID_UF (PK), Cod_uf (int) and Descuf (nvarchar(50))
I have another table called IDE, with 3 columns:
ID_IDE (PK), Cod_uf(int) and Descide (nvarchar(50))
When I try to create a FK between the two tables with the Cod_uf column Sql gives a unique identifier error.
I understand the reason for the mistake, but what is the best solution to create a FK in a situation like this?
EDIT:
Answering questions about Cod_uf:
The ID_UF column is the internal code of the application for a given FU. The Cod_uf column is the code that the IBGE determines.
The IDE table receives information from a third party document that I receive via web service.
As I have no control of this webservice nor have to validate the information filled by the citizen on the other side of the webservice I thought of creating this FK between the UF table and the IDE table to avoid saving in this table an IBGE code that does not exist.
Wouldn’t it be better if you renamed
Cod_UF
ofUF
forCodIBGE
?– Leonel Sanches da Silva
It would even be changed after posting the question to Cod_ibge, because I read the comments and realized that the name of the column could cause confusion in the future.
– Robss70
Okay, but the answer, is there anything missing? You need me to complement something else?
– Leonel Sanches da Silva
I already thought about the solution of the question but I have not found a way to avoid inserting IBGE codes that do not exist in the UF table
– Robss70
I edited the answer, with the tip from
UNIQUE
for your columnCodIBGE
.– Leonel Sanches da Silva