MySQL insertion batch getting reversed

27 views Asked by At

I have a Bash-script doing the following insertion:

    for i in $bb; do
            echo "INSERT INTO $D_BASE2.$table2 (id, DokMed_id, amne) SELECT NULL, DokMed_id, amne FROM DokMed_Amne where id = ${i};"| mysql -u eArkiv -p$PASS_WD $D_BASE1 2>/dev/null
            echo "UPDATE $D_BASE2.$table2 SET DokMed_id = ${aa} where id = ${i};"| mysql -u eArkiv -p$PASS_WD $D_BASE2 2>/dev/null
    done

The insertion works fine in to the table 'DokMed_Amne' say 13 new lines. Those lines will have an autoincremented id of 1 till 13.

When I make a new insertion, that previous insertion is moved up to id 14 till 26 and the new instertion gets id 1 till 13. Is this something in MySQL that can be configured? Or am I doing something wrong?

First insertion          Second insertion
1   Value 1              1    Value 14
2   Value 2              2    Value 15
3   Value 3              3    Value 16
.                        .
.                        .
.                        .
.                        .
.                        .
13   Value 13            13   Value 26
                         14   Value 1
                         15   Value 2
                         16   Value 3
                         .
                         .
                         .
                         .
                         .
                         26   Value 13

How could I make Value 1 till 13 stick with id 1 till 13?

1

There are 1 answers

0
Paul Bergström On

Thank you for your answers. The answer was rather obvious. They say hindsight is the most accurate science of all:-)

 for i in $bb; do
        echo "INSERT INTO $D_BASE2.$table2 (id, DokMed_id, amne) SELECT NULL, DokMed_id, amne FROM DokMed_Amne where id = ${i};"| mysql -u eArkiv -p$PASS_WD $D_BASE1 2>/dev/null
        echo "UPDATE $D_BASE2.$table2 SET DokMed_id = ${aa} where id = ${i};"| mysql -u eArkiv -p$PASS_WD $D_BASE2 2>/dev/null
 done

The script worked as expected edited to this:

 for i in $bb; do
        echo "INSERT INTO $D_BASE2.$table2 (DokMed_id, amne) SELECT DokMed_id, amne FROM DokMed_Amne where id = ${i};"| mysql -u eArkiv -p$PASS_WD $D_BASE1 2>/dev/null
        echo "UPDATE $D_BASE2.$table2 SET DokMed_id = ${aa} where id = ${i};"| mysql -u eArkiv -p$PASS_WD $D_BASE2 2>/dev/null
 done

I guess Salman A had the most accurate explaination, however I'm not really sure why it behaved like this.

Have a nice weekend guys:-)

/Paul