#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Auto increment problem


    Hello everybody,

    in my program (using a firebird database) i have a table "persons" with the columns "personID", "name", "birthday" "gender".

    "personID" is the primary key and auto increments (implemented with generator and trigger).

    My problem with the auto increment is, when i insert the same person again (second time) , it gets a new "personID", but when its exactly the same person (same name, birthday, gender) it should get the same "personID" like when i inserted the person the first time. Is that somehow possible with auto increment ? or how would you solve this ? no auto increment ?(but the personID still has to be unique for each person...)

    thanks a lot for answers
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Location
    Plovdiv. Bulgaria
    Posts
    242
    Rep Power
    18
    Originally Posted by ibmkahm
    Hello everybody,

    in my program (using a firebird database) i have a table "persons" with the columns "personID", "name", "birthday" "gender".

    "personID" is the primary key and auto increments (implemented with generator and trigger).

    My problem with the auto increment is, when i insert the same person again (second time) , it gets a new "personID", but when its exactly the same person (same name, birthday, gender) it should get the same "personID" like when i inserted the person the first time. Is that somehow possible with auto increment ? or how would you solve this ? no auto increment ?(but the personID still has to be unique for each person...)

    thanks a lot for answers
    Primary keys are unique. They can't have equal values. In your case I think you have two options - remove the primary key and replace it with an index on personsID and change the trigger that generates the values for it, or just don't insert equal records in the table.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    205
    Rep Power
    19
    or set a unique constraint of Name + Birthday + Gender
    and it will not allow you to enter the same person twice

    Comments on this post

    • mateoc15 agrees : True true!

IMN logo majestic logo threadwatch logo seochat tools logo