-1

Am trying to create a MySQL that tells

auto_increment

Where and how to start incrementing. Each time I run the code, it always tells me I have error near

auto.

Each time I removed the "=", it always work.

This is the code

CREATE TABLE staff(
id into(11) not null primary key auto_increment=001,
Names varchar(109) not null
);

What am I doing wrong

gbenga ogunbule
  • 589
  • 1
  • 6
  • 15

3 Answers3

0

First create table like below:

CREATE TABLE staff( id into(11) not null primary key auto_increment, Names varchar(109) not null );

then alter to customized auto increment.

ALTER TABLE staff AUTO_INCREMENT=001;

ROHIT KHURANA
  • 903
  • 7
  • 13
0

Schema (MySQL v5.7)

CREATE TABLE staff(
id int not null primary key auto_increment,
Names varchar(255) not null
)auto_increment=001;

View on DB Fiddle

0

The default auto-increment value is an option on the table not on the column (perhaps counterintuitively, but a table is only allowed to have one such column).

The syntax looks like:

CREATE TABLE staff (
    id int not null primary key auto_increment,
    Names varchar(109) not null
) auto_increment = 10;

Here is a db<>fiddle.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786