-3

In a table , for example, have an ID start by 142963 , and there are 2000 record

So , the id are 142963....142963+2000

Then I would like to change the id to start from 740923

After that, the id are 740923.... 740923+2000

The field name is e.g. userid

How to update that? thanks

user782104
  • 13,233
  • 55
  • 172
  • 312
  • 2
    In SQL Server `UPDATE YourTable SET id = id + 597960` (assuming not referenced as an FK anywhere). What RDBMS are you actually using? [In MySQL that might not work](http://stackoverflow.com/a/11207946/73226) – Martin Smith Jun 26 '13 at 10:10
  • I think you need to go for stored procedure. – Mahesh.D Jun 26 '13 at 10:10

3 Answers3

3

Unless I'm missing something, it's just

UPDATE table_name SET userid = userid + 597960;
Aleks G
  • 56,435
  • 29
  • 168
  • 265
0
update forexample
    set userid = 597960 + userid
    where userid >= 142963 and userid <= 144963;
Jodrell
  • 34,946
  • 5
  • 87
  • 124
0

UPDATE table_name SET userid= userid +(740923-142963) WHERE userid BETWEEN 142963 AND (142963+2000);

HERE I HAVE GIVEN YOUR VALUES BUT IT COULD BE USED FOR ANY NUMBER YOU WISH YOU CAN USE ARITHMETIC OPERATORS FOR GETTING ANY COMBINATION.

navi
  • 1