I have a table with a primary key composed of three columns: CODE_TARIF, UNITE, MODE_LIV. In my table there are three records with MODE_LIV = 2. Then I insert a record with MODE_LIV = 4.
INSERT INTO T_TARIF (
CODE_TARIF, ZONE, UNITE, MODE_LIV, LIBELLE, TR_DEBUT, TR_FIN, MONTANT
)
SELECT 'Livr_A_50_99', '2', '1', '4', 'sdg', '50', '99', '90'
UNION ALL
SELECT 'Livr_A_50_99', '2', '1', '4', 'sdg', '50', '99', '90'
UNION ALL
SELECT 'Livr_A_50_99', '2', '1', '4', 'sdg', '50', '99', '90'
It returns an error (violation of primary key), which doesn’t make any sense because MODE_LIV = 2 is not equal to MODE_LIV = 4.
I know I could add a surrogate key as an auto-incrementing identity column, but in my situation that isn’t an option.
You are inserting 3 rows with identical data in the primary key fields.
Of course you’re going to get PK violations.
Change the code to: