Starting Value for AUTO_INCREMENT

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dickey
Forum Commoner
Posts: 50
Joined: Thu May 16, 2002 8:04 pm
Location: Sydney, Australia

Starting Value for AUTO_INCREMENT

Post by dickey »

How do I specify a starting value for use with AUTO_INCREMENT?

example create table script:

CREATE TABLE egtable (
egcolname INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
etc,etc,etc);

In place of starting the numbering at 1, I may like to start the numbering at 10000.

Any advice will be appreciated. Thank you.

-Dickey
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post by Elmseeker »

Code: Select all

ALTER TABLE tbl_name AUTO_INCREMENT = 10000;
will start your records at 10000 if you want to start a number other than 10000 simply replace the 10000 in the command with whatever number you wnat to start with.

as a php statement you would do this normally:

Code: Select all

<?
$query = "ALTER TABLE tbl_name AUTO_INCREMENT = 10000";
$result = mysql_query($query);
?>
Enjoy! :)
Post Reply