0

I have a DB setup with two columns, ID and VAL.

ID is an incrementing integer, starting from 1 and increasing by 1 for each row. VAL is a simple string.

How can I update each row's ID to be 10 times greater? E.g.: ID 1, 2, 3 -> ID 10, 20, 30

Or is there a better method to adding a trailing zero to the end of every row in a column?

8
  • 2
    Does this answer your question? MySQL Auto increment primary key increases by 10 Commented Feb 1, 2021 at 21:51
  • 1
    There is no good reason for wanting to do this. None. Commented Feb 1, 2021 at 22:40
  • 3
    That would be an ill-advised use of an auto incrementing primary key. Commented Feb 1, 2021 at 23:00
  • 2
    agreed with Strawberry; you should not impute any meaning to id values; if you need to order and reorder them, use a separate column for that Commented Feb 1, 2021 at 23:03
  • 1
    You should not be messing with the id Commented Feb 1, 2021 at 23:09

1 Answer 1

1

If you are trying to update the existing values, you simply need to do:

update mysterytablename set ID=ID*10 order by ID desc;

(The order by is only needed if ID is a primary or unique key, which presumably it is.)

Sign up to request clarification or add additional context in comments.

1 Comment

I can't believe this actually works, so I tested it... and it does. Still seems like a bad idea though .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.