This is a discussion on adding record w ID=0 within the MySQL forums, part of the Database Server Software category; --> I have an already existing table created w auto-increment (starting : 1) I need to add a record w ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have an already existing table created w auto-increment (starting : 1) I need to add a record w ID=0 manually... I tried to do it w phpmyadmin... but I always get a new record w the last increment value +1 never the 0... how can I do it manually ? thanks for your help .. joss |
| |||
| On Jun 20, 6:03 am, Josselin <josse...@wanadoo.fr> wrote: > I have an already existing table created w auto-increment (starting : 1) > I need to add a record w ID=0 manually... > I tried to do it w phpmyadmin... but I always get a new record w the > last increment value +1 never the 0... > how can I do it manually ? > > thanks for your help .. > > joss You can't. You can alter the table... ALTER TABLE `my_table` CHANGE `id` `id` TINYINT( 4 ) NOT NULL ....and then insert your 0 value... INSERT INTO `my_table` (id) VALUES (0) ....but when you revert the structure... ALTER TABLE `id` CHANGE `id` `id` TINYINT( 4 ) NOT NULL AUTO_INCREMENT ....the table will renumber itself from 1! |
| |||
| On 2007-06-20 14:48:07 +0200, strawberry <zac.carey@gmail.com> said: > On Jun 20, 6:03 am, Josselin <josse...@wanadoo.fr> wrote: >> I have an already existing table created w auto-increment (starting : 1) >> I need to add a record w ID=0 manually... >> I tried to do it w phpmyadmin... but I always get a new record w the >> last increment value +1 never the 0... >> how can I do it manually ? >> >> thanks for your help .. >> >> joss > > You can't. > > You can alter the table... > > ALTER TABLE `my_table` CHANGE `id` `id` TINYINT( 4 ) NOT NULL > > ...and then insert your 0 value... > > INSERT INTO `my_table` (id) VALUES (0) > > ...but when you revert the structure... > > ALTER TABLE `id` CHANGE `id` `id` TINYINT( 4 ) NOT NULL > AUTO_INCREMENT > > ...the table will renumber itself from 1! OK thanks.. maybe creating a new table with increment starting at 0 then importaing all data and renaming the table ... |
| ||||
| On Jun 22, 6:43 am, Josselin <josse...@wanadoo.fr> wrote: > On 2007-06-20 14:48:07 +0200, strawberry <zac.ca...@gmail.com> said: > > > > > On Jun 20, 6:03 am, Josselin <josse...@wanadoo.fr> wrote: > >> I have an already existing table created w auto-increment (starting : 1) > >> I need to add a record w ID=0 manually... > >> I tried to do it w phpmyadmin... but I always get a new record w the > >> last increment value +1 never the 0... > >> how can I do it manually ? > > >> thanks for your help .. > > >> joss > > > You can't. > > > You can alter the table... > > > ALTER TABLE `my_table` CHANGE `id` `id` TINYINT( 4 ) NOT NULL > > > ...and then insert your 0 value... > > > INSERT INTO `my_table` (id) VALUES (0) > > > ...but when you revert the structure... > > > ALTER TABLE `id` CHANGE `id` `id` TINYINT( 4 ) NOT NULL > > AUTO_INCREMENT > > > ...the table will renumber itself from 1! > > OK thanks.. maybe creating a new table with increment starting at 0 > then importaing all data and renaming the table ... Or just add a 'my_id' column with a value 1 less than the id coulmn - or just SELECT id -1 FROM my_table Why do you need to start at 0 anyway? |