use strict; use warnings; use DBI; my $max=10; #connect to the databases my $dbh=DBI->connect ('dbi:mysql:database', ' ', ' ') || die "Could not connect to database: $DBI::errstr"; my $add_max="update table set table.ID=".$max." where table.ID=5"; my $run=$dbh->prepare($add_max); $run->execute() or die "SQL Error: $DBI::errstr\n"; while(my @row =$run->fetchrow()){ $max++; } Input ID Name 4 AAA 5 BBB 8 CCC 5 GGG 13 TTT 14 RRR 5 YYY output should be ID Name 4 AAA 10 BBB 8 CCC 11 GGG 13 TTT 14 RRR 12 YYY