Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql tables adding onto

    I have a simple table of ten rows.
    When I want to add on ten more, one at a time, keeping things in order, do the keys adjust as the items are entered?

    e.g.
    I use notepad++ to create the tables.
    I want new item 11 to be in the item 3 spot.
    Do I have to manually change each key accordingly?

    If that makes no sense, sorry, just don't know how else to say it.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Depends on your DB design and contents.

    If you mean that you have a field that just contains sequential numbers (1,2,3,etc.), then yes, you'll have to manage it all yourself.

    But it's not hard.

    Example:
    Code:
    UPDATE tablename SET idnum = -(idnum+1) WHERE idnum >= 3
    INSERT INTO tablename (idnum, other, fields) VALUE(3,'other','values')
    UPDATE tablename SET idnum = -idnum WHERE idnum < 0
    (You can't just directily bump the numbers by one, so you make them negative at the same time you bump them and then convert all the negative numbers back.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Jun 2012
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the help. Wasn't sure how that worked.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •