on 02-08-2016 4:13 AM
Given that Max(CODE_ID) = 1006 and CODE_ID is the primary key and that....
begin
declare varCodeID integer;
select Max(CODE_ID) + 1 into varCodeID from CODE;
-- Insert Parent Code
insert into CODE(CODE_ID,PARENT_CODE_ID,CODE_NAME)
select varCodeID,1,'Example Parent';
-- snipped insertion of children
end
works as expected, why does the following fail saying that 1007 is a duplicate primary key?
begin
declare varCodeID integer;
select Max(CODE_ID) + 1 into varCodeID from CODE;
-- Insert Parent Code
insert into CODE(CODE_ID,PARENT_CODE_ID,CODE_NAME)
select varCodeID,1,'Example Parent' from CODE;
-- snipped insertion of children
end
Hoping the answer isn't too embarrassing, Paul
I'm pretty sure that your second example will attempt to insert a row with primary key 1007 into the CODE table for each row that already exists in the table. If there are multiple rows in the table already, I would expect a primary key violation.
Reg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.