Page 1 of 1

violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Posted: Wed 08 Jan 2014 22:23
by inageib
Hello,
I get this error when I try to insert new record although I can do the same without errors inside my admin tool.
violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"
here is the SQL

Code: Select all

CREATE TABLE Table1 (
    MN_ID               INTEGER NOT NULL,
    POS                SMALLINT NOT NULL

);

ALTER TABLE Table1 ADD CONSTRAINT UNQ1 UNIQUE (MN_ID, POS);

/* Trigger */
CREATE OR ALTER TRIGGER Table1_BI0 FOR Table1
ACTIVE BEFORE INSERT POSITION 0
AS
begin
  select max(POS)+1 from table1 where Table1.MN_id = new.mn_id into new.pos;
end

I enter the "MN_ID" value but for "POS" I leave the trigger "Table1_BI0" to do that. The Insert is working inside my admin tool but in my app I get the above error, please advise

Thanks

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Posted: Fri 10 Jan 2014 16:43
by inageib
any response ?

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Posted: Sat 11 Jan 2014 07:36
by ZEuS
Unfortunately, we can not reproduce the "violation of PRIMARY or UNIQUE KEY constraint" error you have reported.
Please create a small sample that demonstrates the problem, and send it to eugeniyz*devart*com.

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Posted: Sat 11 Jan 2014 16:27
by inageib
This is very strange, I tried again and it work without error. What can cause that behavior !!?

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Posted: Tue 14 Jan 2014 09:23
by ZEuS
We can not give a definite answer to such a general question. The problem may be caused by different reasons, and is specific to the code. If you can reproduce the problem and provide us with a test project - we will try to help.