in reply to Re^7: Increment DB using Perl
in thread Increment DB using Perl

ID is the name of the row to be updated and variable $newid should be the new id number to be inserted into the database table, so every time in the while loop the first row should be inserted with a 0 and all the rest of the rows should get incremented values 1 for the second row 2 for the third row until the end of the rows on the table.

Replies are listed 'Best First'.
Re^9: Increment DB using Perl
by jZed (Prior) on Mar 08, 2005 at 17:04 UTC
    > ID is the name of the row

    No, it is the name of a column which identifies the row. So you want something like

    UPDATE request SET ID=$newid WHERE ID = XXX

    Again, you haven't told us enough information to know what XXX is.
      Sorry, there isn't any XXX value the code that I have that does the update is the one here
      $sql2 = "UPDATE request SET ID='$new_id'";

      And no primary key
        As I and others in this thread have pointed out, an UPDATE statement with no WHERE clause updates all rows in the database. If you only wnat to update some rows, you need a WHERE clause. After all this you have never explained what you actually want to do. In which situation do you want to set the ID to 0? to 50? ... And it's very unclear why on earth you are mucking with the IDs anyway. There's no point in discussing the details further unless you can explain what you want to accomplish.

        update I'm sorry if I'm being harsh. There's no sin in you not understanding this. But if you want us to help, *please* tell us what you are trying to accomplish.

        Actually, it sounds like your 'XXX' is $pointer->{"id"}.

        The problem is that you are changing that while you're updating, and it's not going to work.

        You need something like

        Update ID SET ID = (select rownum from request );

        (except that doesn't work)
        You are trying to set the id of each row to be it's rownum in the way it is selected in your original query, neh?
        --------------
        It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs
Re^9: Increment DB using Perl
by Joost (Canon) on Mar 08, 2005 at 17:03 UTC