Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

AUTO_INCREMENT Question

Options
  • 18-11-2009 3:04pm
    #1
    Closed Accounts Posts: 2,828 ✭✭✭


    Here is the situation, I have a customer database where I can add & remove data, CustID acts as the primary key and is set to AUTO_INCREMENT when I add a new customer it increases, but when I delete a customer it will continue to step up. How would I change each CustID, once one is deleted?

    CustID Name
    1 John <-- Next query deletes John and adds Steve.

    CustID Name
    2 Steve <-- Steve should take Johns place and have CustID = 1 instead of counting up.

    Does this make any sense?


Comments

  • Registered Users Posts: 981 ✭✭✭fasty


    That's not how it works. You would then need to go through every table that uses the CustID as a foreign key and update that too or your data would turn to muck.

    The idea behind using an autoincrementing integer as a key is that it's unique, Does it really matter what it is?


  • Closed Accounts Posts: 2,828 ✭✭✭Reamer Fanny


    fasty wrote: »
    That's not how it works. You would then need to go through every table that uses the CustID as a foreign key and update that too or your data would turn to muck.

    The idea behind using an autoincrementing integer as a key is that it's unique, Does it really matter what it is?

    No I suppose you are right :D


  • Closed Accounts Posts: 2,696 ✭✭✭mark renton


    Thats correct - really, data of a customer header nature should not be deleted, it can be archived if no longer required


Advertisement