Mike Maye
Mike Maye

Reputation: 13

Use while loop to update multiple rows SQL

I downloaded a database with over 90,000 rows. I need to make an edit to coulomb 2 of all rows by adding _id at the end of the value. I've never used SQL before so I'm not sure if its possible to just go through and add characters to the ends this way. what i have is this:

 SET @i = 01001
 WHILE(@i<93600)
  BEGIN 

        UPDATE NutritionTable
    SET field2 = (field2)"_id"
    WHERE field1=@i

SET @i = @i+1
  END -- WHILE

field2 being the coulomb that needs to be updated, and @id is the row number. I'm getting near "SET":syntax error.

I've searched around for answers but haven't found much in regards to this. Any assistance would be appreciated, and apologies in advance if there is another post for this that I missed... or its some basics I'm missing.

Upvotes: 1

Views: 3465

Answers (1)

Mureinik
Mureinik

Reputation: 311188

You don't need a loop - you can just update all the rows, without a where clause:

UPDATE NutritionTable
SET    field2 = CONCAT(field2, '_id');

Upvotes: 2

Related Questions