MySQL:如何设置自增字段的起始值? [英] MySQL : How to set the starting value of auto-increment field?
本文介绍了MySQL:如何设置自增字段的起始值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,
有一个表 articles
,它有这些字段:
For example,
there is a table articles
,it has these fields:
id
title
content
slug
id
字段是自动递增的,值从 1
开始.
id
field is auto-increment, the value starts from 1
.
问题:
我想将slug
字段设置为自增,并且值从10000
开始,怎么做?
Question:
I want to set slug
field to be auto-increment, and the value starts from 10000
,how to do it?
推荐答案
为什么要自动递增 2 个字段?即使从 10000 开始,它们也将具有相同的值..
Why do you want 2 fields to be auto incremented? They are going to have the same values, even if one starts from 10000..
示例:
id | title | content | slug
---| ------|---------|------
1 | 10000
2 | 10001
3 | 10001
. | .
. | .
n | n + 10000 - 1
你所要做的就是:
UPDATE articles SET slug = id + (10000 - 1) WHERE id = 'any id here..'
这篇关于MySQL:如何设置自增字段的起始值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文