zwl1619
zwl1619

Reputation: 4222

MySQL : How to set the starting value of auto-increment field?

For example,
there is a table articles,it has these fields:

id
title
content
slug

id field is auto-increment, the value starts from 1.

Question:
I want to set slug field to be auto-increment, and the value starts from 10000,how to do it?

Upvotes: 0

Views: 506

Answers (1)

Vural
Vural

Reputation: 8748

Why do you want 2 fields to be auto incremented? They are going to have the same values, even if one starts from 10000..

Example:

id | title | content | slug
---| ------|---------|------
 1 |                  10000
 2 |                  10001
 3 |                  10001
 . |                  .
 . |                  .
 n |                  n + 10000 - 1   

All you have to do is:

UPDATE articles SET slug = id + (10000 - 1) WHERE id = 'any id here..'

Upvotes: 1

Related Questions