Setting auto_increment from a certain number
Posted by: sofia (---.bornet.net)
Date: June 27, 2006 04:21PM

I've got my other question partly sorted so now I wonder why I can't set auto_increment to start at a certain number.
I've tried ALTER TABLE author AUTO_INCREMENT=100586 in the SQL box but it doesn't seem to work as I keep getting the same error as I got in my other post when I try to insert data through a form.

Please help ASAP.

Options: ReplyQuote
Re: Setting auto_increment from a certain number
Posted by: CyberSpatium (67.170.181.---)
Date: June 27, 2006 09:08PM

use DEFAULT to set the value at 100586

Options: ReplyQuote
Re: Setting auto_increment from a certain number
Posted by: sofia (---.bornet.net)
Date: June 27, 2006 09:19PM

Like this? which doesn't work...
ALTER TABLE author AUTO_INCREMENT=default

Tried to change under settings (operations) but it doesn't work there neither........

Options: ReplyQuote
Re: Setting auto_increment from a certain number
Posted by: sofia (---.bornet.net)
Date: June 27, 2006 11:25PM

BTW, wouldn't default mean that auto_increment would start from 1, which doesn't work if there's already data with manually given keys in the table, if I've understood everything correctly.

Please explain this a bit more to me.

Options: ReplyQuote
Re: Setting auto_increment from a certain number
Posted by: CyberSpatium (67.170.181.---)
Date: June 28, 2006 09:48AM

ALTER TABLE `table_name` MODIFY `column_name` MEDIUMINT(6) DEFAUTL ('100586')

replace the table_name and column_name from the sql above with your values. then run the sql statement. it will set the field to a MEDIUMINTwhich will hold a value between -8388608 to 8388607.

for more info on types, see:
[dev.mysql.com]

Options: ReplyQuote
Re: Setting auto_increment from a certain number
Posted by: sofia (---.bornet.net)
Date: June 28, 2006 06:34PM

Thank you! I'll give it a try, though I found a loophole (empty database, turn on auo_increment, import the files with set key values and then import the files without key values set)
I'd still like to know though why it doesn't work with inserting data from a script. I keep getting:
Error: Duplicate entry '0' for key 1
every time I try, even when leaving the key fields blank.

ETA: I've set the password to null in case anyone asks. winking smiley



Post Edited (06-28-06 18:38)

Options: ReplyQuote
Re: Setting auto_increment from a certain number
Posted by: CyberSpatium (67.170.181.---)
Date: June 29, 2006 01:03AM

you are getting that error becuase you have matching data. mysql cannot store duplicate data in the database.

Options: ReplyQuote
Re: Setting auto_increment from a certain number
Posted by: sofia (---.bornet.net)
Date: June 29, 2006 08:24AM

What I've tried to enter is two fields with one of the data matching a post that's already in.
Eg:
What's already in: Nilsson, Gert
What I try to enter: Nilsson, Nils
What's already in: Pipkorn, Bengt
What I try to enter: Bentsson, Bengt

Please don't tell me that all the surnames, first names and sources has to be unique in order to get a new post. winking smiley

Options: ReplyQuote


Sorry, only registered users may post in this forum.