Laxmi Lal Menaria
Laxmi Lal Menaria

Reputation: 1445

How to update existing AUTO NUMBER Values in MYSQL

I have created a MYSQL table with autoincrement id, and inserted appx 10K values, so now id starts from 1 onwards.

Now I would like to change my existing ID from 10001 onwards.. i.e. my existing id 1 should starts from 10001..next 10002...

So how it possible without affect other data's

Thanks, Laxmilal Menaria

Upvotes: 0

Views: 455

Answers (2)

evan
evan

Reputation: 12543

To "correct" old values do this:

UPDATE TABLE `tbl` SET `id` = `id` + 10000;

If you want all new autoincrementing values to start at 10001, do this (it will automatically skip numbers that are already set; so, if you already have 10001, it will start with 10002):

ALTER TABLE `tbl` AUTO_INCREMENT = 10000;

Upvotes: 0

Marco
Marco

Reputation: 57593

Try this:

UPDATE your_table
SET id = id + 10000

Upvotes: 1

Related Questions