Alan
Alan

Reputation: 5189

How can I specify the auto-increment value of a primay key column?

How can I specify the auto-increment value of a primay key column? I would like to initialize it to 18.

Upvotes: 0

Views: 282

Answers (2)

Mark Byers
Mark Byers

Reputation: 838974

You can change the value of AUTO_INCREMENT:

ALTER TABLE tbl AUTO_INCREMENT = 18;

It can also be set to an initial value in the table create statement.

CREATE TABLE test1
(
    x INT PRIMARY KEY AUTO_INCREMENT,
    y VARCHAR(100)
)
AUTO_INCREMENT = 18;

See the documentation for CREATE TABLE and ALTER TABLE.

Upvotes: 5

Brad
Brad

Reputation: 163528

I'm assuming your PK is an auto-number...

ALTER TABLE tblSomething AUTO_INCREMENT=18;

Upvotes: 3

Related Questions