开发者

MySQL problem: autoID not starting with 1

I开发者_JAVA技巧'm creating a new table from scratch through scripting - first, I'm dropping it (in case it already exists):

DROP TABLE IF EXISTS `myTable`

then I'm creating it:

CREATE TABLE IF NOT EXISTS `myTable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
... and so on

The problem: for some strange reason, my autoID-field ALWAYS starts at 2028 instead of 1, although I'm generating it from scratch. What is wrong?


Look at the end of create block. You probably have something like AUTO_INCREMENT=2028. If this is the case just put AUTO_INCREMENT=1 at the end of create table block

such as

CREATE TABLE IF NOT EXISTS `myTable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
...
) ENGINE=xxx AUTO_INCREMENT=1;


CREATE TABLE IF NOT EXISTS `myTable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id));

Please add primary key


You can update it by altering the table

ALTER TABLE <tablename> AUTO_INCREMENT = 1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜