Subject Re: [firebird-support] Re: Key violation on Primary/Unique key constraint INTEG_55/30 on table(s)
Author Gaurav Sood
Good insight Svein!

That's one problem that I didn't know about and is infact the probable cause
(most likely) as the first query produced a result of 103, where as the Max
value for ID is 140.

What do I do to set the Generator to the correct values here ?
SET GENERATOR PEOPLEIDGEN TO 140 ?

How do I automate it for the rest of the tables which have generators
controlling the insertion of values ?

Thanks!



On 3/14/06, Svein Erling Tysv�r <svein.erling.tysvaer@...>
wrote:
>
> I haven't followed this thread, so I apologize if my suggestion has
> been mentioned before.
>
> With creating the database, the generators may have been set to 0, and
> since you disabled the triggers, they never advanced. Pumping the data
> filled the ID field and whenever you now try to insert a new record,
> your database will try to use a number that has already been assigned.
>
> This is easy enough to check.
>
> SELECT GEN_ID(PEOPLEIDGEN, 0) FROM RDB$DATABASE
>
> SELECT MAX(ID) FROM PEOPLE
>
> If the first query returns a lower number than the latter, then you've
> probably found your problem.
>
> HTH,
> Set
>
> --- In firebird-support@yahoogroups.com, "Gaurav Sood" wrote:
> > Except one thing:
> >
> > I created the database using IBPump, and probably Disabled the
> > Triggers when I pumped the data, perhaps that could be a problem ?
> > how do I check or enable all the triggers ?
> >
> > > > > I found there is a separate trigger for PeopleID as follows;
> > > > >
> > > > >
> > > > > CREATE TRIGGER CREATEPEOPLEID FOR PEOPLE
> > > > > ACTIVE BEFORE INSERT POSITION 0
> > > > > AS BEGIN
> > > > > NEW.ID = GEN_ID(PEOPLEIDGEN, 1);
> > > > > END ^
> > > >
> > > > This will always assign a new generated value to ID. This is a
> > > > valid way of doing what was done in Delphi, however be aware
> > > > that in FB 1.5 you have no way of seeing the value of NEW.ID if
> > > > you do it this way.
> > > >
> > > > A better approach is
> > > >
> > > > CREATE TRIGGER CREATEPEOPLEID FOR PEOPLE
> > > > ACTIVE BEFORE INSERT POSITION 0
> > > > AS
> > > > BEGIN
> > > > IF (NEW.ID IS NULL) THEN
> > > > BEGIN
> > > > NEW.ID = GEN_ID(PEOPLEIDGEN, 1);
> > > > END
> > > > END
> > > > ^
> > > >
> > > > This will only generate an ID if you do not explicitly define
> > > > one.
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--



Analyst
B. Engineering, B. IT
A.N.U (2004)

M: +61 401 409 620
H: +61 3 9376 8580


"In life, always do right. This will gratify some people and astonish the
rest."

� Mark Twain


[Non-text portions of this message have been removed]