0
I have a system that integrates data from three different banks, more specifically the registration of the companies of these three banks, I created a table where are stored the integrations that user will do, for example:
no banco X a empresa A é código 01
no banco Y a empresa A é código 02
no banco Z a empresa A é código 03
in my table that stores the integrations that user will do the data would look like this:
nomeEmpresa = A
codigoBancoX = 1
codigoBancoY = 2
codigoBancoZ = 3
I need to avoid that by carelessness of the user be added exactly equal all fields, ie can not have two rows in my table exactly equal. My question is. If I put all fields of my table as Primary Key would solve my problem? Because then no line could be exactly the same but still could exist line like this:
nomeEmpresa = A
codigoBancoX = 1
codigoBancoY = 2
codigoBancoZ = 3
nomeEmpresa = A
codigoBancoX = 1
codigoBancoY = 2
codigoBancoZ = 4
Don’t use PK for this, create a UNIQUE key with relevant columns.
– bfavaretto
How do I do this in Postgresql you could tell me? I thought that PK was for this, so that it was only the column
– R.Santos
Related: It is possible to have more than one Primary key in a table?
– Marconi
In Postgres I do not know, but surely there is someone here who does. PK is the primary key, the main identifier of the line. It’s usually not cool that it’s too complex. Semantically it’s different from UNIQUE (although it implies UNIQUE).
– bfavaretto
@R.Santos feel free to use one Indice Unico or a Restriction Unica, if you want to know the difference between the two... CLICK HERE
– Tobias Mesquita