View Full Version : Mysql Auto_icrement
borrob
February 22nd, 2007, 10:11 AM
Ok this is not really a php question but maybe somebody can help me.
i have a mysql table with the field id that's an auto_increment column.
but now i want the auto_increment to start at 'somenumber' and not at 1
anybody know the correct syntax for this when creating the table?
only for this table so no global setting
:cons:
bwh2
February 22nd, 2007, 10:41 AM
i always forget the syntax, but it's called a seed.
ramie
February 22nd, 2007, 02:08 PM
Create the table... (example)
CREATE TABLE `test` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`created_at` DATETIME NOT NULL
) ENGINE = MYISAM;
and then modify it.
ALTER TABLE test AUTO_INCREMENT = 100;
(and some test code if you like)
INSERT INTO `test` ( id` , `title` , `created_at` )
VALUES (
NULL , 'test title', '2007-02-22 18:08:28'
), (
NULL , 'another test title', '2007-02-22 18:08:39'
);
SELECT id FROM test;
should return 100, 101
bwh2
February 22nd, 2007, 10:05 PM
yeah, it sucks but i don't think there's a way to define the seed when you CREATE TABLE.
kdd
February 23rd, 2007, 02:32 AM
Why don't you download mysql's control center? instead of writing all this code, you can put 1 for auto increment. it has a gui, that's why...
borrob
February 23rd, 2007, 03:03 AM
Thanks very much a was breaking my head about this....
Time is here to consume.
foodpk
February 24th, 2007, 03:10 PM
I saw this thread and I thought I'd chime in. There is a way to set the AUTO_INCREMENT start when creating a table without using ALTER. Do it like so:
CREATE TABLE something (
....
fields here, bla bla
PRIMARY KEY( bla,blarg)
....
) TYPE=MyISAM AUTO_INCREMENT=1001;
evildrummer
February 24th, 2007, 03:12 PM
Why don't you download mysql's control center? instead of writing all this code, you can put 1 for auto increment. it has a gui, that's why...
Because it makes people feel less manly! :angry:
bwh2
February 25th, 2007, 04:42 PM
^^ excellent. i should have known because i've definitely exported CREATE TABLE statements before which included the AUTO_INCREMENT.
borrob
February 26th, 2007, 02:57 AM
Yes it worked. Thanks very much. This information is unbelievably hard to find. thanks foodpk... this is exactly what i needed.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.