Sun
Sun

Reputation: 3564

How to use AUTO_INCREMENT=value in MYSQL

I am creating simple table like below, But I am getting below error. I search in net, but I am not able to find error. I am just trying to use AUTO_INCREMENT=201.

CREATE TABLE `address` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT=201,
  `kkk` varchar(3) NOT NULL,
   PRIMARY KEY (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8;

Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 201, kkk varchar(3) NOT NULL, PRIMARY KEY (account_id) ) ENGINE=InnoD' at line 2 0.000 sec

Upvotes: 1

Views: 325

Answers (3)

Vick
Vick

Reputation: 19

Use below

CREATE TABLE `address` (
  `id` smallint(5) unsigned NOT NULL,
  `kkk` varchar(3) NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8;

Upvotes: 0

ranakrunal9
ranakrunal9

Reputation: 13558

Use below Query :

CREATE TABLE `address` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `kkk` varchar(3) NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8;

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269445

The auto_increment option is a table option, not a column option. Hence, it goes at the end of the create table statement or in a separate alter table statement:

CREATE TABLE `address` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `jjj` varchar(3) NOT NULL,
   PRIMARY KEY (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8;

Upvotes: 1

Related Questions