auto-increment
Moderator: General Moderators
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
auto-increment
i would like to add a field on my database that i would like to auto-increment with starting value as 10001, is that possible? how? what should be the type varchar or tinyint? i already have more than 6000 data! thanx!
- puckeye
- Forum Contributor
- Posts: 105
- Joined: Fri Dec 06, 2002 7:26 pm
- Location: Joliette, QC, CA
- Contact:
Re: auto-increment
Your field will have to be at least a smallint (values up to 65535 if unsigned) or probably better as mediumint (values up to 16777215 unsigned). Tinyint has a maximum value of 256 unsigned.sirTemplar wrote:i would like to add a field on my database that i would like to auto-increment with starting value as 10001, is that possible? how? what should be the type varchar or tinyint? i already have more than 6000 data! thanx!
To add a new field you'll have to alter your table with the following query:
Code: Select all
ALTER TABLE tbl_name ADD 'auto' MEDIUMINT(10) UNSIGNED NOT NULL AUTO_INCREMENTAfter the ALTER TABLE your new auto-increment will probably start at 0 so you sedn another query adding 10001 to that field. Something like:
Code: Select all
UPDATE tbl_name SET 'auto' + 10001when you created the table you should have had
this would have made your first value 10001
Code: Select all
CREATE TABLE test ( col1 int primary key auto_increment not null,
col2 text
)
AUTO_INCREMENT=10001- puckeye
- Forum Contributor
- Posts: 105
- Joined: Fri Dec 06, 2002 7:26 pm
- Location: Joliette, QC, CA
- Contact:
Yes you are right but how do you ADD a field with an autoincrement starting at 10001?Wayne wrote:when you created the table you should have had
this would have made your first value 10001Code: Select all
CREATE TABLE test ( col1 int primary key auto_increment not null, col2 text ) AUTO_INCREMENT=10001