Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make my ID field start from a specific number

Status
Not open for further replies.

blaises

Technical User
Sep 29, 2003
9
GB
Hi all,

I have an order table in mysql database and need to make the OrderId field entry start from a 5 figure number with an increment of 1. Any ideas how I can do this?

 
Make sure of the version -- it makes a difference.

MySQL version 4.x supports the statement:

alter table <tablename> auto_increment = <starting number>;


In MySQL 3.x, if you insert a record and set a value for the auto_increment column, the server will begin generating auto_incrmement numbers from that value. It's the only way to set a starting value.

You can then delete that record, but do not perform a &quot;DELETE from <tablename>&quot; query that does not have a WHERE clause. MySQL, in order to speed &quot;DELETE from <tablename>&quot; queries, will drop and recreate the table, which will reset the auto_increment start value back to 1.

MySQL's auto_increment always increments by 1.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top