-1

I added new columns to the current table employee called salary, now I have to add values for 100 records. I don't want to write the update column 100 times,more over I can't define case statement , because salary for each employeeId is different. So the command below is not what I want.

     UPDATE employee
    SET salary = 10000
    WHERE employeeId = 1;

THE SAME FOR employeeId = 2,3,....

I am interesting to have id as parameter like @id, as employeeId defined aut_increment , so in each iteration adding a corresponding values to it.

Imagin salaries are (1000,2000,4000,5000,....) What are the best way or solutions to do that?

pm1359
  • 622
  • 1
  • 10
  • 31
  • See http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query – Strawberry May 13 '17 at 14:32
  • @Strawberry I can't undrestand what do u mean by giving negative to my question? and i can't see my answer in the link you have posted here. I am new to mysql and I am asking a question,and 3 hours looking here and not finding a proper answer so if u know something try to help the other rather than rejecting them! – pm1359 May 13 '17 at 14:43
  • If you hover over the down arrow, it may offer a clue. – Strawberry May 13 '17 at 14:47

1 Answers1

0

In spring jpa, find all the records, loop through each of the record and do update operation. Example:

List<YourEntity> entities= repositoryObject.findAll();

for (Entity e : entities)
{
e.setSalary(<your salary values>). // salary values you can read from a file etc..

repositoryObject.save(e); //Do the save operation on the object you are looping through. Hence other column values still persist in the object. Hence you would update the row.

}
Tanmay Delhikar
  • 1,275
  • 11
  • 16